refactoring

This commit is contained in:
2023-06-08 15:15:38 +06:00
parent a983df1ac6
commit c5585bbb0c
88 changed files with 922 additions and 1071 deletions

4
.gitignore vendored
View File

@@ -4,6 +4,10 @@ obj/
# user files # user files
.old*/ .old*/
[Tt]mp/
[Tt]emp/
.[Tt]mp/
.[Tt]emp/
.vs/ .vs/
.vshistory/ .vshistory/
.editorconfig .editorconfig

View File

@@ -1,31 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.2.32317.152 VisualStudioVersion = 17.2.32317.152
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kerep", "kerep.vcxproj", "{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kerep", "kerep.vcxproj", "{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
Debug|x86 = Debug|x86 Debug|x86 = Debug|x86
Release|x64 = Release|x64 Release|x64 = Release|x64
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x64.ActiveCfg = Debug|x64 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x64.ActiveCfg = Debug|x64
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x64.Build.0 = Debug|x64 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x64.Build.0 = Debug|x64
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x86.ActiveCfg = Debug|Win32 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x86.ActiveCfg = Debug|Win32
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x86.Build.0 = Debug|Win32 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Debug|x86.Build.0 = Debug|Win32
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x64.ActiveCfg = Release|x64 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x64.ActiveCfg = Release|x64
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x64.Build.0 = Release|x64 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x64.Build.0 = Release|x64
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x86.ActiveCfg = Release|Win32 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x86.ActiveCfg = Release|Win32
{52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x86.Build.0 = Release|Win32 {52F0BD29-A3CB-47CE-B25D-CEAF5DFB2D73}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {22F8C351-9A96-4F37-94E6-37E6AB5BA058} SolutionGuid = {22F8C351-9A96-4F37-94E6-37E6AB5BA058}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -1,297 +1,297 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64"> <ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|x64"> <ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\Array\Array.c" /> <ClCompile Include="src\Array\Array.c" />
<ClCompile Include="src\Autoarr\Autoarr.c" /> <ClCompile Include="src\Autoarr\Autoarr.c" />
<ClCompile Include="src\Autoarr\Autoarr_KVPair_exported.c" /> <ClCompile Include="src\Autoarr\Autoarr_KVPair_exported.c" />
<ClCompile Include="src\Autoarr\Autoarr_Unitype.c" /> <ClCompile Include="src\Autoarr\Autoarr_Unitype.c" />
<ClCompile Include="src\Autoarr\Autoarr_Unitype_exported.c" /> <ClCompile Include="src\Autoarr\Autoarr_Unitype_exported.c" />
<ClCompile Include="src\base\cptr.c" /> <ClCompile Include="src\base\cptr.c" />
<ClCompile Include="src\base\endian.c" /> <ClCompile Include="src\base\endian.c" />
<ClCompile Include="src\base\errors.c" /> <ClCompile Include="src\base\errors.c" />
<ClCompile Include="src\base\type_system\base_toString.c" /> <ClCompile Include="src\base\type_system\base_toString.c" />
<ClCompile Include="src\base\type_system\init.c" /> <ClCompile Include="src\base\type_system\init.c" />
<ClCompile Include="src\base\type_system\kt_functions.c" /> <ClCompile Include="src\base\type_system\kt_functions.c" />
<ClCompile Include="src\base\type_system\unitype.c" /> <ClCompile Include="src\base\type_system\unitype.c" />
<ClCompile Include="src\DtsodParser\DtsodV24.c" /> <ClCompile Include="src\DtsodParser\DtsodV24.c" />
<ClCompile Include="src\DtsodParser\DtsodV24_deserialize.c" /> <ClCompile Include="src\DtsodParser\DtsodV24_deserialize.c" />
<ClCompile Include="src\DtsodParser\DtsodV24_exported.c" /> <ClCompile Include="src\DtsodParser\DtsodV24_exported.c" />
<ClCompile Include="src\DtsodParser\DtsodV24_serialize.c" /> <ClCompile Include="src\DtsodParser\DtsodV24_serialize.c" />
<ClCompile Include="src\Filesystem\dir.c" /> <ClCompile Include="src\Filesystem\dir.c" />
<ClCompile Include="src\Filesystem\file.c" /> <ClCompile Include="src\Filesystem\file.c" />
<ClCompile Include="src\Filesystem\path.c" /> <ClCompile Include="src\Filesystem\path.c" />
<ClCompile Include="src\HashFunctions\hash.c" /> <ClCompile Include="src\HashFunctions\hash.c" />
<ClCompile Include="src\Hashtable\Hashtable.c" /> <ClCompile Include="src\Hashtable\Hashtable.c" />
<ClCompile Include="src\Hashtable\KeyValuePair.c" /> <ClCompile Include="src\Hashtable\KeyValuePair.c" />
<ClCompile Include="src\kprint\kprint.c" /> <ClCompile Include="src\kprint\kprint.c" />
<ClCompile Include="src\kprint\kprintf.c" /> <ClCompile Include="src\kprint\kprintf.c" />
<ClCompile Include="src\random\splitmix64\splitmix64.c" /> <ClCompile Include="src\random\splitmix64\splitmix64.c" />
<ClCompile Include="src\random\xoroshiro\32bitValue\xoroshiro64star.c" /> <ClCompile Include="src\random\xoroshiro\32bitValue\xoroshiro64star.c" />
<ClCompile Include="src\random\xoroshiro\32bitValue\xoroshiro64starstar.c" /> <ClCompile Include="src\random\xoroshiro\32bitValue\xoroshiro64starstar.c" />
<ClCompile Include="src\random\xoroshiro\64bitValue\xoroshiro128plus.c" /> <ClCompile Include="src\random\xoroshiro\64bitValue\xoroshiro128plus.c" />
<ClCompile Include="src\random\xoroshiro\64bitValue\xoroshiro128plusplus.c" /> <ClCompile Include="src\random\xoroshiro\64bitValue\xoroshiro128plusplus.c" />
<ClCompile Include="src\random\xoroshiro\64bitValue\xoroshiro128starstar.c" /> <ClCompile Include="src\random\xoroshiro\64bitValue\xoroshiro128starstar.c" />
<ClCompile Include="src\random\xoshiro\32bitValue\xoshiro128plus.c" /> <ClCompile Include="src\random\xoshiro\32bitValue\xoshiro128plus.c" />
<ClCompile Include="src\random\xoshiro\32bitValue\xoshiro128plusplus.c" /> <ClCompile Include="src\random\xoshiro\32bitValue\xoshiro128plusplus.c" />
<ClCompile Include="src\random\xoshiro\32bitValue\xoshiro128starstar.c" /> <ClCompile Include="src\random\xoshiro\32bitValue\xoshiro128starstar.c" />
<ClCompile Include="src\random\xoshiro\64bitValue\xoshiro256plus.c" /> <ClCompile Include="src\random\xoshiro\64bitValue\xoshiro256plus.c" />
<ClCompile Include="src\random\xoshiro\64bitValue\xoshiro256plusplus.c" /> <ClCompile Include="src\random\xoshiro\64bitValue\xoshiro256plusplus.c" />
<ClCompile Include="src\random\xoshiro\64bitValue\xoshiro256starstar.c" /> <ClCompile Include="src\random\xoshiro\64bitValue\xoshiro256starstar.c" />
<ClCompile Include="src\SearchTree\SearchTree.c" /> <ClCompile Include="src\SearchTree\SearchTree.c" />
<ClCompile Include="src\String\string.c" /> <ClCompile Include="src\String\string.c" />
<ClCompile Include="src\String\StringBuilder.c" /> <ClCompile Include="src\String\StringBuilder.c" />
<ClCompile Include="tests\test_marshalling.c" /> <ClCompile Include="tests\test_marshalling.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\Array\Array.h" /> <ClInclude Include="src\Array\Array.h" />
<ClInclude Include="src\Array\Array_declare.h" /> <ClInclude Include="src\Array\Array_declare.h" />
<ClInclude Include="src\Array\Array_define.h" /> <ClInclude Include="src\Array\Array_define.h" />
<ClInclude Include="src\Autoarr\Autoarr.h" /> <ClInclude Include="src\Autoarr\Autoarr.h" />
<ClInclude Include="src\Autoarr\Autoarr_declare.h" /> <ClInclude Include="src\Autoarr\Autoarr_declare.h" />
<ClInclude Include="src\Autoarr\Autoarr_define.h" /> <ClInclude Include="src\Autoarr\Autoarr_define.h" />
<ClInclude Include="src\Autoarr\Autoarr_Unitype.h" /> <ClInclude Include="src\Autoarr\Autoarr_Unitype.h" />
<ClInclude Include="src\base\base.h" /> <ClInclude Include="src\base\base.h" />
<ClInclude Include="src\base\cptr.h" /> <ClInclude Include="src\base\cptr.h" />
<ClInclude Include="src\base\endian.h" /> <ClInclude Include="src\base\endian.h" />
<ClInclude Include="src\base\errors.h" /> <ClInclude Include="src\base\errors.h" />
<ClInclude Include="src\base\optime.h" /> <ClInclude Include="src\base\optime.h" />
<ClInclude Include="src\base\std.h" /> <ClInclude Include="src\base\std.h" />
<ClInclude Include="src\base\type_system\base_toString.h" /> <ClInclude Include="src\base\type_system\base_toString.h" />
<ClInclude Include="src\base\type_system\init.h" /> <ClInclude Include="src\base\type_system\init.h" />
<ClInclude Include="src\base\type_system\ktDescriptor.h" /> <ClInclude Include="src\base\type_system\ktDescriptor.h" />
<ClInclude Include="src\base\type_system\ktid.h" /> <ClInclude Include="src\base\type_system\ktid.h" />
<ClInclude Include="src\base\type_system\kt_functions.h" /> <ClInclude Include="src\base\type_system\kt_functions.h" />
<ClInclude Include="src\base\type_system\type_system.h" /> <ClInclude Include="src\base\type_system\type_system.h" />
<ClInclude Include="src\base\type_system\unitype.h" /> <ClInclude Include="src\base\type_system\unitype.h" />
<ClInclude Include="src\DtsodParser\DtsodV24.h" /> <ClInclude Include="src\DtsodParser\DtsodV24.h" />
<ClInclude Include="src\Filesystem\dir.h" /> <ClInclude Include="src\Filesystem\dir.h" />
<ClInclude Include="src\Filesystem\file.h" /> <ClInclude Include="src\Filesystem\file.h" />
<ClInclude Include="src\Filesystem\filesystem.h" /> <ClInclude Include="src\Filesystem\filesystem.h" />
<ClInclude Include="src\Filesystem\path.h" /> <ClInclude Include="src\Filesystem\path.h" />
<ClInclude Include="src\HashFunctions\hash.h" /> <ClInclude Include="src\HashFunctions\hash.h" />
<ClInclude Include="src\Hashtable\Hashtable.h" /> <ClInclude Include="src\Hashtable\Hashtable.h" />
<ClInclude Include="src\Hashtable\KeyValuePair.h" /> <ClInclude Include="src\Hashtable\KeyValuePair.h" />
<ClInclude Include="src\kprint\kprint.h" /> <ClInclude Include="src\kprint\kprint.h" />
<ClInclude Include="src\kprint\kprintf.h" /> <ClInclude Include="src\kprint\kprintf.h" />
<ClInclude Include="src\kprint\kprint_colors.h" /> <ClInclude Include="src\kprint\kprint_colors.h" />
<ClInclude Include="src\kprint\kprint_format.h" /> <ClInclude Include="src\kprint\kprint_format.h" />
<ClInclude Include="src\random\krandom.h" /> <ClInclude Include="src\random\krandom.h" />
<ClInclude Include="src\random\splitmix64\splitmix64.h" /> <ClInclude Include="src\random\splitmix64\splitmix64.h" />
<ClInclude Include="src\random\xoroshiro\32bitValue\xoroshiro64.h" /> <ClInclude Include="src\random\xoroshiro\32bitValue\xoroshiro64.h" />
<ClInclude Include="src\random\xoroshiro\64bitValue\xoroshiro128.h" /> <ClInclude Include="src\random\xoroshiro\64bitValue\xoroshiro128.h" />
<ClInclude Include="src\random\xoroshiro\xoroshiro.h" /> <ClInclude Include="src\random\xoroshiro\xoroshiro.h" />
<ClInclude Include="src\random\xoshiro\32bitValue\xoshiro128.h" /> <ClInclude Include="src\random\xoshiro\32bitValue\xoshiro128.h" />
<ClInclude Include="src\random\xoshiro\64bitValue\xoshiro256.h" /> <ClInclude Include="src\random\xoshiro\64bitValue\xoshiro256.h" />
<ClInclude Include="src\random\xoshiro\xoshiro.h" /> <ClInclude Include="src\random\xoshiro\xoshiro.h" />
<ClInclude Include="src\SearchTree\SearchTree.h" /> <ClInclude Include="src\SearchTree\SearchTree.h" />
<ClInclude Include="src\String\string.h" /> <ClInclude Include="src\String\string.h" />
<ClInclude Include="src\String\StringBuilder.h" /> <ClInclude Include="src\String\StringBuilder.h" />
<ClInclude Include="tests\tests.h" /> <ClInclude Include="tests\tests.h" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion> <VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<ProjectGuid>{52f0bd29-a3cb-47ce-b25d-ceaf5dfb2d73}</ProjectGuid> <ProjectGuid>{52f0bd29-a3cb-47ce-b25d-ceaf5dfb2d73}</ProjectGuid>
<RootNamespace>kerep</RootNamespace> <RootNamespace>kerep</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
<CLRSupport>false</CLRSupport> <CLRSupport>false</CLRSupport>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
<CLRSupport>false</CLRSupport> <CLRSupport>false</CLRSupport>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
<CLRSupport>false</CLRSupport> <CLRSupport>false</CLRSupport>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
<CLRSupport>false</CLRSupport> <CLRSupport>false</CLRSupport>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
<ImportGroup Label="Shared"> <ImportGroup Label="Shared">
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>bin\$(Configuration)-$(Platform)\</OutDir> <OutDir>bin\$(Configuration)-$(Platform)\</OutDir>
<IntDir>obj\$(Configuration)-$(Platform)\</IntDir> <IntDir>obj\$(Configuration)-$(Platform)\</IntDir>
<RunCodeAnalysis>true</RunCodeAnalysis> <RunCodeAnalysis>true</RunCodeAnalysis>
<ManagedAssembly>false</ManagedAssembly> <ManagedAssembly>false</ManagedAssembly>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>bin\x86\</OutDir> <OutDir>bin\x86\</OutDir>
<IntDir>obj\x86\</IntDir> <IntDir>obj\x86\</IntDir>
<RunCodeAnalysis>true</RunCodeAnalysis> <RunCodeAnalysis>true</RunCodeAnalysis>
<ManagedAssembly>false</ManagedAssembly> <ManagedAssembly>false</ManagedAssembly>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<RunCodeAnalysis>true</RunCodeAnalysis> <RunCodeAnalysis>true</RunCodeAnalysis>
<OutDir>bin\$(Configuration)-$(Platform)\</OutDir> <OutDir>bin\$(Configuration)-$(Platform)\</OutDir>
<IntDir>obj\$(Configuration)-$(Platform)\</IntDir> <IntDir>obj\$(Configuration)-$(Platform)\</IntDir>
<ManagedAssembly>false</ManagedAssembly> <ManagedAssembly>false</ManagedAssembly>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<RunCodeAnalysis>true</RunCodeAnalysis> <RunCodeAnalysis>true</RunCodeAnalysis>
<OutDir>bin\x64\</OutDir> <OutDir>bin\x64\</OutDir>
<IntDir>obj\x64\</IntDir> <IntDir>obj\x64\</IntDir>
<ManagedAssembly>false</ManagedAssembly> <ManagedAssembly>false</ManagedAssembly>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>TurnOffAllWarnings</WarningLevel> <WarningLevel>TurnOffAllWarnings</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile> <PrecompiledHeaderFile>
</PrecompiledHeaderFile> </PrecompiledHeaderFile>
<LanguageStandard_C>stdc17</LanguageStandard_C> <LanguageStandard_C>stdc17</LanguageStandard_C>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<PrecompiledHeaderOutputFile /> <PrecompiledHeaderOutputFile />
<AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions>
<CompileAs>Default</CompileAs> <CompileAs>Default</CompileAs>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<DebugInformationFormat>None</DebugInformationFormat> <DebugInformationFormat>None</DebugInformationFormat>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC> <EnableUAC>false</EnableUAC>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>TurnOffAllWarnings</WarningLevel> <WarningLevel>TurnOffAllWarnings</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile> <PrecompiledHeaderFile>
</PrecompiledHeaderFile> </PrecompiledHeaderFile>
<LanguageStandard_C>stdc17</LanguageStandard_C> <LanguageStandard_C>stdc17</LanguageStandard_C>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<PrecompiledHeaderOutputFile /> <PrecompiledHeaderOutputFile />
<AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<CompileAs>Default</CompileAs> <CompileAs>Default</CompileAs>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<DebugInformationFormat>None</DebugInformationFormat> <DebugInformationFormat>None</DebugInformationFormat>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC> <EnableUAC>false</EnableUAC>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile> <ClCompile>
<WarningLevel>TurnOffAllWarnings</WarningLevel> <WarningLevel>TurnOffAllWarnings</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile> <PrecompiledHeaderFile>
</PrecompiledHeaderFile> </PrecompiledHeaderFile>
<LanguageStandard_C>stdc17</LanguageStandard_C> <LanguageStandard_C>stdc17</LanguageStandard_C>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<PrecompiledHeaderOutputFile /> <PrecompiledHeaderOutputFile />
<AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions>
<CompileAs>Default</CompileAs> <CompileAs>Default</CompileAs>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<DebugInformationFormat>None</DebugInformationFormat> <DebugInformationFormat>None</DebugInformationFormat>
<TreatAngleIncludeAsExternal>true</TreatAngleIncludeAsExternal> <TreatAngleIncludeAsExternal>true</TreatAngleIncludeAsExternal>
<DisableAnalyzeExternal>true</DisableAnalyzeExternal> <DisableAnalyzeExternal>true</DisableAnalyzeExternal>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC> <EnableUAC>false</EnableUAC>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
<WarningLevel>TurnOffAllWarnings</WarningLevel> <WarningLevel>TurnOffAllWarnings</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;KEREP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile> <PrecompiledHeaderFile>
</PrecompiledHeaderFile> </PrecompiledHeaderFile>
<LanguageStandard_C>stdc17</LanguageStandard_C> <LanguageStandard_C>stdc17</LanguageStandard_C>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<PrecompiledHeaderOutputFile /> <PrecompiledHeaderOutputFile />
<AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/Zc:twoPhase- /MP -fms-compatibility-version=14 -Wno-clang-analyzer-valist.Uninitialized %(AdditionalOptions)</AdditionalOptions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<CompileAs>Default</CompileAs> <CompileAs>Default</CompileAs>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<DebugInformationFormat>None</DebugInformationFormat> <DebugInformationFormat>None</DebugInformationFormat>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC> <EnableUAC>false</EnableUAC>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -1,27 +0,0 @@
#include "Array.h"
Array_define(char)
Array_define(bool)
Array_define(f32)
Array_define(f64)
Array_define(i8)
Array_define(u8)
Array_define(i16)
Array_define(u16)
Array_define(i32)
Array_define(u32)
Array_define(i64)
Array_define(u64)
Array_define(Pointer)
Array_define(Unitype)
void Array_Unitype_free_(Array_Unitype* array, bool freeMembers){
if(freeMembers) for (u32 i=0; i<array->length; i++)
Unitype_free(array->values[i]);
if(array->allocatedOnHeap)
free(array->values);
}
void __Array_Unitype_free_(void* ar)
{ Array_Unitype_free_(ar, true); }

View File

@@ -1,32 +0,0 @@
#pragma once
#if __cplusplus
extern "C" {
#endif
#include "Array_declare.h"
#include "Array_define.h"
Array_declare(char)
Array_declare(bool)
Array_declare(f32)
Array_declare(f64)
Array_declare(i8)
Array_declare(u8)
Array_declare(i16)
Array_declare(u16)
Array_declare(i32)
Array_declare(u32)
Array_declare(i64)
Array_declare(u64)
Array_declare(Pointer)
Array_declare(Unitype)
/// use this function instead of auto generated
void Array_Unitype_free_(Array_Unitype* array, bool freeMembers);
void __Array_Unitype_free_(void* ar);
#if __cplusplus
}
#endif

View File

@@ -1,39 +0,0 @@
#pragma once
#if __cplusplus
extern "C" {
#endif
#include "../base/base.h"
#define Array_declare(type) \
STRUCT(Array_##type, \
type* values; \
u32 length; \
bool allocatedOnHeap; \
) \
\
static inline Array_##type Array_##type##_allocValues(u32 length){ \
return (Array_##type) { \
.values=(type*)malloc(sizeof(type)*length), \
.length=length, \
.allocatedOnHeap=true \
}; \
} \
\
static inline Array_##type Array_##type##_fromBuffer(type* buffer, u32 bufferLength, bool allocatedOnHeap){ \
return (Array_##type) { \
.values=buffer, \
.length=bufferLength, \
.allocatedOnHeap=allocatedOnHeap \
}; \
} \
\
static inline void Array_##type##_free(Array_##type* array){ \
if(array->allocatedOnHeap) \
free(array->values); \
}
#if __cplusplus
}
#endif

View File

@@ -1,14 +0,0 @@
#pragma once
#if __cplusplus
extern "C" {
#endif
#include "../base/base.h"
#define Array_define(type) \
kt_define(Array_##type, (freeMembers_t)Array_##type##_free, NULL);
#if __cplusplus
}
#endif

View File

@@ -1,2 +0,0 @@
# Array struct
This struct stores array pointer and length. If you want to use `Array` of some type, it should be declared in header file by macro `Array_declare` and defined in source file by `Array_define`.

View File

@@ -40,4 +40,4 @@ Autoarr_declare(Unitype)
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -9,8 +9,8 @@ EXPORT void CALL kerep_Autoarr_KVPair_create(u16 max_chunks_count, u16 max_chunk
*output=Autoarr_create(KVPair, max_chunks_count, max_chunk_length); *output=Autoarr_create(KVPair, max_chunks_count, max_chunk_length);
} }
EXPORT void CALL kerep_Autoarr_KVPair_free(Autoarr_KVPair* ar){ EXPORT void CALL kerep_Autoarr_KVPair_destruct(Autoarr_KVPair* ar){
Autoarr_free(ar, true); Autoarr_destruct(ar, true);
} }
EXPORT void CALL kerep_Autoarr_KVPair_get(Autoarr_KVPair* ar, u32 index, KVPair* output){ EXPORT void CALL kerep_Autoarr_KVPair_get(Autoarr_KVPair* ar, u32 index, KVPair* output){
@@ -35,4 +35,4 @@ EXPORT void CALL kerep_Autoarr_KVPair_max_length(Autoarr_KVPair* ar, u32* output
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -8,8 +8,8 @@ EXPORT void CALL kerep_Autoarr_Unitype_create(u16 max_chunks_count, u16 max_chun
*output=Autoarr_create(Unitype, max_chunks_count, max_chunk_length); *output=Autoarr_create(Unitype, max_chunks_count, max_chunk_length);
} }
EXPORT void CALL kerep_Autoarr_Unitype_free(Autoarr_Unitype* ar){ EXPORT void CALL kerep_Autoarr_Unitype_destruct(Autoarr_Unitype* ar){
Autoarr_free(ar, true); Autoarr_destruct(ar, true);
} }
EXPORT void CALL kerep_Autoarr_Unitype_get(Autoarr_Unitype* ar, u32 index, Unitype* output){ EXPORT void CALL kerep_Autoarr_Unitype_get(Autoarr_Unitype* ar, u32 index, Unitype* output){
@@ -34,4 +34,4 @@ EXPORT void CALL kerep_Autoarr_Unitype_max_length(Autoarr_Unitype* ar, u32* outp
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -32,8 +32,8 @@ STRUCT(Autoarr_##type, \
) \ ) \
\ \
Autoarr_##type* __Autoarr_##type##_create(u16 max_chunks_count, u16 max_chunk_length); \ Autoarr_##type* __Autoarr_##type##_create(u16 max_chunks_count, u16 max_chunk_length); \
void __Autoarr_##type##_freeWithMembers(Autoarr_##type* ar, bool freePtr); \ void __Autoarr_##type##_destructWithMembers(Autoarr_##type* ar, bool freePtr); \
void ____Autoarr_##type##_freeWithMembers(void* ar); void ____Autoarr_##type##_destructWithMembers(void* ar);
#define Autoarr(type) Autoarr_##type #define Autoarr(type) Autoarr_##type
@@ -47,9 +47,9 @@ void ____Autoarr_##type##_freeWithMembers(void* ar);
autoarr->functions->getPtr(autoarr,index) autoarr->functions->getPtr(autoarr,index)
#define Autoarr_set(autoarr, index, element) \ #define Autoarr_set(autoarr, index, element) \
autoarr->functions->set(autoarr, index, element) autoarr->functions->set(autoarr, index, element)
#define Autoarr_free(autoarr, freePtr) \ #define Autoarr_destruct(autoarr, freePtr) \
autoarr->functions->freeWithMembers(autoarr, freePtr) autoarr->functions->freeWithMembers(autoarr, freePtr)
#define Autoarr_freeWithoutMembers(autoarr, freePtr) \ #define Autoarr_destructWithoutMembers(autoarr, freePtr) \
autoarr->functions->freeWithoutMembers(autoarr, freePtr) autoarr->functions->freeWithoutMembers(autoarr, freePtr)
#define Autoarr_toArray(autoarr) \ #define Autoarr_toArray(autoarr) \
autoarr->functions->toArray(autoarr) autoarr->functions->toArray(autoarr)
@@ -71,4 +71,4 @@ void ____Autoarr_##type##_freeWithMembers(void* ar);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -8,7 +8,7 @@ extern "C" {
#define Autoarr_define(type, TYPE_IS_PTR) \ #define Autoarr_define(type, TYPE_IS_PTR) \
\ \
kt_define(Autoarr_##type, ____Autoarr_##type##_freeWithMembers, NULL); \ kt_define(Autoarr_##type, ____Autoarr_##type##_destructWithMembers, NULL); \
\ \
void __Autoarr_##type##_add(Autoarr_##type* ar, type element){ \ void __Autoarr_##type##_add(Autoarr_##type* ar, type element){ \
if(!ar->chunks){ \ if(!ar->chunks){ \
@@ -41,14 +41,14 @@ void __Autoarr_##type##_set(Autoarr_##type* ar, u32 index, type element){ \
ar->chunks[index/ar->max_chunk_length][index%ar->max_chunk_length]=element; \ ar->chunks[index/ar->max_chunk_length][index%ar->max_chunk_length]=element; \
} \ } \
\ \
void __Autoarr_##type##_freeWithoutMembers(Autoarr_##type* ar, bool freePtr){ \ void __Autoarr_##type##_destructWithoutMembers(Autoarr_##type* ar, bool freePtr){ \
for(u16 i=0; i<ar->chunks_count;i++) \ for(u16 i=0; i<ar->chunks_count;i++) \
free(ar->chunks[i]); \ free(ar->chunks[i]); \
free(ar->chunks); \ free(ar->chunks); \
if(freePtr) free(ar); \ if(freePtr) free(ar); \
} \ } \
\ \
void __Autoarr_##type##_freeWithMembers(Autoarr_##type* ar, bool freePtr){ \ void __Autoarr_##type##_destructWithMembers(Autoarr_##type* ar, bool freePtr){ \
if(ktDescriptor_##type.freeMembers!=NULL) { \ if(ktDescriptor_##type.freeMembers!=NULL) { \
Autoarr_foreach(ar, el, \ Autoarr_foreach(ar, el, \
void* members_ptr=&el; \ void* members_ptr=&el; \
@@ -56,10 +56,10 @@ void __Autoarr_##type##_freeWithMembers(Autoarr_##type* ar, bool freePtr){ \
ktDescriptor_##type.freeMembers(members_ptr); \ ktDescriptor_##type.freeMembers(members_ptr); \
); \ ); \
} \ } \
__Autoarr_##type##_freeWithoutMembers(ar, freePtr);\ __Autoarr_##type##_destructWithoutMembers(ar, freePtr); \
} \ } \
void ____Autoarr_##type##_freeWithMembers(void* ar){ \ void ____Autoarr_##type##_destructWithMembers(void* ar){ \
__Autoarr_##type##_freeWithMembers((Autoarr_##type*)ar, false); \ __Autoarr_##type##_destructWithMembers((Autoarr_##type*)ar, false); \
} \ } \
\ \
type* __Autoarr_##type##_toArray(Autoarr_##type* ar){ \ type* __Autoarr_##type##_toArray(Autoarr_##type* ar){ \
@@ -77,8 +77,8 @@ __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list={ \
&__Autoarr_##type##_get, \ &__Autoarr_##type##_get, \
&__Autoarr_##type##_getPtr, \ &__Autoarr_##type##_getPtr, \
&__Autoarr_##type##_set, \ &__Autoarr_##type##_set, \
&__Autoarr_##type##_freeWithMembers, \ &__Autoarr_##type##_destructWithMembers, \
&__Autoarr_##type##_freeWithoutMembers, \ &__Autoarr_##type##_destructWithoutMembers, \
&__Autoarr_##type##_toArray \ &__Autoarr_##type##_toArray \
}; \ }; \
\ \
@@ -97,4 +97,4 @@ Autoarr_##type* __Autoarr_##type##_create(u16 max_chunks_count, u16 max_chunk_le
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -25,6 +25,6 @@ bool DtsodV24_remove(Hashtable* dtsod, char* key){
} }
// frees memory including memory of elements (hashtables, autoarrs, etc.) // frees memory including memory of elements (hashtables, autoarrs, etc.)
void DtsodV24_free(Hashtable* dtsod){ void DtsodV24_destruct(Hashtable* dtsod){
Hashtable_free(dtsod); Hashtable_destruct(dtsod);
} }

View File

@@ -25,8 +25,8 @@ bool DtsodV24_contains(Hashtable* dtsod, char* key);
bool DtsodV24_remove(Hashtable* dtsod, char* key); bool DtsodV24_remove(Hashtable* dtsod, char* key);
// frees memory including memory of elements (hashtables, autoarrs, etc.) // frees memory including memory of elements (hashtables, autoarrs, etc.)
void DtsodV24_free(Hashtable* dtsod); void DtsodV24_destruct(Hashtable* dtsod);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -44,16 +44,10 @@ Maybe ERROR_WRONGCHAR(const char c, char* _text, char* text_first, const char* s
if(!_c) break; if(!_c) break;
} }
char errmsg[1024]; char errmsg[1024];
IFMSC( sprintf_s(errmsg, sizeof(errmsg), "unexpected <%c> at:\n"
sprintf_s(errmsg,1024, "unexpected <%c> at:\n" " \"%s\"\n"
" \"%s\"\n" "\\___[%s:%d] %s()",
"\\___[%s:%d] %s()", c,errBuf, srcfile,line,funcname);
c,errBuf, srcfile,line,funcname),
sprintf(errmsg, "unexpected <%c> at:\n"
" \"%s\"\n"
" \\___[%s:%d] %s()",
c,errBuf, srcfile,line,funcname)
);
safethrow(errmsg,;); safethrow(errmsg,;);
} }
#define safethrow_wrongchar(C, freeMem) { freeMem; return ERROR_WRONGCHAR(C, text, shared->sh_text_first, __FILE__,__LINE__,__func__); } #define safethrow_wrongchar(C, freeMem) { freeMem; return ERROR_WRONGCHAR(C, text, shared->sh_text_first, __FILE__,__LINE__,__func__); }
@@ -96,7 +90,7 @@ Maybe __ReadName(DeserializeSharedData* shared){
nameStr.ptr=text+1; // skips '\n' nameStr.ptr=text+1; // skips '\n'
break; break;
case '}': case '}':
if(!calledRecursively || nameStr.length!=0) if(!calledRecursively || nameStr.length!=0)
safethrow_wrongchar(c,;); safethrow_wrongchar(c,;);
return SUCCESS(UniHeapPtr(char,NULL)); return SUCCESS(UniHeapPtr(char,NULL));
case ':': case ':':
@@ -131,7 +125,7 @@ Maybe __ReadString(DeserializeSharedData* shared){
if(c=='"') { if(c=='"') {
if(prevIsBackslash) { if(prevIsBackslash) {
// replacing <\"> with <"> // replacing <\"> with <">
StringBuilder_rmchar(b); StringBuilder_rmchar(b);
StringBuilder_append_char(b,c); StringBuilder_append_char(b,c);
prevIsBackslash=false; prevIsBackslash=false;
} }
@@ -139,14 +133,14 @@ Maybe __ReadString(DeserializeSharedData* shared){
char* str=StringBuilder_build(b).ptr; char* str=StringBuilder_build(b).ptr;
return SUCCESS(UniHeapPtr(char,str)); return SUCCESS(UniHeapPtr(char,str));
} }
} }
else { else {
prevIsBackslash= c=='\\' && !prevIsBackslash; prevIsBackslash= c=='\\' && !prevIsBackslash;
StringBuilder_append_char(b,c); StringBuilder_append_char(b,c);
} }
} }
safethrow(ERR_ENDOFSTR, StringBuilder_free(b)); safethrow(ERR_ENDOFSTR, StringBuilder_destruct(b));
} }
#define ReadString() __ReadString(shared) #define ReadString() __ReadString(shared)
@@ -154,8 +148,8 @@ Maybe __ReadList(DeserializeSharedData* shared){
Autoarr(Unitype)* list=Autoarr_create(Unitype,ARR_BC,ARR_BL); Autoarr(Unitype)* list=Autoarr_create(Unitype,ARR_BC,ARR_BL);
bool readingList=true; bool readingList=true;
while (true){ while (true){
try(ReadValue((&readingList)), m_val, Autoarr_free(list, true)) try(ReadValue((&readingList)), m_val, Autoarr_destruct(list, true))
Autoarr_add(list,m_val.value); Autoarr_add(list,m_val.value);
if (!readingList){ if (!readingList){
if(Unitype_isUniNull(m_val.value)) if(Unitype_isUniNull(m_val.value))
Autoarr_pop(list); Autoarr_pop(list);
@@ -192,10 +186,7 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
char* _c=string_extract(str); char* _c=string_extract(str);
if(sscanf(_c, IFWIN("%llu", "%lu"), &lu)!=1){ if(sscanf(_c, IFWIN("%llu", "%lu"), &lu)!=1){
char err[64]; char err[64];
IFMSC( sprintf_s(err, sizeof(err), "can't parse to int: <%s>", _c);
sprintf_s(err,64,"can't parse to int: <%s>",_c),
sprintf(err,"can't parse to int: <%s>",_c)
);
safethrow(err,free(_c)); safethrow(err,free(_c));
} }
free(_c); free(_c);
@@ -208,10 +199,7 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
char* _c=string_extract(str); char* _c=string_extract(str);
if(sscanf(_c, IFWIN("%lli", "%li"), &li)!=1){ if(sscanf(_c, IFWIN("%lli", "%li"), &li)!=1){
char err[64]; char err[64];
IFMSC( sprintf_s(err, sizeof(err),"can't parse to int: <%s>",_c);
sprintf_s(err,64,"can't parse to int: <%s>",_c),
sprintf(err,"can't parse to int: <%s>",_c)
);
safethrow(err,free(_c)); safethrow(err,free(_c));
} }
free(_c); free(_c);
@@ -239,53 +227,53 @@ Maybe __ReadValue(DeserializeSharedData* shared, bool* readingList){
spaceAfterVal=true; spaceAfterVal=true;
else valueStr.ptr++; else valueStr.ptr++;
break; break;
case '=': case ':': case '=': case ':':
case '}': case '$': case '}': case '$':
case '\'': case '\'':
safethrow_wrongchar(c,Unitype_free(value)); safethrow_wrongchar(c,Unitype_destruct(&value));
case '#':; case '#':;
char _c=c; char _c=c;
char* _text=text; char* _text=text;
try(SkipComment(),_,;); try(SkipComment(),_,;);
if(valueStr.length!=0){ if(valueStr.length!=0){
text=_text; text=_text;
safethrow_wrongchar(_c,Unitype_free(value)); safethrow_wrongchar(_c,Unitype_destruct(&value));
} }
valueStr.ptr=text+1; // skips '\n' valueStr.ptr=text+1; // skips '\n'
break; break;
case '"': case '"':
if(valueStr.length!=0) safethrow_wrongchar(c,Unitype_free(value)); if(valueStr.length!=0) safethrow_wrongchar(c,Unitype_destruct(&value));
try(ReadString(),maybeString,;) try(ReadString(),maybeString,;)
value=maybeString.value; value=maybeString.value;
break; break;
case '{': case '{':
if(valueStr.length!=0) safethrow_wrongchar(c,Unitype_free(value)); if(valueStr.length!=0) safethrow_wrongchar(c,Unitype_destruct(&value));
++text; // skips '{' ++text; // skips '{'
try(__deserialize(&text,true), val,Unitype_free(value)) try(__deserialize(&text,true), val,Unitype_destruct(&value))
value=val.value; value=val.value;
break; break;
case '[': case '[':
if(valueStr.length!=0) safethrow_wrongchar(c,Unitype_free(value)); if(valueStr.length!=0) safethrow_wrongchar(c,Unitype_destruct(&value));
try(ReadList(),maybeList,Unitype_free(value)) try(ReadList(),maybeList,Unitype_destruct(&value))
value=maybeList.value; value=maybeList.value;
break; break;
case ']': case ']':
if(!readingList) safethrow_wrongchar(c,Unitype_free(value)); if(!readingList) safethrow_wrongchar(c,Unitype_destruct(&value));
*readingList=false; *readingList=false;
goto return_value; goto return_value;
case ';': case ';':
case ',': case ',':
return_value: return_value:
if(valueStr.length!=0){ if(valueStr.length!=0){
if(!Unitype_isUniNull(value)) if(!Unitype_isUniNull(value))
safethrow_wrongchar(c,Unitype_free(value)); safethrow_wrongchar(c,Unitype_destruct(&value));
try(ParseValue(valueStr),maybeParsed,;) try(ParseValue(valueStr),maybeParsed,;)
value=maybeParsed.value; value=maybeParsed.value;
} }
return SUCCESS(value); return SUCCESS(value);
default: default:
if(spaceAfterVal) if(spaceAfterVal)
safethrow_wrongchar(c,Unitype_free(value)); safethrow_wrongchar(c,Unitype_destruct(&value));
valueStr.length++; valueStr.length++;
break; break;
} }
@@ -306,12 +294,12 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
text--; text--;
while(true){ while(true){
try(ReadName(), maybeName, Hashtable_free(dict)) try(ReadName(), maybeName, Hashtable_destruct(dict))
if(!maybeName.value.VoidPtr) // end of file or '}' in recursive call if(!maybeName.value.VoidPtr) // end of file or '}' in recursive call
goto END; goto END;
char* nameCPtr=maybeName.value.VoidPtr; char* nameCPtr=maybeName.value.VoidPtr;
try(ReadValue(NULL), val, { try(ReadValue(NULL), val, {
Hashtable_free(dict); Hashtable_destruct(dict);
free(nameCPtr); free(nameCPtr);
}) { }) {
if(partOfDollarList){ if(partOfDollarList){

View File

@@ -1,8 +1,8 @@
// //
// I planned to export functions from DtsodV24.h, // I planned to export functions from DtsodV24.h,
// but C# P/Invoke can't get returned values for some reason. // but C# P/Invoke can't get returned values for some reason.
// Following functions return values by pointer, which looks in C# like out parameter // Following functions return values by pointer, which looks in C# like out parameter
// //
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
@@ -45,8 +45,8 @@ EXPORT void CALL kerep_DtsodV24_remove(Hashtable* dtsod, char* key, bool* output
} }
// replaces value with UniNull if key exists in dtsod // replaces value with UniNull if key exists in dtsod
EXPORT void CALL kerep_DtsodV24_free(Hashtable* dtsod){ EXPORT void CALL kerep_DtsodV24_destruct(Hashtable* dtsod){
DtsodV24_free(dtsod); DtsodV24_destruct(dtsod);
} }
EXPORT void CALL kerep_DtsodV24_height(Hashtable* dtsod, u16* heigth){ EXPORT void CALL kerep_DtsodV24_height(Hashtable* dtsod, u16* heigth){
@@ -59,4 +59,4 @@ EXPORT void CALL kerep_DtsodV24_getrow(Hashtable* dtsod, u16 h, Autoarr_KVPair**
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -3,7 +3,7 @@
STRUCT(SerializeSharedData, STRUCT(SerializeSharedData,
StringBuilder* sh_builder; StringBuilder* sh_builder;
u8 sh_tabs; u8 sh_tabs;
) )
#define b shared->sh_builder #define b shared->sh_builder
@@ -55,7 +55,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
AppendTabs(); AppendTabs();
addc('['); addc('[');
tabs++; tabs++;
Autoarr_foreach(((Autoarr_Unitype*)(u.VoidPtr)), e, Autoarr_foreach(((Autoarr_Unitype*)(u.VoidPtr)), e,
addc('\n'); addc('\n');
AppendTabs(); AppendTabs();
try(AppendValue(e),__,;); try(AppendValue(e),__,;);
@@ -75,7 +75,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
else if(u.typeId==ktid_ptrName(Hashtable)){ else if(u.typeId==ktid_ptrName(Hashtable)){
// check hashtable is blank // check hashtable is blank
bool hashtableNotBlank=false; bool hashtableNotBlank=false;
Hashtable_foreach(((Hashtable*)u.VoidPtr), __, Hashtable_foreach(((Hashtable*)u.VoidPtr), __,
hashtableNotBlank=true; hashtableNotBlank=true;
if(__.key) {} // weird way to disable warning if(__.key) {} // weird way to disable warning
break; break;
@@ -96,7 +96,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
} }
} }
else { else {
dbg((u.typeId)); dbg((u.typeId));
safethrow(ERR_WRONGTYPE,;); safethrow(ERR_WRONGTYPE,;);
} }
return MaybeNull; return MaybeNull;
@@ -109,7 +109,7 @@ Maybe __serialize(StringBuilder* _b, u8 _tabs, Hashtable* dtsod){
}; };
SerializeSharedData* shared=&_shared; SerializeSharedData* shared=&_shared;
Hashtable_foreach(dtsod, p, Hashtable_foreach(dtsod, p,
AppendTabs(); AppendTabs();
StringBuilder_append_cptr(b,p.key); StringBuilder_append_cptr(b,p.key);
addc(':'); addc(':');
@@ -124,7 +124,7 @@ Maybe __serialize(StringBuilder* _b, u8 _tabs, Hashtable* dtsod){
Maybe DtsodV24_serialize(Hashtable* dtsod){ Maybe DtsodV24_serialize(Hashtable* dtsod){
StringBuilder* sb=StringBuilder_create(); StringBuilder* sb=StringBuilder_create();
try(__serialize(sb,0,dtsod),__, StringBuilder_free(sb)); try(__serialize(sb,0,dtsod),__, StringBuilder_destruct(sb));
char* str=StringBuilder_build(sb).ptr; char* str=StringBuilder_build(sb).ptr;
return SUCCESS(UniHeapPtr(char, str)); return SUCCESS(UniHeapPtr(char, str));
} }

View File

@@ -4,7 +4,7 @@
bool dir_exists(const char* path){ bool dir_exists(const char* path){
if(path[0]=='.'){ if(path[0]=='.'){
if(path[1]==0 || (path[1]==path_sep && path[1]==0)) if(path[1]==0 || (path[1]==path_sep && path[1]==0))
return true; // dir . or ./ always exists return true; // dir . or ./ always exists
// else if(path[1]=='.' && path[2]==path_sep) // else if(path[1]=='.' && path[2]==path_sep)
//TODO path_resolve because windows doesnt recognize .\ pattern //TODO path_resolve because windows doesnt recognize .\ pattern
@@ -26,9 +26,10 @@ bool dir_exists(const char* path){
Maybe dir_create(const char* path){ Maybe dir_create(const char* path){
if (dir_exists(path)) if (dir_exists(path))
return MaybeNull; return MaybeNull;
char* parentDir=path_parentDir(path); LinearAllocator _al; LinearAllocator_construct(&_al, 128);
allocator_ptr al=&_al.base;
char* parentDir=path_parentDir(al, path);
dir_create(parentDir); dir_create(parentDir);
free(parentDir);
#if KFS_USE_WINDOWS_H #if KFS_USE_WINDOWS_H
if(!CreateDirectory(path, NULL)) if(!CreateDirectory(path, NULL))
#else #else
@@ -36,12 +37,10 @@ Maybe dir_create(const char* path){
#endif #endif
{ {
char err[512]; char err[512];
IFWIN( sprintf_s(err, sizeof(err), "can't create dicectory <%s>", path);
sprintf_s(err, 512, "can't create dicectory <%s>", path),
sprintf(err, "can't create dicectory <%s>", path));
safethrow(err,;); safethrow(err,;);
} }
LinearAllocator_destruct(&_al);
return MaybeNull; return MaybeNull;
} }

View File

@@ -25,4 +25,4 @@ Maybe dir_findDirs(const char* path, char* searchPattern, bool recursive);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -2,9 +2,9 @@
#include "../String/StringBuilder.h" #include "../String/StringBuilder.h"
#include "io_includes.h" #include "io_includes.h"
void __file_freeMembers(void* _f){ fclose((FileHandle)_f); } void __file_destructMembers(void* _f){ fclose((FileHandle)_f); }
kt_define(FileHandle, __file_freeMembers, NULL) kt_define(FileHandle, __file_destructMembers, NULL)
bool file_exists(const char* path){ bool file_exists(const char* path){
if(path[0]=='.'){ if(path[0]=='.'){
@@ -50,8 +50,11 @@ char* FileOpenMode_toStr(FileOpenMode m){
Maybe file_open(const char* path, FileOpenMode mode){ Maybe file_open(const char* path, FileOpenMode mode){
FileHandle file=fopen(path, FileOpenMode_toStr(mode)); FileHandle file=fopen(path, FileOpenMode_toStr(mode));
LinearAllocator _al; LinearAllocator_construct(&_al, 128);
allocator_ptr al=&_al.base;
if(!file) if(!file)
safethrow(cptr_concat("can't open file ", (char*)path),;); safethrow(cptr_concat(al, "can't open file ", (char*)path),;);
LinearAllocator_destruct(&_al);
return SUCCESS(UniHeapPtr(FileHandle,file)); return SUCCESS(UniHeapPtr(FileHandle,file));
} }
@@ -117,8 +120,8 @@ Maybe file_readAll(FileHandle file, char** allBytes){
while(true){ while(true){
rezult=fgetc(file); rezult=fgetc(file);
if(rezult==EOF){ if(rezult==EOF){
if(ferror(file)) if(ferror(file))
safethrow(ERR_IO, StringBuilder_free(sb)); safethrow(ERR_IO, StringBuilder_destruct(sb));
break; break;
} }
buffer[i%sizeof(buffer)]=(char)rezult; buffer[i%sizeof(buffer)]=(char)rezult;
@@ -132,7 +135,7 @@ Maybe file_readAll(FileHandle file, char** allBytes){
string str=StringBuilder_build(sb); string str=StringBuilder_build(sb);
*allBytes=str.ptr; *allBytes=str.ptr;
// i dont know how can it happen, but if it will have, it will be very dangerous // i dont know how can it happen, but if it will have, it will be very dangerous
if(i!=str.length) if(i!=str.length)
throw(ERR_UNEXPECTEDVAL); throw(ERR_UNEXPECTEDVAL);
return SUCCESS(UniUInt64(i)); return SUCCESS(UniUInt64(i));
} }

View File

@@ -5,7 +5,6 @@ extern "C" {
#endif #endif
#include "../base/base.h" #include "../base/base.h"
#include "../Array/Array.h"
#include "../String/string.h" #include "../String/string.h"
typedef FILE* FileHandle; typedef FILE* FileHandle;
@@ -17,15 +16,15 @@ bool file_exists(const char* path);
Maybe file_delete(const char* path, bool recursive); Maybe file_delete(const char* path, bool recursive);
PACKED_ENUM(FileOpenMode, PACKED_ENUM(FileOpenMode,
// open a file for reading // open a file for reading
FileOpenMode_Read=1, FileOpenMode_Read=1,
// (re)create a file for writing // (re)create a file for writing
FileOpenMode_Write=2, FileOpenMode_Write=2,
// opens file for writing additional data to the end / creates new file // opens file for writing additional data to the end / creates new file
FileOpenMode_Append=4, FileOpenMode_Append=4,
// (re)creates file for reading/writing // (re)creates file for reading/writing
FileOpenMode_ReadWrite=FileOpenMode_Read|FileOpenMode_Write, FileOpenMode_ReadWrite=FileOpenMode_Read|FileOpenMode_Write,
// opens file for readng/writing additional data to the end / creates new file // opens file for readng/writing additional data to the end / creates new file
FileOpenMode_ReadAppend=FileOpenMode_Read|FileOpenMode_Append FileOpenMode_ReadAppend=FileOpenMode_Read|FileOpenMode_Append
) )
@@ -67,10 +66,10 @@ Maybe file_readChar(FileHandle file);
Maybe file_readBuffer(FileHandle file, char* buffer, u64 length); Maybe file_readBuffer(FileHandle file, char* buffer, u64 length);
/// @brief reads all bytes from file /// @brief reads all bytes from file
/// @param allBytes ptr to the file's content will be pushed there /// @param allBytes ptr to the file's content will be pushed there
/// @return Maybe<u64> total number of successfully read bytes /// @return Maybe<u64> total number of successfully read bytes
Maybe file_readAll(FileHandle file, char** allBytes); Maybe file_readAll(FileHandle file, char** allBytes);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -2,7 +2,7 @@
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
#define KFS_USE_WINDOWS_H 1 #define KFS_USE_WINDOWS_H 1
#else #else
#define KFS_USE_WINDOWS_H 0 #define KFS_USE_WINDOWS_H 0
#endif #endif

View File

@@ -1,8 +1,8 @@
#include "filesystem.h" #include "filesystem.h"
char* __path_concat(u32 n, ...){ char* __path_concat(allocator_ptr al, u32 n, ...){
char** parts=(char**)malloc(n*sizeof(char*)); char** parts=(char**)allocator_alloc(al, n*sizeof(char*));
u32* lengths=malloc(n*sizeof(u32)); u32* lengths=allocator_alloc(al, n*sizeof(u32));
u32 totalLength=0; u32 totalLength=0;
// reading args from va_list // reading args from va_list
@@ -18,7 +18,7 @@ char* __path_concat(u32 n, ...){
va_end(vl); va_end(vl);
// allocating memory for output value // allocating memory for output value
char* totality=malloc(totalLength+1); char* totality=allocator_alloc(al, totalLength+1);
const char* output=totality; const char* output=totality;
totality[totalLength]=0; totality[totalLength]=0;
@@ -32,13 +32,13 @@ char* __path_concat(u32 n, ...){
} }
memcpy(totality, parts[k], lengths[k]); memcpy(totality, parts[k], lengths[k]);
free(parts); allocator_free(al, lengths);
free(lengths); allocator_free(al, parts);
return output; return output;
} }
char* path_fixSeparators(const char* path){ char* path_fixSeparators(allocator_ptr al, const char* path){
char* pathCopy=cptr_copy(path); char* pathCopy=cptr_copy(al, path);
char c; char c;
while((c=*pathCopy)){ while((c=*pathCopy)){
if(c==path_notSep) if(c==path_notSep)
@@ -49,13 +49,16 @@ char* path_fixSeparators(const char* path){
} }
Maybe path_throwIfEscapes(const char* path){ Maybe path_throwIfEscapes(const char* path){
LinearAllocator _al; LinearAllocator_construct(&_al, 128);
allocator_ptr al=&_al.base;
if(cptr_contains(path,"..")) if(cptr_contains(path,".."))
safethrow(cptr_concat("path <",path,"> uses <..>, that's not allowed"),); safethrow(cptr_concat(al, "path <",path,"> uses <..>, that's not allowed"),);
LinearAllocator_destruct(&_al);
return MaybeNull; return MaybeNull;
} }
char* path_parentDir(char* dir){ char* path_parentDir(allocator_ptr al, char* dir){
char* copy=cptr_copy(dir); char* copy=cptr_copy(al, dir);
i32 length=cptr_length(copy); i32 length=cptr_length(copy);
i32 i=cptr_lastIndexOfChar(copy,path_sep); i32 i=cptr_lastIndexOfChar(copy,path_sep);
if(i!=-1 && i==length-1){ if(i!=-1 && i==length-1){
@@ -63,8 +66,8 @@ char* path_parentDir(char* dir){
i=cptr_lastIndexOfChar(copy,path_sep); i=cptr_lastIndexOfChar(copy,path_sep);
} }
if(i==-1){ if(i==-1){
free(copy); allocator_free(al, copy);
copy=malloc(2); copy=allocator_alloc(al, 2);
copy[0]='.'; copy[0]='.';
copy[1]=0; copy[1]=0;
} }
@@ -72,7 +75,7 @@ char* path_parentDir(char* dir){
} }
char* path_basename(char* path, bool with_extension){ char* path_basename(allocator_ptr al, char* path, bool with_extension){
i32 nameIndex=cptr_lastIndexOfChar(path, path_sep)+1; i32 nameIndex=cptr_lastIndexOfChar(path, path_sep)+1;
string rezult=string_fromCptr(path+nameIndex); string rezult=string_fromCptr(path+nameIndex);
if(!with_extension){ if(!with_extension){

View File

@@ -14,17 +14,17 @@ static const char path_sep='/';
static const char path_notSep='\\'; static const char path_notSep='\\';
#endif #endif
char* __path_concat(u32 n, ...); char* __path_concat(allocator_ptr al, u32 n, ...);
/// @brief merges path parts together and puts <path_sep> between them /// @brief merges path parts together and puts <path_sep> between them
/// @return new cstr /// @return new cstr
#define path_concat(PATH_PARTS...) __path_concat(count_args(PATH_PARTS), PATH_PARTS) #define path_concat(ALLOCATOR, PATH_PARTS...) __path_concat(ALLOCATOR, count_args(PATH_PARTS), PATH_PARTS)
/// @brief fixes path separators /// @brief fixes path separators
/// @param cstr where can be <path_notSep> /// @param cstr where can be <path_notSep>
/// @return new cstr with correct separators /// @return new cstr with correct separators
char* path_fixSeparators(const char* path); char* path_fixSeparators(allocator_ptr al, const char* path);
#define path_resolve(PATH_PARTS...) path_fixSeparators(path_concat(PATH_PARTS)) #define path_resolve(ALLOCATOR, PATH_PARTS...) path_fixSeparators(ALLOCATOR, path_concat(ALLOCATOR, PATH_PARTS))
/// @brief calls safethrow() if finds escape sequense in path /// @brief calls safethrow() if finds escape sequense in path
/// @param path cstr where can be <..> /// @param path cstr where can be <..>
@@ -32,11 +32,11 @@ char* path_fixSeparators(const char* path);
Maybe path_throwIfEscapes(const char* path); Maybe path_throwIfEscapes(const char* path);
///@return path of parent dir ///@return path of parent dir
char* path_parentDir(char* path); char* path_parentDir(allocator_ptr al, char* path);
///@return file name ///@return file name
char* path_basename(char* path, bool with_extension); char* path_basename(allocator_ptr al, char* path, bool with_extension);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -9,68 +9,68 @@ u32 hash_sdbm32(u32 oldhash, void* buf, u32 len){
} }
static const u32 crc_32_tab[]={ static const u32 crc_32_tab[]={
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
}; };

View File

@@ -14,4 +14,4 @@ u32 hash_crc32(u32 oldhash, void* buf, u32 len);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -1,6 +1,6 @@
#include "Hashtable.h" #include "Hashtable.h"
kt_define(Hashtable, __Hashtable_free, NULL); kt_define(Hashtable, __Hashtable_destruct, NULL);
// amount of rows // amount of rows
static const u16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521}; static const u16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521};
@@ -19,14 +19,14 @@ Hashtable* Hashtable_create(){
return ht; return ht;
} }
void __Hashtable_free(void* _ht){ void __Hashtable_destruct(void* _ht){
Hashtable* ht=_ht; Hashtable* ht=_ht;
for(u16 i=0;i<HT_HEIGHTS[ht->hein];i++) for(u16 i=0;i<HT_HEIGHTS[ht->hein];i++)
Autoarr_free(ht->rows[i], true); Autoarr_destruct(ht->rows[i], true);
free(ht->rows); free(ht->rows);
} }
void Hashtable_free(Hashtable* ht){ void Hashtable_destruct(Hashtable* ht){
__Hashtable_free(ht); __Hashtable_destruct(ht);
free(ht); free(ht);
} }
@@ -51,7 +51,7 @@ void Hashtable_expand(Hashtable* ht){
} }
// there is no need to free array values, because they are copied into new array // there is no need to free array values, because they are copied into new array
// so dont replace this incorrect auto-generated function // so dont replace this incorrect auto-generated function
Autoarr_freeWithoutMembers(ar, true); Autoarr_destructWithoutMembers(ar, true);
} }
free(ht->rows); free(ht->rows);
@@ -68,7 +68,7 @@ Autoarr(KVPair)* getrow(Hashtable* ht, char* key, bool can_expand){
} }
/// @param key must be heap allocated /// @param key must be heap allocated
/// Hashtable_free will free this pointer /// Hashtable_destruct will free this pointer
void Hashtable_add(Hashtable* ht, char* key, Unitype u){ void Hashtable_add(Hashtable* ht, char* key, Unitype u){
KVPair p={ .key=key, .value=u }; KVPair p={ .key=key, .value=u };
Autoarr_add(getrow(ht,key,true),p); Autoarr_add(getrow(ht,key,true),p);

View File

@@ -9,13 +9,13 @@ extern "C" {
#include "KeyValuePair.h" #include "KeyValuePair.h"
STRUCT(Hashtable, STRUCT(Hashtable,
u8 hein; // height=HT_HEIGHTS[hein] u8 hein; // height=HT_HEIGHTS[hein]
Autoarr(KVPair)** rows; // Autoarr[height] Autoarr(KVPair)** rows; // Autoarr[height]
) )
Hashtable* Hashtable_create(); Hashtable* Hashtable_create();
void Hashtable_free(Hashtable* ht); void Hashtable_destruct(Hashtable* ht);
void __Hashtable_free(void* ht); void __Hashtable_destruct(void* ht);
// amount of rows // amount of rows
u16 Hashtable_height(Hashtable* ht); u16 Hashtable_height(Hashtable* ht);
@@ -46,4 +46,4 @@ bool Hashtable_tryGet(Hashtable* ht, char* key, Unitype* output);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -1,15 +1,15 @@
#include "KeyValuePair.h" #include "KeyValuePair.h"
kt_define(KVPair, __KVPair_free, NULL); kt_define(KVPair, __KVPair_destruct, NULL);
Autoarr_define(KVPair, false) Autoarr_define(KVPair, false)
// proper way to clean a KVP // proper way to clean a KVP
void KVPair_free(KVPair p){ void KVPair_destruct(KVPair p){
free(p.key); free(p.key);
Unitype_free(p.value); Unitype_destruct(&p.value);
} }
void __KVPair_free(void* p){ KVPair_free(*(KVPair*)p); } void __KVPair_destruct(void* p){ KVPair_destruct(*(KVPair*)p); }
void printkvp(KVPair p){ void printkvp(KVPair p){
kprintf("{\"%s\", ",p.key); kprintf("{\"%s\", ",p.key);

View File

@@ -15,11 +15,11 @@ STRUCT(KVPair,
Autoarr_declare(KVPair) Autoarr_declare(KVPair)
// proper way to clean a KVP // proper way to clean a KVP
void KVPair_free(KVPair p); void KVPair_destruct(KVPair p);
void __KVPair_free(void* p); void __KVPair_destruct(void* p);
void printkvp(KVPair p); void printkvp(KVPair p);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -34,7 +34,7 @@ void LinkedList_addToEnd(void* _llist, void* _new_node) {
llist->last_node=new_node; llist->last_node=new_node;
} }
static inline void _insertNode(LinkedList(Pointer)* llist, static inline void _insertNode(LinkedList(Pointer)* llist,
LLNode(Pointer)* prev_node, LLNode(Pointer)* new_node, LLNode(Pointer)* next_node){ LLNode(Pointer)* prev_node, LLNode(Pointer)* new_node, LLNode(Pointer)* next_node){
if(prev_node==NULL){ if(prev_node==NULL){
if(next_node==llist->first_node) if(next_node==llist->first_node)

View File

@@ -16,7 +16,7 @@ extern "C" {
#define LLNode_create(TYPE, VALUE) LLNode_##TYPE##_create(VALUE) #define LLNode_create(TYPE, VALUE) LLNode_##TYPE##_create(VALUE)
#define LinkedList_create(TYPE) LinkedList_##TYPE##_create() #define LinkedList_create(TYPE) LinkedList_##TYPE##_create()
#define LinkedList_free(LLIST) ({ LLIST->_functions->freeMembers(LLIST); free(LLIST); }) #define LinkedList_destruct(LLIST) ({ LLIST->_functions->freeMembers(LLIST); free(LLIST); })
void LinkedList_addToBeginning(void* _llist, void* _new_node); void LinkedList_addToBeginning(void* _llist, void* _new_node);

View File

@@ -12,7 +12,7 @@ STRUCT(LLNode(TYPE), \
) \ ) \
\ \
LLNode(TYPE)* LLNode_##TYPE##_create(TYPE value); \ LLNode(TYPE)* LLNode_##TYPE##_create(TYPE value); \
void LLNode_##TYPE##_free(LLNode(TYPE)* node, bool free_value); void LLNode_##TYPE##_destruct(LLNode(TYPE)* node, bool free_value);
#define LinkedList_declare(TYPE)\ #define LinkedList_declare(TYPE)\

View File

@@ -14,19 +14,19 @@ LLNode(TYPE)* LLNode_##TYPE##_create(TYPE value){ \
return node; \ return node; \
} \ } \
\ \
void LLNode_##TYPE##_freeMembers(void* _node){ \ void LLNode_##TYPE##_destructMembers(void* _node){ \
LLNode(TYPE)* node=(LLNode(TYPE)*)_node; \ LLNode(TYPE)* node=(LLNode(TYPE)*)_node; \
void* value_ptr=&node->value; \ void* value_ptr=&node->value; \
if(TYPE_IS_PTR) value_ptr=*(TYPE**)value_ptr; \ if(TYPE_IS_PTR) value_ptr=*(TYPE**)value_ptr; \
ktDescriptor_##TYPE.freeMembers(value_ptr); \ ktDescriptor_##TYPE.freeMembers(value_ptr); \
} \ } \
\ \
void LLNode_##TYPE##_free(LLNode(TYPE)* node, bool free_value){ \ void LLNode_##TYPE##_destruct(LLNode(TYPE)* node, bool free_value){ \
if(free_value) LLNode_##TYPE##_freeMembers(node); \ if(free_value) LLNode_##TYPE##_destructMembers(node); \
free(node); \ free(node); \
} \ } \
\ \
kt_define(LLNode_##TYPE, LLNode_##TYPE##_freeMembers, NULL) kt_define(LLNode_##TYPE, LLNode_##TYPE##_destructMembers, NULL)
#define LinkedList_define(TYPE, VALUE_IS_PTR)\ #define LinkedList_define(TYPE, VALUE_IS_PTR)\
@@ -41,10 +41,10 @@ LinkedList(TYPE)* LinkedList_##TYPE##_create(){ \
return l; \ return l; \
} \ } \
\ \
void LinkedList_##TYPE##_freeMembers(void* _l){ \ void LinkedList_##TYPE##_destructMembers(void* _l){ \
LinkedList(TYPE)* l=(LinkedList(TYPE)*)_l; \ LinkedList(TYPE)* l=(LinkedList(TYPE)*)_l; \
if(l->first_node!=NULL) \ if(l->first_node!=NULL) \
LinkedList_foreach(l, node, LLNode_##TYPE##_free(node, true)); \ LinkedList_foreach(l, node, LLNode_##TYPE##_destruct(node, true)); \
l->first_node=NULL; l->last_node=NULL; l->count=0; \ l->first_node=NULL; l->last_node=NULL; l->count=0; \
} \ } \
\ \
@@ -55,7 +55,7 @@ void LinkedList_##TYPE##_removePrev(LinkedList(TYPE)* llist, LLNode(TYPE)* nextN
nextNode->prev=prevNode; \ nextNode->prev=prevNode; \
prevNode->next=nextNode; \ prevNode->next=nextNode; \
if(freeRemoved) \ if(freeRemoved) \
LLNode_##TYPE##_free(removedNode, true); \ LLNode_##TYPE##_destruct(removedNode, true); \
} \ } \
\ \
void LinkedList_##TYPE##_removeNext(LinkedList(TYPE)* llist, LLNode(TYPE)* prevNode, bool freeRemoved){ \ void LinkedList_##TYPE##_removeNext(LinkedList(TYPE)* llist, LLNode(TYPE)* prevNode, bool freeRemoved){ \
@@ -65,16 +65,16 @@ void LinkedList_##TYPE##_removeNext(LinkedList(TYPE)* llist, LLNode(TYPE)* prevN
prevNode->next=nextNode; \ prevNode->next=nextNode; \
nextNode->prev=prevNode; \ nextNode->prev=prevNode; \
if(freeRemoved) \ if(freeRemoved) \
LLNode_##TYPE##_free(removedNode, true); \ LLNode_##TYPE##_destruct(removedNode, true); \
} \ } \
\ \
LinkedList_##TYPE##_functions_t _LinkedList_##TYPE##_functions={ \ LinkedList_##TYPE##_functions_t _LinkedList_##TYPE##_functions={ \
.freeMembers=LinkedList_##TYPE##_freeMembers, \ .freeMembers=LinkedList_##TYPE##_destructMembers, \
.removePrev=LinkedList_##TYPE##_removePrev, \ .removePrev=LinkedList_##TYPE##_removePrev, \
.removeNext=LinkedList_##TYPE##_removeNext \ .removeNext=LinkedList_##TYPE##_removeNext \
}; \ }; \
\ \
kt_define(LinkedList_##TYPE, LinkedList_##TYPE##_freeMembers, NULL) kt_define(LinkedList_##TYPE, LinkedList_##TYPE##_destructMembers, NULL)
#if __cplusplus #if __cplusplus

View File

@@ -1,6 +1,6 @@
#include "SearchTree.h" #include "SearchTree.h"
kt_define(STNode, __STNode_free, NULL); kt_define(STNode, __STNode_destruct, NULL);
STNode* STNode_create(){ STNode* STNode_create(){
STNode* node=malloc(sizeof(STNode)); STNode* node=malloc(sizeof(STNode));
@@ -9,20 +9,20 @@ STNode* STNode_create(){
return node; return node;
} }
void __STNode_free(void* _node){ void __STNode_destruct(void* _node){
STNode* node=_node; STNode* node=_node;
if (!node) throw(ERR_NULLPTR); if (!node) throw(ERR_NULLPTR);
if(node->branches){ if(node->branches){
for(u8 n32 = 0;n32<8;n32++){ for(u8 n32 = 0;n32<8;n32++){
STNode*** ptrn32=(STNode***)node->branches[n32]; STNode*** ptrn32=(STNode***)node->branches[n32];
if(ptrn32){ if(ptrn32){
for(u8 n4 = 0;n4<8;n4++){ for(u8 n4 = 0;n4<8;n4++){
STNode** ptrn4=ptrn32[n4]; STNode** ptrn4=ptrn32[n4];
if (ptrn4){ if (ptrn4){
for(u8 rem=0;rem<4;rem++){ for(u8 rem=0;rem<4;rem++){
STNode* ptrrem=ptrn4[rem]; STNode* ptrrem=ptrn4[rem];
if(ptrrem) if(ptrrem)
STNode_free(ptrrem); STNode_destruct(ptrrem);
} }
free(ptrn4); free(ptrn4);
} }
@@ -32,11 +32,11 @@ void __STNode_free(void* _node){
} }
free(node->branches); free(node->branches);
} }
if(node->value.VoidPtr) if(node->value.VoidPtr)
Unitype_free(node->value); Unitype_destruct(&node->value);
} }
void STNode_free(STNode* node){ void STNode_destruct(STNode* node){
__STNode_free(node); __STNode_destruct(node);
free(node); free(node);
} }

View File

@@ -13,8 +13,8 @@ STRUCT(STNode,
) )
STNode* STNode_create(); STNode* STNode_create();
void STNode_free(STNode* node); void STNode_destruct(STNode* node);
void __STNode_free(void* node); void __STNode_destruct(void* node);
void ST_push(STNode* node, char* key, Unitype value); void ST_push(STNode* node, char* key, Unitype value);
void ST_pushString(STNode* node, string key, Unitype value); void ST_pushString(STNode* node, string key, Unitype value);
@@ -23,4 +23,4 @@ Unitype ST_pullString(STNode* node, string key);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -22,4 +22,4 @@ STNode.branches byte
┗━[7]━┳━[0] 252 ┗━[7]━┳━[0] 252
┣━... ┣━...
┗━[3] 255 ┗━[3] 255
``` ```

View File

@@ -1,23 +1,23 @@
#include "StringBuilder.h" #include "StringBuilder.h"
kt_define(StringBuilder, __StringBuilder_free, NULL); kt_define(StringBuilder, __StringBuilder_destruct, NULL);
#define BL_C 32 #define BL_C 32
#define BL_L 1024 #define BL_L 1024
void complete_buf(StringBuilder* b){ void complete_buf(StringBuilder* b){
if(!b->compl_bufs) if(!b->compl_bufs)
b->compl_bufs=Autoarr_create(string,BL_C,BL_L); b->compl_bufs=Autoarr_create(string,BL_C,BL_L);
u32 len=Autoarr_length(b->curr_buf); u32 len=Autoarr_length(b->curr_buf);
if(!len) return; if(!len) return;
string str={.length=len, .ptr=malloc(len)}; string str={.length=len, .ptr=malloc(len)};
u32 i=0; u32 i=0;
Autoarr_foreach(b->curr_buf, c, Autoarr_foreach(b->curr_buf, c,
str.ptr[i++]=c; str.ptr[i++]=c;
); );
Autoarr_add(b->compl_bufs,str); Autoarr_add(b->compl_bufs,str);
Autoarr_free(b->curr_buf, true); Autoarr_destruct(b->curr_buf, true);
b->curr_buf=Autoarr_create(i8,BL_C,BL_L); b->curr_buf=Autoarr_create(i8,BL_C,BL_L);
} }
@@ -34,31 +34,31 @@ StringBuilder* StringBuilder_create(){
return b; return b;
} }
void __StringBuilder_free(void* _b){ void __StringBuilder_destruct(void* _b){
StringBuilder* b=_b; StringBuilder* b=_b;
if(b->compl_bufs) Autoarr_free(b->compl_bufs, true); if(b->compl_bufs) Autoarr_destruct(b->compl_bufs, true);
Autoarr_free(b->curr_buf, true); Autoarr_destruct(b->curr_buf, true);
} }
void StringBuilder_free(StringBuilder* b){ void StringBuilder_destruct(StringBuilder* b){
__StringBuilder_free(b); __StringBuilder_destruct(b);
free(b); free(b);
} }
string StringBuilder_build(StringBuilder* b){ string StringBuilder_build(StringBuilder* b){
complete_buf(b); complete_buf(b);
u32 len=0; u32 len=0;
Autoarr_foreach(b->compl_bufs, cs, Autoarr_foreach(b->compl_bufs, cs,
len+=cs.length; len+=cs.length;
); );
string str= { .length=len, .ptr=malloc(len+1) }; string str= { .length=len, .ptr=malloc(len+1) };
str.ptr[len]='\0'; str.ptr[len]='\0';
u32 i=0; u32 i=0;
Autoarr_foreach(b->compl_bufs, cs, Autoarr_foreach(b->compl_bufs, cs,
for(u32 n=0;n<cs.length;n++) for(u32 n=0;n<cs.length;n++)
str.ptr[i++]=cs.ptr[n]; str.ptr[i++]=cs.ptr[n];
free(cs.ptr); free(cs.ptr);
); );
StringBuilder_free(b); StringBuilder_destruct(b);
return str; return str;
} }
@@ -87,7 +87,7 @@ void StringBuilder_append_string(StringBuilder* b, string s){
void StringBuilder_append_cptr(StringBuilder* b, char* s){ void StringBuilder_append_cptr(StringBuilder* b, char* s){
string str={ string str={
.ptr=s, .ptr=s,
.length=cptr_length(s) .length=cptr_length(s)
}; };
StringBuilder_append_string(b,str); StringBuilder_append_string(b,str);
@@ -139,9 +139,6 @@ void StringBuilder_append_u64(StringBuilder* b, u64 a){
void StringBuilder_append_f64(StringBuilder* b, f64 a){ void StringBuilder_append_f64(StringBuilder* b, f64 a){
try_complete_buf(b); try_complete_buf(b);
char buf[32]; char buf[32];
IFMSC( sprintf_s(buf, sizeof(buf), "%lf", a);
sprintf_s(buf,32,"%lf",a),
sprintf(buf,"%lf",a)
);
curr_buf_add_string(b, (string){.ptr=buf, .length=cptr_length(buf)}); curr_buf_add_string(b, (string){.ptr=buf, .length=cptr_length(buf)});
} }

View File

@@ -13,8 +13,8 @@ STRUCT(StringBuilder,
) )
StringBuilder* StringBuilder_create(void); StringBuilder* StringBuilder_create(void);
void StringBuilder_free(StringBuilder* b); void StringBuilder_destruct(StringBuilder* b);
void __StringBuilder_free(void* b); void __StringBuilder_destruct(void* b);
// Joins all strings from compl_bufs. // Joins all strings from compl_bufs.
// Returns zero-terminated string. // Returns zero-terminated string.
// No need to call string_extract()! // No need to call string_extract()!
@@ -31,4 +31,4 @@ void StringBuilder_append_f64(StringBuilder* b, f64 a);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -1,8 +1,7 @@
#include "string.h" #include "string.h"
kt_define(string, NULL, NULL); kt_define(string, NULL, NULL);
Array_define(string) Autoarr_define(string, false);
Autoarr_define(string, false)
// copies str content to new char pointer value (adding '\0' at the end) // copies str content to new char pointer value (adding '\0' at the end)
char* string_extract(string str){ char* string_extract(string str){
@@ -33,7 +32,7 @@ bool string_compare(string str0, string str1){
if(!str0.ptr) return str1.ptr ? false : true; if(!str0.ptr) return str1.ptr ? false : true;
else if(!str1.ptr) return false; else if(!str1.ptr) return false;
while(str0.length-->0) while(str0.length-->0)
if(*str0.ptr++ != *str1.ptr++) if(*str0.ptr++ != *str1.ptr++)
return false; return false;
return true; return true;
} }

View File

@@ -5,7 +5,6 @@ extern "C" {
#endif #endif
#include "../base/base.h" #include "../base/base.h"
#include "../Array/Array.h"
#include "../Autoarr/Autoarr.h" #include "../Autoarr/Autoarr.h"
// my fixed length string struct // my fixed length string struct
@@ -15,7 +14,6 @@ STRUCT(string,
u64 length; // amount of chars in ptr value u64 length; // amount of chars in ptr value
) )
Array_declare(string)
Autoarr_declare(string) Autoarr_declare(string)
static const string stringNull={NULL,0}; static const string stringNull={NULL,0};
@@ -37,4 +35,4 @@ string string_reverse(string s);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -15,4 +15,4 @@ extern "C" {
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -11,16 +11,16 @@ u32 cptr_length(const char* str){
} }
// allocates new char[] and copies src there // allocates new char[] and copies src there
char* cptr_copy(const char* src){ char* cptr_copy(allocator_ptr al, const char* src){
u32 len=cptr_length(src)+1; u32 len=cptr_length(src)+1;
char* dst=malloc(len); char* dst=allocator_alloc(al, len);
memcpy(dst, src, len); memcpy(dst, src, len);
return dst; return dst;
} }
// multiplies char n times // multiplies char n times
char* char_multiply(char c, u32 n){ char* char_multiply(allocator_ptr al, char c, u32 n){
char* rez=malloc(n+1); char* rez=allocator_alloc(al, n+1);
rez[n]=0; rez[n]=0;
while(n--!=0) while(n--!=0)
rez[n]=c; rez[n]=c;
@@ -130,9 +130,9 @@ i32 cptr_seekCharReverse(const char* src, char fragment, u32 startIndex, u32 see
return -1; return -1;
} }
char* __cptr_concat(u32 n, ...){ char* __cptr_concat(allocator_ptr al, u32 n, ...){
char** strs=(char**)malloc(n*sizeof(char*)); char** strs=(char**)allocator_alloc(al, n*sizeof(char*));
u32* lengths=malloc(n*sizeof(u32)); u32* lengths=allocator_alloc(al, n*sizeof(u32));
u32 totalLength=0; u32 totalLength=0;
// reading args from va_list // reading args from va_list
@@ -148,7 +148,7 @@ char* __cptr_concat(u32 n, ...){
va_end(vl); va_end(vl);
// allocating memory for output value // allocating memory for output value
char* totality=malloc(totalLength+1); char* totality=allocator_alloc(al, totalLength+1);
char* output=totality; char* output=totality;
totality[totalLength]=0; totality[totalLength]=0;
@@ -163,26 +163,26 @@ char* __cptr_concat(u32 n, ...){
return output; return output;
} }
char* cptr_toLower(const char* src) { char* cptr_toLower(allocator_ptr al, const char* src) {
u32 length=cptr_length(src); u32 length=cptr_length(src);
char *p=malloc(length+1); char *p=allocator_alloc(al, length+1);
p[length]=0; p[length]=0;
for(u32 i=0; i<length; i++) for(u32 i=0; i<length; i++)
p[i]=tolower(src[i]); p[i]=tolower(src[i]);
return p; return p;
} }
char* cptr_toUpper(const char* src) { char* cptr_toUpper(allocator_ptr al, const char* src) {
u32 length=cptr_length(src); u32 length=cptr_length(src);
char *p=malloc(length+1); char *p=allocator_alloc(al, length+1);
p[length]=0; p[length]=0;
for(u32 i=0; i<length; i++) for(u32 i=0; i<length; i++)
p[i]=toupper(src[i]); p[i]=toupper(src[i]);
return p; return p;
} }
char* cptr_replaceCharIn(const char* src, char c_old, char c_new, u32 startIndex, u32 seekLength){ char* cptr_replaceCharIn(allocator_ptr al, const char* src, char c_old, char c_new, u32 startIndex, u32 seekLength){
char* rzlt=cptr_copy(src); char* rzlt=cptr_copy(al, src);
for(u32 i=startIndex; i!=seekLength && src[i]!=0; i++){ for(u32 i=startIndex; i!=seekLength && src[i]!=0; i++){
if(src[i]==c_old) if(src[i]==c_old)
rzlt[i]=c_new; rzlt[i]=c_new;
@@ -190,7 +190,7 @@ char* cptr_replaceCharIn(const char* src, char c_old, char c_new, u32 startIndex
return rzlt; return rzlt;
} }
char* cptr_replaceIn(const char* src, const char* str_old, const char* str_new, u32 startIndex, u32 seekLength){ char* cptr_replaceIn(allocator_ptr al, const char* src, const char* str_old, const char* str_new, u32 startIndex, u32 seekLength){
StringBuilder* sb=StringBuilder_create(); StringBuilder* sb=StringBuilder_create();
const u32 str_old_len=cptr_length(str_old); const u32 str_old_len=cptr_length(str_old);
const u32 str_new_len=cptr_length(str_new); const u32 str_new_len=cptr_length(str_new);

View File

@@ -5,12 +5,13 @@ extern "C" {
#endif #endif
#include "std.h" #include "std.h"
#include "memory/allocator_base.h"
// returns length of char buffer (without \0) // returns length of char buffer (without \0)
u32 cptr_length(const char* str); u32 cptr_length(const char* str);
// allocates new char[] and copies src there // allocates new char[] and copies src there
char* cptr_copy(const char* src); char* cptr_copy(allocator_ptr al, const char* src);
bool cptr_equals(const char* key0, const char* key1); bool cptr_equals(const char* key0, const char* key1);
@@ -19,9 +20,9 @@ bool cptr_startsWith(const char* src, const char* fragment);
bool cptr_endsWith(const char* src, const char* fragment); bool cptr_endsWith(const char* src, const char* fragment);
// multiplies char n times // multiplies char n times
char* char_multiply(char c, u32 n); char* char_multiply(allocator_ptr al, char c, u32 n);
/// @param startIndex 0 ... src length /// @param startIndex 0 ... src length
/// @param seekLength 0 ... -1 /// @param seekLength 0 ... -1
/// @return pos of first <fragment> inclusion in <src> or -1 if not found /// @return pos of first <fragment> inclusion in <src> or -1 if not found
i32 cptr_seek(const char* src, const char* fragment, u32 startIndex, u32 seekLength); i32 cptr_seek(const char* src, const char* fragment, u32 startIndex, u32 seekLength);
@@ -66,27 +67,27 @@ static inline bool cptr_contains(const char* src, const char* fragment){
return cptr_seek(src, fragment, 0, -1) +1; return cptr_seek(src, fragment, 0, -1) +1;
} }
char* __cptr_concat(u32 n, ...); char* __cptr_concat(allocator_ptr al, u32 n, ...);
#define cptr_concat(STR...) __cptr_concat(count_args(STR), STR) #define cptr_concat(ALLOCATOR, STR...) __cptr_concat(ALLOCATOR, count_args(STR), STR)
char* cptr_toLower(const char* src); char* cptr_toLower(allocator_ptr al, const char* src);
char* cptr_toUpper(const char* src); char* cptr_toUpper(allocator_ptr al, const char* src);
/// @param startIndex 0 ... src length /// @param startIndex 0 ... src length
/// @param seekLength 0 ... -1 /// @param seekLength 0 ... -1
/// @return <src> with <str_old> replaced by <str_new> or empty cstring if <str_old> not found /// @return <src> with <str_old> replaced by <str_new> or empty cstring if <str_old> not found
char* cptr_replaceIn(const char* src, const char* str_old, const char* str_new, u32 startIndex, u32 seekLength); char* cptr_replaceIn(allocator_ptr al, const char* src, const char* str_old, const char* str_new, u32 startIndex, u32 seekLength);
/// @param startIndex 0 ... src length /// @param startIndex 0 ... src length
/// @param seekLength 0 ... -1 /// @param seekLength 0 ... -1
/// @return <src> with <c_old> replaced by <c_new> or empty cstring if <str_old> not found /// @return <src> with <c_old> replaced by <c_new> or empty cstring if <str_old> not found
char* cptr_replaceCharIn(const char* src, char c_old, char c_new, u32 startIndex, u32 seekLength); char* cptr_replaceCharIn(allocator_ptr al, const char* src, char c_old, char c_new, u32 startIndex, u32 seekLength);
static inline char* cptr_replace(const char* src, const char* str_old, const char* str_new) static inline char* cptr_replace(allocator_ptr al, const char* src, const char* str_old, const char* str_new)
{ return cptr_replaceIn(src, str_old, str_new, 0, -1); } { return cptr_replaceIn(al, src, str_old, str_new, 0, -1); }
static inline char* cptr_replaceChar(const char* src, char c_old, char c_new) static inline char* cptr_replaceChar(allocator_ptr al, const char* src, char c_old, char c_new)
{ return cptr_replaceCharIn(src, c_old, c_new, 0, -1); } { return cptr_replaceCharIn(al, src, c_old, c_new, 0, -1); }
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -26,27 +26,21 @@ char* errname(ErrorId err){
char* __genErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname){ char* __genErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname){
size_t bufsize=ERRMSG_MAXLENGTH; size_t bufsize=ERRMSG_MAXLENGTH;
char* rezult=malloc(bufsize); char* rezult=malloc(bufsize);
IFMSC( sprintf_s(rezult,bufsize,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg);
sprintf_s(rezult,bufsize,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg),
sprintf(rezult,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg)
);
return rezult; return rezult;
} }
char* __extendErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname){ char* __extendErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname){
size_t bufsize=cptr_length(errmsg)+ERRMSG_MAXLENGTH; size_t bufsize=cptr_length(errmsg)+ERRMSG_MAXLENGTH;
char* rezult=malloc(bufsize); char* rezult=malloc(bufsize);
IFMSC( sprintf_s(rezult,bufsize,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname);
sprintf_s(rezult,bufsize,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname),
sprintf(rezult,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname)
);
free(errmsg); free(errmsg);
return rezult; return rezult;
} }
void Maybe_free(Maybe e){ void Maybe_destruct(Maybe e){
free(e.errmsg); free(e.errmsg);
Unitype_free(e.value); Unitype_destruct(&e.value);
} }
void printMaybe(Maybe e){ void printMaybe(Maybe e){

View File

@@ -29,7 +29,7 @@ STRUCT(Maybe,
// .value .errmsg // .value .errmsg
#define MaybeNull (Maybe){UniNull, NULL} #define MaybeNull (Maybe){UniNull, NULL}
void Maybe_free(Maybe e); void Maybe_destruct(Maybe e);
void printMaybe(Maybe e); void printMaybe(Maybe e);
@@ -87,4 +87,4 @@ char* __unknownErr( );
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -1,12 +1,12 @@
#include "allocators_internal.h" #include "allocators_internal.h"
void* CstdAllocator_alloc(allocator_t* self, size_t size){ void* CstdAllocator_alloc(allocator_ptr self, size_t size){
assert(size>0); // assert(size>0);
return malloc(size); return malloc(size);
} }
void CstdAllocator_free(allocator_t* self, void* ptr){ void CstdAllocator_free(allocator_ptr self, void* ptr){
assert(ptr!=NULL); // assert(ptr!=NULL);
free(ptr); free(ptr);
} }

View File

@@ -30,7 +30,7 @@ __attribute__ ((noinline)) void* __alloc_new_chunk(LinearAllocator* self, size_t
return curr_chunk->data; return curr_chunk->data;
} }
void* LinearAllocator_alloc(allocator_t* _self, size_t size){ void* LinearAllocator_alloc(allocator_ptr _self, size_t size){
// assert(_self!=NULL); // assert(_self!=NULL);
// assert(size>0); // assert(size>0);
LinearAllocator* self = (LinearAllocator*)_self; LinearAllocator* self = (LinearAllocator*)_self;
@@ -55,7 +55,7 @@ void* LinearAllocator_alloc(allocator_t* _self, size_t size){
} }
} }
void LinearAllocator_free(allocator_t* _self, void* ptr){ void LinearAllocator_free(allocator_ptr _self, void* ptr){
// LinearAllocator can't free pointers // LinearAllocator can't free pointers
} }

View File

@@ -8,7 +8,7 @@ typedef struct {
size_t data_size; size_t data_size;
} AllocationHeader; } AllocationHeader;
void* StackingAllocator_alloc(allocator_t* _self, size_t size){ void* StackingAllocator_alloc(allocator_ptr _self, size_t size){
assert(_self!=NULL); assert(_self!=NULL);
assert(size>0); assert(size>0);
StackingAllocator* self = (StackingAllocator*)_self; StackingAllocator* self = (StackingAllocator*)_self;
@@ -23,7 +23,7 @@ void* StackingAllocator_alloc(allocator_t* _self, size_t size){
return data_ptr; return data_ptr;
} }
void StackingAllocator_free(allocator_t* _self, void* data_ptr){ void StackingAllocator_free(allocator_ptr _self, void* data_ptr){
assert(_self!=NULL); assert(_self!=NULL);
assert(data_ptr!=NULL); assert(data_ptr!=NULL);
StackingAllocator* self = (StackingAllocator*)_self; StackingAllocator* self = (StackingAllocator*)_self;

View File

@@ -0,0 +1,34 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "../std.h"
///////////////////////////////////////////
// MemoryAllocator interface //
///////////////////////////////////////////
typedef struct MemoryAllocator* allocator_ptr;
typedef void* (*alloc_t)(allocator_ptr, size_t size);
typedef void (*free_t)(allocator_ptr, void* ptr);
typedef struct MemoryAllocator {
alloc_t alloc_f;
free_t free_f;
} MemoryAllocator;
#define allocator_alloc(ALLOCATOR, SIZE) \
((allocator_ptr)ALLOCATOR)->alloc_f(ALLOCATOR, SIZE)
#define allocator_free(ALLOCATOR, PTR) \
((allocator_ptr)ALLOCATOR)->free_f(ALLOCATOR, PTR)
#define allocator_destruct(ALLOCATOR) \
((allocator_ptr)ALLOCATOR)->destruct_f(ALLOCATOR)
void* allocator_transfer(allocator_ptr src, allocator_ptr dest, void* data, size_t data_size);
#ifdef __cplusplus
}
#endif

View File

@@ -1,6 +1,6 @@
#include "memory.h" #include "memory.h"
void* allocator_transfer(allocator_t* src, allocator_t* dest, void* data, size_t data_size) void* allocator_transfer(allocator_ptr src, allocator_ptr dest, void* data, size_t data_size)
{ {
void* transfered=allocator_alloc(dest, data_size); void* transfered=allocator_alloc(dest, data_size);
memcpy(transfered, data, data_size); memcpy(transfered, data, data_size);

View File

@@ -6,30 +6,7 @@ extern "C" {
#include "../std.h" #include "../std.h"
#include "../type_system/ktDescriptor.h" #include "../type_system/ktDescriptor.h"
#include "allocator_base.h"
///////////////////////////////////////////
// MemoryAllocator interface //
///////////////////////////////////////////
typedef struct MemoryAllocator allocator_t;
typedef void* (*alloc_t)(allocator_t*, size_t size);
typedef void (*free_t)(allocator_t*, void* ptr);
typedef struct MemoryAllocator {
alloc_t alloc_f;
free_t free_f;
} allocator_t;
#define allocator_alloc(ALLOCATOR, SIZE) \
((allocator_t*)ALLOCATOR)->alloc_f(ALLOCATOR, SIZE)
#define allocator_free(ALLOCATOR, PTR) \
((allocator_t*)ALLOCATOR)->free_f(ALLOCATOR, PTR)
#define allocator_destruct(ALLOCATOR) \
((allocator_t*)ALLOCATOR)->destruct_f(ALLOCATOR)
void* allocator_transfer(allocator_t* src, allocator_t* dest, void* data, size_t data_size);
/////////////////////////////////////////// ///////////////////////////////////////////
// CstdAllocator // // CstdAllocator //
@@ -38,7 +15,7 @@ void* allocator_transfer(allocator_t* src, allocator_t* dest, void* data, size_t
/////////////////////////////////////////// ///////////////////////////////////////////
STRUCT(CstdAllocator, STRUCT(CstdAllocator,
allocator_t base; MemoryAllocator base;
); );
void CstdAllocator_construct(CstdAllocator* self); void CstdAllocator_construct(CstdAllocator* self);
@@ -59,7 +36,7 @@ typedef struct MemoryChunk {
} MemoryChunk; } MemoryChunk;
STRUCT(LinearAllocator, STRUCT(LinearAllocator,
allocator_t base; MemoryAllocator base;
MemoryChunk* chunks; /* MemoryChunk[max_chunks_count] */ MemoryChunk* chunks; /* MemoryChunk[max_chunks_count] */
u16 chunks_count; /* allocated chunks */ u16 chunks_count; /* allocated chunks */
u16 max_chunks_count; /* chunks that can be allocated without reallocating .chunks */ u16 max_chunks_count; /* chunks that can be allocated without reallocating .chunks */

View File

@@ -1,4 +1,4 @@
#include <assert.h> #include <assert.h>
#include "memory.h" #include "memory.h"
void* LinearAllocator_alloc(allocator_t* _self, size_t size); void* LinearAllocator_alloc(allocator_ptr _self, size_t size);

View File

@@ -15,7 +15,7 @@
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%f \e[93m%s\n", \ kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%f \e[93m%s\n", \
opname, t, tnames[tni]); opname, t, tnames[tni]);
#ifdef CLOCK_REALTIME #ifdef CLOCK_REALTIME
/// executes codeblock and prints execution time /// executes codeblock and prints execution time
/// u64 op_i is counter of the internal loop /// u64 op_i is counter of the internal loop
/// uses non-standard high-precision clock /// uses non-standard high-precision clock
@@ -28,7 +28,7 @@
f64 t=(f64)(stop.tv_sec-start.tv_sec)*1000000+(f64)(stop.tv_nsec-start.tv_nsec)/1000; \ f64 t=(f64)(stop.tv_sec-start.tv_sec)*1000000+(f64)(stop.tv_nsec-start.tv_nsec)/1000; \
__optime_print(opname,t); \ __optime_print(opname,t); \
} }
#else #else
/// uses standard low precision clock /// uses standard low precision clock
#define optime(opname, repeats, codeblock...) { \ #define optime(opname, repeats, codeblock...) { \
clock_t start=clock(); \ clock_t start=clock(); \

View File

@@ -28,7 +28,7 @@ typedef double f64;
/// anonymous pointer without specified freeMembers() func /// anonymous pointer without specified freeMembers() func
typedef void* Pointer; typedef void* Pointer;
// Usually bool from stdbool.h is defined as macro, // Usually bool from stdbool.h is defined as macro,
// so in other macros like ktid_##TYPE it will be replaced by _Bool. // so in other macros like ktid_##TYPE it will be replaced by _Bool.
// ktid__Bool will be created instead of ktid_bool // ktid__Bool will be created instead of ktid_bool
// In C++ bool is a keyword, so there is no need to redefine it. // In C++ bool is a keyword, so there is no need to redefine it.
@@ -136,4 +136,4 @@ You can even embed it into macro in header (see kprint.h)
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -5,14 +5,14 @@
// accepts char* (ptr to char) and char* (ptr to string) // accepts char* (ptr to char) and char* (ptr to string)
// uses format kp_s and kp_c to determine what type is <c> argument // uses format kp_s and kp_c to determine what type is <c> argument
char* __toString_char(void* c, u32 fmt) { char* __toString_char(allocator_ptr al, void* c, u32 fmt) {
// *c=char* // *c=char*
if(kp_fmt_dataFormat(fmt)==kp_s){ if(kp_fmt_dataFormat(fmt)==kp_s){
return cptr_copy((char*)c); // to avoid segmentation fault on free() when *c allocalet on stack return cptr_copy(al, (char*)c); // to avoid segmentation fault on free() when *c allocalet on stack
} }
// *c=char // *c=char
if(kp_fmt_dataFormat(fmt)==kp_c){ if(kp_fmt_dataFormat(fmt)==kp_c){
char* cc=malloc(2); char* cc=allocator_alloc(al, 2);
cc[0]=*(char*)c; cc[0]=*(char*)c;
cc[1]=0; cc[1]=0;
return cc; return cc;
@@ -20,10 +20,10 @@ char* __toString_char(void* c, u32 fmt) {
else throw(ERR_FORMAT); else throw(ERR_FORMAT);
} }
char* __toString_bool(void* c, u32 fmt) { char* __toString_bool(allocator_ptr al, void* c, u32 fmt) {
static const char _strbool[4][6]={ "false", "true\0", "False", "True\0" }; static const char _strbool[4][6]={ "false", "true\0", "False", "True\0" };
u8 strind=*(bool*)c==1 + kp_fmt_isUpper(fmt)*2; u8 strind=*(bool*)c==1 + kp_fmt_isUpper(fmt)*2;
char* rez=malloc(6); char* rez=allocator_alloc(al, 6);
rez[0]=_strbool[strind][0]; rez[0]=_strbool[strind][0];
rez[1]=_strbool[strind][1]; rez[1]=_strbool[strind][1];
rez[2]=_strbool[strind][2]; rez[2]=_strbool[strind][2];
@@ -33,7 +33,7 @@ char* __toString_bool(void* c, u32 fmt) {
return rez; return rez;
} }
char* toString_i64(i64 n){ char* toString_i64(allocator_ptr al, i64 n){
i64 d=n<0 ? -1*n : n; i64 d=n<0 ? -1*n : n;
char str[32]; char str[32];
u8 i=sizeof(str); u8 i=sizeof(str);
@@ -46,10 +46,10 @@ char* toString_i64(i64 n){
} }
if(n<0) if(n<0)
str[--i]='-'; str[--i]='-';
return cptr_copy((char*)str+i); return cptr_copy(al, (char*)str+i);
} }
char* toString_u64(u64 n, bool withPostfix, bool uppercase){ char* toString_u64(allocator_ptr al, u64 n, bool withPostfix, bool uppercase){
char str[32]; char str[32];
u8 i=sizeof(str); u8 i=sizeof(str);
str[--i]=0; str[--i]=0;
@@ -61,33 +61,30 @@ char* toString_u64(u64 n, bool withPostfix, bool uppercase){
str[--i]='0' + n%10; str[--i]='0' + n%10;
n/=10; n/=10;
} }
return cptr_copy((char*)str+i); return cptr_copy(al, (char*)str+i);
} }
#define _toString_float_impl(bufsize, maxPrecision) { \ #define _toString_float_impl(al, bufsize, maxPrecision) { \
char str[bufsize]; \ char str[bufsize]; \
if(precision>maxPrecision) \ if(precision>maxPrecision) \
throw("too big precision"); \ throw("too big precision"); \
if(precision==0) \ if(precision==0) \
precision=toString_float_default_precision; \ precision=toString_float_default_precision; \
i32 cn=IFMSC( \ i32 cn=sprintf_s(str, bufsize, "%.*f", precision, n); \
sprintf_s(str, bufsize, "%.*f", precision, n), \
sprintf(str, "%.*f", precision, n) \
); \
/* remove trailing zeroes except .0*/ \ /* remove trailing zeroes except .0*/ \
while(str[cn-1]=='0' && str[cn-2]!='.') \ while(str[cn-1]=='0' && str[cn-2]!='.') \
cn--; \ cn--; \
if(withPostfix) \ if(withPostfix) \
str[cn++]= uppercase ? 'F' : 'f'; \ str[cn++]= uppercase ? 'F' : 'f'; \
str[cn]='\0'; \ str[cn]='\0'; \
return cptr_copy(str); \ return cptr_copy(al, str); \
} }
char* toString_f32(f32 n, u8 precision, bool withPostfix, bool uppercase) char* toString_f32(allocator_ptr al, f32 n, u8 precision, bool withPostfix, bool uppercase)
_toString_float_impl(48, toString_f32_max_precision) _toString_float_impl(al, 48, toString_f32_max_precision)
char* toString_f64(f64 n, u8 precision, bool withPostfix, bool uppercase) char* toString_f64(allocator_ptr al, f64 n, u8 precision, bool withPostfix, bool uppercase)
_toString_float_impl(512, toString_f64_max_precision) _toString_float_impl(al, 512, toString_f64_max_precision)
#define byte_to_bits(byte) { \ #define byte_to_bits(byte) { \
str[cn++]='0' + (u8)((byte>>7)&1); /* 8th bit */ \ str[cn++]='0' + (u8)((byte>>7)&1); /* 8th bit */ \
@@ -100,9 +97,9 @@ char* toString_f64(f64 n, u8 precision, bool withPostfix, bool uppercase)
str[cn++]='0' + (u8)((byte>>0)&1); /* 1th bit */ \ str[cn++]='0' + (u8)((byte>>0)&1); /* 1th bit */ \
} }
char* toString_bin(void* _bytes, u32 size, bool inverse, bool withPrefix){ char* toString_bin(allocator_ptr al, void* _bytes, u32 size, bool inverse, bool withPrefix){
char* bytes=_bytes; char* bytes=_bytes;
char* str=malloc(size*8 + (withPrefix?2:0) +1); char* str=allocator_alloc(al, size*8 + (withPrefix?2:0) +1);
u32 cn=0; // char number u32 cn=0; // char number
if(withPrefix){ if(withPrefix){
str[cn++]='0'; str[cn++]='0';
@@ -126,19 +123,19 @@ char _4bitsHex(u8 u, bool uppercase){
case 0: case 1: case 2: case 3: case 4: case 0: case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8: case 9: case 5: case 6: case 7: case 8: case 9:
return '0'+u; return '0'+u;
case 0xA: case 0xB: case 0xC: case 0xA: case 0xB: case 0xC:
case 0xD: case 0xE: case 0xF: case 0xD: case 0xE: case 0xF:
return (uppercase ? 'A' : 'a') + u -10; return (uppercase ? 'A' : 'a') + u -10;
default: default:
dbg(u); dbg(u);
throw("incorrect number"); throw("incorrect number");
return 219; return (char)219;
} }
} }
char* toString_hex(void* _bytes, u32 size, bool inverse, bool withPrefix, bool uppercase){ char* toString_hex(allocator_ptr al, void* _bytes, u32 size, bool inverse, bool withPrefix, bool uppercase){
char* bytes=_bytes; char* bytes=_bytes;
char* str=malloc(size*2 + (withPrefix?2:0) + 1); char* str=allocator_alloc(al, size*2 + (withPrefix?2:0) + 1);
u32 cn=0; // char number u32 cn=0; // char number
if(withPrefix){ if(withPrefix){
str[cn++]='0'; str[cn++]='0';
@@ -147,7 +144,7 @@ char* toString_hex(void* _bytes, u32 size, bool inverse, bool withPrefix, bool u
// left to right // left to right
if(inverse){ if(inverse){
// byte number // byte number
for(i32 bn=size-1; bn>=0; bn--){ for(i32 bn=size-1; bn>=0; bn--){
unsigned char byte=bytes[bn]; unsigned char byte=bytes[bn];
str[cn++]=_4bitsHex(byte/16, uppercase); str[cn++]=_4bitsHex(byte/16, uppercase);
str[cn++]=_4bitsHex(byte%16, uppercase); str[cn++]=_4bitsHex(byte%16, uppercase);
@@ -166,67 +163,58 @@ char* toString_hex(void* _bytes, u32 size, bool inverse, bool withPrefix, bool u
} }
#define __toString_i32_def(BITS) char* __toString_i##BITS(void* _n, u32 f){ \ #define __toString_i_def(BITS) char* __toString_i##BITS(allocator_ptr al, void* _n, u32 f){ \
switch(kp_fmt_dataFormat(f)){ \ switch(kp_fmt_dataFormat(f)){ \
case kp_i: ; \ case kp_i: ; \
i##BITS n=*(i##BITS*)_n; \ i##BITS n=*(i##BITS*)_n; \
return toString_i64(n); \ return toString_i64(al,n); \
case kp_b: \ case kp_b: \
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f)); \ return toString_bin(al, _n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f)); \
case kp_h: \ case kp_h: \
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f)); \ return toString_hex(al, _n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f)); \
default: \ default: \
kprintf("\n%u\n", kp_fmt_dataFormat(f)); \ kprintf("\n%u\n", kp_fmt_dataFormat(f)); \
throw(ERR_FORMAT); \ throw(ERR_FORMAT); \
return NULL; \ return NULL; \
} \ } \
} }
__toString_i32_def(8)
__toString_i32_def(16)
__toString_i32_def(32)
__toString_i32_def(64)
#define __toString_u_def(BITS) char* __toString_u##BITS(void* _n, u32 f){ \ __toString_i_def(8)
__toString_i_def(16)
__toString_i_def(32)
__toString_i_def(64)
#define __toString_u_def(BITS) char* __toString_u##BITS(allocator_ptr al, void* _n, u32 f){ \
switch(kp_fmt_dataFormat(f)){ \ switch(kp_fmt_dataFormat(f)){ \
case kp_u: ; \ case kp_u: ; \
u##BITS n=*(u##BITS*)_n; \ u##BITS n=*(u##BITS*)_n; \
return toString_u64(n, kp_fmt_withPostfix(f), kp_fmt_isUpper(f)); \ return toString_u64(al, n, kp_fmt_withPostfix(f), kp_fmt_isUpper(f)); \
case kp_b: \ case kp_b: \
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f)); \ return toString_bin(al, _n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f)); \
case kp_h: \ case kp_h: \
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f)); \ return toString_hex(al, _n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f)); \
default: \ default: \
kprintf("\n%u\n", kp_fmt_dataFormat(f)); \ kprintf("\n%u\n", kp_fmt_dataFormat(f)); \
throw(ERR_FORMAT); \ throw(ERR_FORMAT); \
return NULL; \ return NULL; \
} \ } \
} }
__toString_u_def(8) __toString_u_def(8)
__toString_u_def(16) __toString_u_def(16)
__toString_u_def(32) __toString_u_def(32)
// __toString_u_def(64) __toString_u_def(64)
char* __toString_u64(void* _n, u32 f){
switch(kp_fmt_dataFormat(f)){
case kp_u: ;
u64 n=*(u64*)_n;
return toString_u64(n, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));
case kp_b:
return toString_bin(_n, 64/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));
case kp_h:
return toString_hex(_n, 64/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f));
default:
kprintf("\n%u\n", kp_fmt_dataFormat(f)); throw(ERR_FORMAT); return NULL; }
}
#define __toString_float_def(BITS) char* __toString_f##BITS(void* _n, u32 f){ \
#define __toString_f_def(BITS) char* __toString_f##BITS(allocator_ptr al, void* _n, u32 f){ \
switch(kp_fmt_dataFormat(f)){ \ switch(kp_fmt_dataFormat(f)){ \
case kp_f: ; \ case kp_f: ; \
f##BITS n=*(f##BITS*)_n; \ f##BITS n=*(f##BITS*)_n; \
return toString_f64(n, toString_float_default_precision, kp_fmt_withPostfix(f), kp_fmt_isUpper(f)); \ return toString_f64(al, n, toString_float_default_precision, kp_fmt_withPostfix(f), kp_fmt_isUpper(f)); \
case kp_b: \ case kp_b: \
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f)); \ return toString_bin(al, _n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f)); \
case kp_h: \ case kp_h: \
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f)); \ return toString_hex(al, _n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f)); \
default: \ default: \
kprintf("\n%u\n", kp_fmt_dataFormat(f)); \ kprintf("\n%u\n", kp_fmt_dataFormat(f)); \
throw(ERR_FORMAT); \ throw(ERR_FORMAT); \
@@ -234,5 +222,5 @@ char* __toString_u64(void* _n, u32 f){
} \ } \
} }
__toString_float_def(32) __toString_f_def(32)
__toString_float_def(64) __toString_f_def(64)

View File

@@ -5,43 +5,44 @@ extern "C" {
#endif #endif
#include "../errors.h" #include "../errors.h"
#include "../memory/allocator_base.h"
// accepts char* (ptr to char) and char* (ptr to string) // accepts char* (ptr to char) and char* (ptr to string)
// uses format kp_s and kp_c to determine what type is <c> argument // uses format kp_s and kp_c to determine what type is <c> argument
char* __toString_char(void* c, u32 fmt); char* __toString_char(allocator_ptr al, void* c, u32 fmt);
// bool // bool
char* __toString_bool(void* c, u32 fmt); char* __toString_bool(allocator_ptr al, void* c, u32 fmt);
// signed int // signed int
char* toString_i64(i64 n); char* toString_i64(allocator_ptr al, i64 n);
char* __toString_i8(void* n, u32 fmt); char* __toString_i8(allocator_ptr al, void* n, u32 fmt);
char* __toString_i16(void* n, u32 fmt); char* __toString_i16(allocator_ptr al, void* n, u32 fmt);
char* __toString_i32(void* n, u32 fmt); char* __toString_i32(allocator_ptr al, void* n, u32 fmt);
char* __toString_i64(void* n, u32 fmt); char* __toString_i64(allocator_ptr al, void* n, u32 fmt);
// unsigned int // unsigned int
char* toString_u64(u64 n, bool withPostfix, bool uppercase); char* toString_u64(allocator_ptr al, u64 n, bool withPostfix, bool uppercase);
char* __toString_u8(void* n, u32 fmt); char* __toString_u8(allocator_ptr al, void* n, u32 fmt);
char* __toString_u16(void* n, u32 fmt); char* __toString_u16(allocator_ptr al, void* n, u32 fmt);
char* __toString_u32(void* n, u32 fmt); char* __toString_u32(allocator_ptr al, void* n, u32 fmt);
char* __toString_u64(void* n, u32 fmt); char* __toString_u64(allocator_ptr al, void* n, u32 fmt);
// float // float
#define toString_f32_max_precision 6 #define toString_f32_max_precision 6
#define toString_f64_max_precision 15 #define toString_f64_max_precision 15
#define toString_float_default_precision 6 #define toString_float_default_precision 6
char* toString_f32(f32 n, u8 precision, bool withPostfix, bool uppercase); // uses sprintf char* toString_f32(allocator_ptr al, f32 n, u8 precision, bool withPostfix, bool uppercase); // uses sprintf
char* toString_f64(f64 n, u8 precision, bool withPostfix, bool uppercase); // uses sprintf char* toString_f64(allocator_ptr al, f64 n, u8 precision, bool withPostfix, bool uppercase); // uses sprintf
char* __toString_f32(void* n, u32 fmt); char* __toString_f32(allocator_ptr al, void* n, u32 fmt);
char* __toString_f64(void* n, u32 fmt); char* __toString_f64(allocator_ptr al, void* n, u32 fmt);
///@param inverse set to true for little endian numbers (their bytes are in reverse order) ///@param inverse set to true for little endian numbers (their bytes are in reverse order)
char* toString_bin(void* bytes, u32 size, bool inverse, bool withPrefix); char* toString_bin(allocator_ptr al, void* bytes, u32 size, bool inverse, bool withPrefix);
///@param inverse set to true for little endian numbers (their bytes are in reverse order) ///@param inverse set to true for little endian numbers (their bytes are in reverse order)
char* toString_hex(void* bytes, u32 size, bool inverse, bool withPrefix, bool uppercase); char* toString_hex(allocator_ptr al, void* bytes, u32 size, bool inverse, bool withPrefix, bool uppercase);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -1,5 +1,4 @@
#include "../base.h" #include "../base.h"
#include "../../Array/Array.h"
#include "../../Autoarr/Autoarr.h" #include "../../Autoarr/Autoarr.h"
#include "../../SearchTree/SearchTree.h" #include "../../SearchTree/SearchTree.h"
#include "../../Hashtable/Hashtable.h" #include "../../Hashtable/Hashtable.h"
@@ -29,21 +28,6 @@ void kt_initKerepTypes(){
// ktDescriptor // ktDescriptor
kt_register(ktDescriptor); kt_register(ktDescriptor);
// base type arrays
kt_register(Array_char);
kt_register(Array_bool);
kt_register(Array_f32);
kt_register(Array_f64);
kt_register(Array_i8);
kt_register(Array_u8);
kt_register(Array_i16);
kt_register(Array_u16);
kt_register(Array_i32);
kt_register(Array_u32);
kt_register(Array_i64);
kt_register(Array_u64);
kt_register(Array_Pointer);
// base type autoarrs // base type autoarrs
kt_register(Autoarr_Pointer); kt_register(Autoarr_Pointer);
kt_register(Autoarr_char); kt_register(Autoarr_char);
@@ -61,7 +45,6 @@ void kt_initKerepTypes(){
// Unitype // Unitype
kt_register(Unitype); kt_register(Unitype);
kt_register(Array_Unitype);
kt_register(Autoarr_Unitype); kt_register(Autoarr_Unitype);
// STNode // STNode
@@ -76,12 +59,16 @@ void kt_initKerepTypes(){
// string // string
kt_register(string); kt_register(string);
kt_register(Array_string);
kt_register(Autoarr_string); kt_register(Autoarr_string);
// StringBuilder // StringBuilder
kt_register(StringBuilder); kt_register(StringBuilder);
//File // File
kt_register(FileHandle); kt_register(FileHandle);
// Allocators
kt_register(CstdAllocator);
kt_register(LinearAllocator);
kt_register(StackingAllocator);
} }

View File

@@ -9,4 +9,4 @@ void kt_initKerepTypes();
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -7,6 +7,7 @@ extern "C" {
#include "../std.h" #include "../std.h"
#include "ktid.h" #include "ktid.h"
#include "typedef_macros.h" #include "typedef_macros.h"
#include "../memory/allocator_base.h"
#define kt_declare(TYPE)\ #define kt_declare(TYPE)\
ktid_declare(TYPE);\ ktid_declare(TYPE);\
@@ -31,7 +32,7 @@ extern "C" {
}; };
typedef void (*freeMembers_t)(void*); typedef void (*freeMembers_t)(void*);
typedef char* (*toString_t)(void* obj, u32 fmt); typedef char* (*toString_t)(allocator_ptr al, void* obj, u32 fmt);
STRUCT(ktDescriptor, STRUCT(ktDescriptor,
char* name; char* name;
@@ -48,4 +49,4 @@ STRUCT(ktDescriptor,
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -17,33 +17,33 @@ kt_define(i64, NULL, __toString_i64);
kt_define(u64, NULL, __toString_u64); kt_define(u64, NULL, __toString_u64);
char* ktDescriptor_toString(ktDescriptor* d){ char* ktDescriptor_toString(allocator_ptr al, ktDescriptor* d){
const char* n="null"; const char* n="null";
char *s0 = toString_u64(d->id, 0,0); char *s0 = toString_u64(al, d->id, 0,0);
char *s1 = toString_u64(d->size, 0,0); char *s1 = toString_u64(al, d->size, 0,0);
char *s2 = d->toString ? toString_hex(d->toString, sizeof(void*), 0,1,0) : n; char *s2 = d->toString ? toString_hex(al, d->toString, sizeof(void*), 0,1,0) : n;
char *s3 = d->freeMembers ? toString_hex(d->freeMembers, sizeof(void*), 0,1,0) : n; char *s3 = d->freeMembers ? toString_hex(al, d->freeMembers, sizeof(void*), 0,1,0) : n;
char *rez=cptr_concat("ktDescriptor {" char *rez=cptr_concat(al, "ktDescriptor {"
" name:", d->name, " name:", d->name,
" id:",s0, " id:",s0,
" size:",s1, " size:",s1,
" toString:",s2, " toString:",s2,
" freeMembers:",s3, " freeMembers:",s3,
" }"); " }");
free(s0); if(s3!=n) allocator_free(al, s3);
free(s1); if(s2!=n) allocator_free(al, s2);
if(s2!=n) free(s2); allocator_free(al, s1);
if(s3!=n) free(s3); allocator_free(al, s0);
return rez; return rez;
} }
char* _ktDescriptor_toString(void* _d, u32 fmt) { return ktDescriptor_toString(_d); } char* _ktDescriptor_toString(allocator_ptr al, void* _d, u32 fmt) { return ktDescriptor_toString(al, _d); }
kt_define(ktDescriptor, NULL, _ktDescriptor_toString); kt_define(ktDescriptor, NULL, _ktDescriptor_toString);
typedef ktDescriptor* ktDescriptor_Ptr; typedef ktDescriptor* ktDescriptor_Ptr;
// type descriptors are stored here during initialization // type descriptors are stored here during initialization
Autoarr(Pointer)* __descriptorPointers=NULL; Autoarr(Pointer)* __descriptorPointers=NULL;
// here type descriptors are stored when initialization is complited // here type descriptors are stored when initialization is complited
ktDescriptor** typeDescriptors=NULL; ktDescriptor** typeDescriptors=NULL;
@@ -63,7 +63,7 @@ void kt_endInit(){
if(__descriptorPointers==NULL) if(__descriptorPointers==NULL)
throw(ERR_NULLPTR); throw(ERR_NULLPTR);
typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers); typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers);
Autoarr_free(__descriptorPointers,true); Autoarr_destruct(__descriptorPointers,true);
if(typeDescriptors==NULL) throw(ERR_NULLPTR); if(typeDescriptors==NULL) throw(ERR_NULLPTR);
kprintf("\e[92minitialized %u type descriptors\n", ktid_last); kprintf("\e[92minitialized %u type descriptors\n", ktid_last);
} }
@@ -81,6 +81,6 @@ ktDescriptor* ktDescriptor_get(ktid id){
return typeDescriptors[id]; return typeDescriptors[id];
} }
void kt_free(){ void kt_deinit(){
free(typeDescriptors); free(typeDescriptors);
} }

View File

@@ -23,10 +23,10 @@ void kt_endInit();
/// @param id id of registered type /// @param id id of registered type
ktDescriptor* ktDescriptor_get(ktid id); ktDescriptor* ktDescriptor_get(ktid id);
char* ktDescriptor_toString(ktDescriptor* d); char* ktDescriptor_toString(allocator_ptr al, ktDescriptor* d);
// call it to free heap-allocated ktDescriptors array // call it to free heap-allocated ktDescriptors array
void kt_free(); void kt_deinit();
kt_declare(Pointer); kt_declare(Pointer);
kt_declare(char); kt_declare(char);
@@ -46,4 +46,4 @@ kt_declare(ktDescriptor);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -25,4 +25,4 @@ static const ktid ktid_undefined=-1;
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -1,40 +1,36 @@
#include "../../kprint/kprint_format.h" #include "../../kprint/kprint_format.h"
#include "../base.h" #include "../base.h"
char *__Unitype_toString(void *_u, u32 fmt) char *__Unitype_toString(allocator_ptr al, void *_u, u32 fmt)
{ {
return Unitype_toString(*(Unitype *)_u, fmt); return Unitype_toString(al, *(Unitype *)_u, fmt);
} }
kt_define(Unitype, __UnitypePtr_free, __Unitype_toString); kt_define(Unitype, (freeMembers_t)Unitype_destruct, __Unitype_toString);
void Unitype_free(Unitype u) void Unitype_destruct(Unitype* u)
{ {
if (u.typeId == ktid_undefined) if (u->typeId == ktid_undefined)
{ {
if (u.VoidPtr != NULL) if (u->VoidPtr != NULL)
throw("unitype with undefined typeId has value"); throw("unitype with undefined typeId has value");
return; return;
} }
ktDescriptor *type = ktDescriptor_get(u.typeId); ktDescriptor *type = ktDescriptor_get(u->typeId);
if (type->freeMembers) if (type->freeMembers)
type->freeMembers(u.VoidPtr); type->freeMembers(u->VoidPtr);
if (u.allocatedInHeap) if (u->allocatedInHeap)
free(u.VoidPtr); free(u->VoidPtr);
}
void __UnitypePtr_free(void *u)
{
Unitype_free(*(Unitype *)u);
} }
char *Unitype_toString(Unitype u, u32 fmt) char *Unitype_toString(allocator_ptr al, Unitype u, u32 fmt)
{ {
if (u.typeId == ktid_undefined) if (u.typeId == ktid_undefined)
{ {
if (u.VoidPtr != NULL) if (u.VoidPtr != NULL)
throw("unitype with undefined typeId has value"); throw("unitype with undefined typeId has value");
return cptr_copy("{ERROR_TYPE}"); return cptr_copy(al, "{ERROR_TYPE}");
} }
if (fmt == 0) if (fmt == 0)
@@ -74,7 +70,7 @@ char *Unitype_toString(Unitype u, u32 fmt)
else if (u.typeId == ktid_name(Pointer)) else if (u.typeId == ktid_name(Pointer))
{ {
if (u.VoidPtr == NULL) if (u.VoidPtr == NULL)
return cptr_copy("{ UniNull }"); return cptr_copy(al, "{ UniNull }");
fmt = kp_h; fmt = kp_h;
} }
} }
@@ -82,19 +78,22 @@ char *Unitype_toString(Unitype u, u32 fmt)
ktDescriptor *type = ktDescriptor_get(u.typeId); ktDescriptor *type = ktDescriptor_get(u.typeId);
char *valuestr; char *valuestr;
if (type->toString) if (type->toString)
valuestr = type->toString(u.VoidPtr, fmt); valuestr = type->toString(al, u.VoidPtr, fmt);
else else
valuestr = "ERR_NO_TOSTRING_FUNC"; valuestr = "ERR_NO_TOSTRING_FUNC";
char *rezult = cptr_concat("{ type: ", type->name, ", allocated on heap: ", (u.allocatedInHeap ? "true" : "false"), char *rezult = cptr_concat(al, "{ type: ", type->name, ", allocated on heap: ", (u.allocatedInHeap ? "true" : "false"),
", value:", valuestr, " }"); ", value:", valuestr, " }");
if (type->toString) if (type->toString)
free(valuestr); allocator_free(al, valuestr);
return rezult; return rezult;
} }
void printuni(Unitype v) void printuni(Unitype v)
{ {
char *s = Unitype_toString(v, 0); LinearAllocator _al;
LinearAllocator_construct(&_al, 256);
allocator_ptr al=&_al.base;
char *s = Unitype_toString(al, v, 0);
fputs(s, stdout); fputs(s, stdout);
free(s); LinearAllocator_destruct(&_al);
} }

View File

@@ -17,7 +17,7 @@ STRUCT(Unitype,
char Bytes[8]; char Bytes[8];
}; };
ktid typeId; ktid typeId;
bool allocatedInHeap; // should Unitype_free call free() to VoidPtr* bool allocatedInHeap; // should Unitype_destruct call free() to VoidPtr*
) )
@@ -45,11 +45,10 @@ STRUCT(Unitype,
#define UniCheckTypePtr(UNI, TYPE) UniCheckTypeId(UNI, ktid_ptrName(TYPE)) #define UniCheckTypePtr(UNI, TYPE) UniCheckTypeId(UNI, ktid_ptrName(TYPE))
// frees VoidPtr value or does nothing if type isn't pointer // frees VoidPtr value or does nothing if type isn't pointer
void Unitype_free(Unitype u); void Unitype_destruct(Unitype* u);
void __UnitypePtr_free(void* u); char* Unitype_toString(allocator_ptr al, Unitype v, u32 fmt);
char* Unitype_toString(Unitype v, u32 fmt);
void printuni(Unitype v); void printuni(Unitype v);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -3,27 +3,27 @@
ktid __typeFromFormat(kp_fmt f){ ktid __typeFromFormat(kp_fmt f){
ktid typeId=kp_fmt_ktid(f); ktid typeId=kp_fmt_ktid(f);
if(typeId) if(typeId)
return typeId; return typeId;
switch(kp_fmt_dataFormat(f)){ switch(kp_fmt_dataFormat(f)){
case kp_i: case kp_i:
case kp_h: case kp_h:
case kp_b: case kp_b:
return ktid_name(i64); return ktid_name(i64);
case kp_u: case kp_u:
return ktid_name(u64); return ktid_name(u64);
case kp_f: case kp_f:
return ktid_name(f64); return ktid_name(f64);
case kp_c: case kp_c:
return ktid_name(char); return ktid_name(char);
case kp_s: case kp_s:
return ktid_ptrName(char); return ktid_ptrName(char);
default: default:
return ktid_undefined; return ktid_undefined;
} }
} }
Maybe __next_toString(kp_fmt f, void* object){ Maybe __next_toString(allocator_ptr al, kp_fmt f, void* object){
// detecting type // detecting type
ktid typeId=__typeFromFormat(f); ktid typeId=__typeFromFormat(f);
if(typeId==ktid_undefined) if(typeId==ktid_undefined)
@@ -35,7 +35,7 @@ Maybe __next_toString(kp_fmt f, void* object){
ktDescriptor* type=ktDescriptor_get(typeId); ktDescriptor* type=ktDescriptor_get(typeId);
if(!type->toString) if(!type->toString)
safethrow("type descriptor doesnt have toString() func",;); safethrow("type descriptor doesnt have toString() func",;);
return SUCCESS(UniHeapPtr(char, type->toString(object, f))); return SUCCESS(UniHeapPtr(char, type->toString(al, object, f)));
} }
Maybe check_argsN(u8 n){ Maybe check_argsN(u8 n){
@@ -44,14 +44,14 @@ Maybe check_argsN(u8 n){
return MaybeNull; return MaybeNull;
} }
Maybe __ksprint(u8 n, kp_fmt* formats, __kp_value_union* objects){ Maybe __ksprint(allocator_ptr al, u8 n, kp_fmt* formats, __kp_value_union* objects){
try(check_argsN(n), _,;); try(check_argsN(n), _,;);
n/=2; n/=2;
StringBuilder* strb=StringBuilder_create(); StringBuilder* strb=StringBuilder_create();
for(u8 i=0; i<n; i++){ for(u8 i=0; i<n; i++){
try(__next_toString(formats[i], &objects[i]),mStr,;); try(__next_toString(al, formats[i], &objects[i]),mStr,;);
StringBuilder_append_cptr(strb, mStr.value.VoidPtr); StringBuilder_append_cptr(strb, mStr.value.VoidPtr);
Unitype_free(mStr.value); allocator_free(al, mStr.value.VoidPtr);
} }
char* rezult=StringBuilder_build(strb).ptr; char* rezult=StringBuilder_build(strb).ptr;
return SUCCESS(UniHeapPtr(char, rezult)); return SUCCESS(UniHeapPtr(char, rezult));
@@ -60,36 +60,43 @@ Maybe __ksprint(u8 n, kp_fmt* formats, __kp_value_union* objects){
Maybe __kfprint(FILE* file, u8 n, kp_fmt* formats, __kp_value_union* objects){ Maybe __kfprint(FILE* file, u8 n, kp_fmt* formats, __kp_value_union* objects){
try(check_argsN(n), _,;); try(check_argsN(n), _,;);
n/=2; n/=2;
LinearAllocator _al;
LinearAllocator_construct(&_al, 256);
allocator_ptr al=&_al.base;
for(u8 i=0; i<n; i++){ for(u8 i=0; i<n; i++){
try(__next_toString(formats[i], &objects[i]),maybeStr,;); try(__next_toString(al, formats[i], &objects[i]),maybeStr, LinearAllocator_destruct(&_al));
if(fputs(maybeStr.value.VoidPtr, file)==EOF) if(fputs(maybeStr.value.VoidPtr, file)==EOF)
safethrow("can't write string to file", Unitype_free(maybeStr.value)); safethrow("can't write string to file", LinearAllocator_destruct(&_al));
Unitype_free(maybeStr.value);
} }
fflush(file); fflush(file);
LinearAllocator_destruct(&_al);
return MaybeNull; return MaybeNull;
} }
void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){ void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){
tryLast(check_argsN(n), _,;); tryLast(check_argsN(n), _,;);
n/=2; n/=2;
LinearAllocator _al;
LinearAllocator_construct(&_al, 256);
allocator_ptr al=&_al.base;
for(u8 i=0; i<n; i++){ for(u8 i=0; i<n; i++){
kp_fmt fmt=formats[i]; kp_fmt fmt=formats[i];
kprint_setColor(fmt); kprint_setColor(fmt);
tryLast(__next_toString(fmt, &objects[i]),maybeStr, kprint_setColor(kp_bgBlack|kp_fgGray)); tryLast(__next_toString(al, fmt, &objects[i]), maybeStr,
if(fputs(maybeStr.value.VoidPtr, stdout)==EOF) \ LinearAllocator_destruct(&_al);
kprint_setColor(kp_bgBlack|kp_fgGray););
if(fputs(maybeStr.value.VoidPtr, stdout)==EOF)
throw("can't write string to stdout"); throw("can't write string to stdout");
//, Unitype_free(maybeStr.value)
Unitype_free(maybeStr.value);
} }
fflush(stdout); fflush(stdout);
LinearAllocator_destruct(&_al);
} }
#if defined(_WIN32)|| defined(_WIN64) #if defined(_WIN32)|| defined(_WIN64)
#include <windows.h> #include <windows.h>
#define FOREGROUND_YELLOW FOREGROUND_GREEN | FOREGROUND_RED #define FOREGROUND_YELLOW FOREGROUND_GREEN | FOREGROUND_RED
DWORD kp_fgColor_toWin(kp_fgColor f){ DWORD kp_fgColor_toWin(kp_fgColor f){
//kprintf("fg: %x\n", f); //kprintf("fg: %x\n", f);
switch(f){ switch(f){
case kp_fgBlack: return 0; case kp_fgBlack: return 0;
@@ -112,7 +119,7 @@ DWORD kp_fgColor_toWin(kp_fgColor f){
} }
} }
DWORD kp_bgColor_toWin(kp_bgColor f){ DWORD kp_bgColor_toWin(kp_bgColor f){
//kprintf("bg: %x\n", f); //kprintf("bg: %x\n", f);
switch(f){ switch(f){
case kp_bgBlack: return 0; case kp_bgBlack: return 0;
@@ -199,12 +206,12 @@ static const char* _kp_colorNames[16]={
"white" "white"
}; };
char* kp_bgColor_toString(kp_bgColor c){ char* kp_bgColor_toString(allocator_ptr al, kp_bgColor c){
u32 color_index=(c&0x00f00000)>>20; u32 color_index=(c&0x00f00000)>>20;
if(color_index>15) throw(ERR_WRONGINDEX); if(color_index>15) throw(ERR_WRONGINDEX);
return _kp_colorNames[color_index]; return _kp_colorNames[color_index];
} }
char* kp_fgColor_toString(kp_fgColor c){ char* kp_fgColor_toString(allocator_ptr al, kp_fgColor c){
u32 color_index=(c&0x00f00000)>>24; u32 color_index=(c&0x00f00000)>>24;
if(color_index>15) throw(ERR_WRONGINDEX); if(color_index>15) throw(ERR_WRONGINDEX);
return _kp_colorNames[color_index]; return _kp_colorNames[color_index];

View File

@@ -9,7 +9,7 @@ extern "C" {
/* /*
This file looks like a mess, but all cotnent here just solves the problem of putting variadic arguments to array of formats and array of objects. This file looks like a mess, but all cotnent here just solves the problem of putting variadic arguments to array of formats and array of objects.
*/ */
@@ -18,11 +18,11 @@ typedef union {
u64 u64; u64 u64;
f64 f64; f64 f64;
void* ptr; void* ptr;
} __kp_value_union; } __kp_value_union;
static inline __kp_value_union __kpVU_f(f64 f) { return (__kp_value_union){ .f64=f }; } static inline __kp_value_union __kpVU_f(f64 f) { return (__kp_value_union){ .f64=f }; }
static inline __kp_value_union __kpVU_i(i64 f) { return (__kp_value_union){ .i64=f }; } static inline __kp_value_union __kpVU_i(i64 f) { return (__kp_value_union){ .i64=f }; }
#define __kpVU_selectType(V) _Generic(V, float: __kpVU_f, f64: __kpVU_f, default: __kpVU_i)(V) #define __kpVU_selectType(V) _Generic(V, float: __kpVU_f, f64: __kpVU_f, default: __kpVU_i)(V)
@@ -70,18 +70,18 @@ static inline __kp_value_union __kpVU_i(i64 f) { return (__kp_value_union){ .i64
__kp_argsToObjs32(ARGS)) __kp_argsToObjs32(ARGS))
Maybe __ksprint(u8 n, kp_fmt* formats, __kp_value_union* objects); Maybe __ksprint(allocator_ptr al, u8 n, kp_fmt* formats, __kp_value_union* objects);
/// @param ARGS kp_fmt, value, kp_fmt, value... /// @param ARGS kp_fmt, value, kp_fmt, value...
///@returns Maybe<char*> ///@returns Maybe<char*>
#define ksprint(ARGS...) WARNING_DISABLE( W_INT_CONVERSION, \ #define ksprint(ALLOCATOR, ARGS...) WARNING_DISABLE( W_INT_CONVERSION, \
__ksprint(count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes)) \ __ksprint(ALLOCATOR, count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes)) \
) )
/*-Wint-conversion warning was produced during value to __kp_value_union conversion*/ /*-Wint-conversion warning was produced during value to __kp_value_union conversion*/
Maybe __kfprint(FILE* fd, u8 n, kp_fmt* formats, __kp_value_union* objects); Maybe __kfprint(FILE* fd, u8 n, kp_fmt* formats, __kp_value_union* objects);
/// @param FD FILE* /// @param FD FILE*
/// @param ARGS kp_fmt, value, kp_fmt, value... /// @param ARGS kp_fmt, value, kp_fmt, value...
///@returns Maybe<void> ///@returns Maybe<void>
#define kfprint(FD, ARGS...) WARNING_DISABLE( W_INT_CONVERSION, \ #define kfprint(FD, ARGS...) WARNING_DISABLE( W_INT_CONVERSION, \
@@ -99,4 +99,4 @@ void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -4,10 +4,12 @@
extern "C" { extern "C" {
#endif #endif
#include "../base/memory/allocator_base.h"
// 10000000 00000000 00000000 00000000 // 10000000 00000000 00000000 00000000
// ^ ^^^^ // ^ ^^^^
// | color num // | color num
// fgColorSet flag // fgColorSet flag
PACKED_ENUM(kp_fgColor, PACKED_ENUM(kp_fgColor,
/// black foreground /// black foreground
kp_fgBlack = 0x80000000, kp_fgBlack = 0x80000000,
@@ -40,7 +42,7 @@ PACKED_ENUM(kp_fgColor,
/// cyan foreground /// cyan foreground
kp_fgCyan = 0x8e000000, kp_fgCyan = 0x8e000000,
/// white foreground /// white foreground
kp_fgWhite = 0x8f000000 kp_fgWhite = 0x8f000000
) )
// 01000000 00000000 00000000 00000000 // 01000000 00000000 00000000 00000000
@@ -81,9 +83,9 @@ PACKED_ENUM(kp_bgColor,
kp_bgWhite = 0x40f00000 kp_bgWhite = 0x40f00000
) )
char* kp_bgColor_toString(kp_bgColor c); char* kp_bgColor_toString(allocator_ptr al, kp_bgColor c);
char* kp_fgColor_toString(kp_fgColor c); char* kp_fgColor_toString(allocator_ptr al, kp_fgColor c);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -45,9 +45,9 @@ PACKED_ENUM(kp_dataFmt,
#define kp_fmt_dataFormat(FMT) (kp_dataFmt)(FMT&0x000f0000) #define kp_fmt_dataFormat(FMT) (kp_dataFmt)(FMT&0x000f0000)
#define kp_fmt_ktid(FMT) (ktid)(FMT&0x0000ffff) #define kp_fmt_ktid(FMT) (ktid)(FMT&0x0000ffff)
///@param f bgColor | fgColor ///@param f bgColor | fgColor
void kprint_setColor(kp_fmt f); void kprint_setColor(kp_fmt f);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -49,6 +49,9 @@ void kprintf(const char* format, ...){
va_list vl; va_list vl;
va_start(vl, format); va_start(vl, format);
u32 i=0; u32 i=0;
LinearAllocator _al;
LinearAllocator_construct(&_al, 256);
allocator_ptr al=(allocator_ptr)&_al;
for(char c=format[i++]; c!=0; c=format[i++]){ for(char c=format[i++]; c!=0; c=format[i++]){
// value format specifiers // value format specifiers
if(c=='%'){ if(c=='%'){
@@ -58,18 +61,18 @@ void kprintf(const char* format, ...){
format_escape_seq: format_escape_seq:
switch (c) { switch (c) {
case 'u': case 'u':
argstr=toString_u64( argstr=toString_u64(al,
l ? va_arg(vl, u64) : va_arg(vl, u32) l ? va_arg(vl, u64) : va_arg(vl, u32)
,0,0); ,0,0);
break; break;
case 'i': case 'd': case 'i': case 'd':
argstr=toString_i64( argstr=toString_i64(al,
l ? va_arg(vl, i64) : va_arg(vl, i32) l ? va_arg(vl, i64) : va_arg(vl, i32)
); );
break; break;
case 'f': case 'f':
// f32 is promoted to f64 when passed through '...' // f32 is promoted to f64 when passed through '...'
argstr=toString_f64(va_arg(vl, f64), toString_float_default_precision,0,0); argstr=toString_f64(al, va_arg(vl, f64), toString_float_default_precision,0,0);
break; break;
case 'l': case 'l':
l=true; l=true;
@@ -78,16 +81,16 @@ void kprintf(const char* format, ...){
break; break;
case 'p': ; case 'p': ;
void* phex=va_arg(vl, void*); void* phex=va_arg(vl, void*);
argstr=toString_hex(&phex,getEndian()==LittleEndian,sizeof(phex),1,0); argstr=toString_hex(al, &phex,getEndian()==LittleEndian,sizeof(phex),1,0);
break; break;
case 'x': ; case 'x': ;
if(l){ if(l){
u64 xhex=va_arg(vl, u64); u64 xhex=va_arg(vl, u64);
argstr=toString_hex(&xhex,getEndian()==LittleEndian,sizeof(xhex),0,1); argstr=toString_hex(al, &xhex,getEndian()==LittleEndian,sizeof(xhex),0,1);
} }
else { else {
u32 xhex=va_arg(vl, u32); u32 xhex=va_arg(vl, u32);
argstr=toString_hex(&xhex,getEndian()==LittleEndian,sizeof(xhex),0,1); argstr=toString_hex(al, &xhex,getEndian()==LittleEndian,sizeof(xhex),0,1);
} }
break; break;
case 's': ; case 's': ;
@@ -98,7 +101,7 @@ void kprintf(const char* format, ...){
fputs(cptr, stdout); fputs(cptr, stdout);
break; break;
case 'c': case 'c':
argstr=malloc(2); argstr=allocator_alloc(al, 2);
argstr[0]=(char)va_arg(vl,int); argstr[0]=(char)va_arg(vl,int);
argstr[1]=0; argstr[1]=0;
break; break;
@@ -111,10 +114,9 @@ void kprintf(const char* format, ...){
} }
if(argstr){ if(argstr){
fputs(argstr, stdout); fputs(argstr, stdout);
free(argstr);
} }
} }
// escape sequences // escape sequences
else if(c=='\e'){ else if(c=='\e'){
IFWIN( IFWIN(
/* WINDOWS */ /* WINDOWS */
@@ -143,7 +145,7 @@ void kprintf(const char* format, ...){
putc(c,stdout); putc(c,stdout);
); );
} }
// common characters // common characters
else { else {
putc(c,stdout); putc(c,stdout);
} }
@@ -152,4 +154,5 @@ void kprintf(const char* format, ...){
#endif #endif
} }
va_end(vl); va_end(vl);
LinearAllocator_destruct(&_al);
} }

View File

@@ -11,4 +11,4 @@ void kprintf(const char* format, ...);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@@ -1,24 +0,0 @@
# Xoshiro/Xoroshiro RNG algorithms
There are a bunch of versions of xoshiro/xoroshiro algorithms, which are created by [David Blackman and Sebastiano Vigna](https://prng.di.unimi.it/)
```
xoroshiro
├── 32bitValue
| ├── xoroshiro64star.c
| └── xoroshiro64starstar.c
└── 64bitValue
├── xoroshiro128plus.c
├── xoroshiro128plusplus.c
└── xoroshiro128starstar.c
xoshiro
├── 32bitValue
│ ├── xoshiro128plus.c
│ ├── xoshiro128plusplus.c
│ └── xoshiro128starstar.c
└── 64bitValue
├── xoshiro256plus.c
├── xoshiro256plusplus.c
└── xoshiro256starstar.c
```

View File

@@ -7,7 +7,7 @@ i32 main(){
kt_initKerepTypes(); kt_initKerepTypes();
kt_endInit(); kt_endInit();
test_all(); test_all();
kt_free(); kt_deinit();
kprintf("\e[0m\n"); kprintf("\e[0m\n");
return 0; return 0;
} }

View File

@@ -1,6 +1,6 @@
#include "tests.h" #include "tests.h"
void _test_allocator(allocator_t* al){ void _test_allocator(allocator_ptr al){
void* ptr=allocator_alloc(al, 1); void* ptr=allocator_alloc(al, 1);
allocator_free(al, ptr); allocator_free(al, ptr);
ptr=allocator_alloc(al, 5); ptr=allocator_alloc(al, 5);
@@ -30,18 +30,18 @@ void test_allocators(){
optime("test CstdAllocator", 10000, optime("test CstdAllocator", 10000,
CstdAllocator al; CstdAllocator al;
CstdAllocator_construct(&al); CstdAllocator_construct(&al);
_test_allocator((allocator_t*)&al); _test_allocator((allocator_ptr)&al);
); );
optime("test LinearAllocator", 10000, optime("test LinearAllocator", 10000,
LinearAllocator al; LinearAllocator al;
LinearAllocator_construct(&al, 4096); LinearAllocator_construct(&al, 4096);
_test_allocator((allocator_t*)&al); _test_allocator((allocator_ptr)&al);
LinearAllocator_destruct(&al); LinearAllocator_destruct(&al);
); );
optime("test StackingAllocator", 10000, optime("test StackingAllocator", 10000,
StackingAllocator al; StackingAllocator al;
StackingAllocator_construct(&al, 4096); StackingAllocator_construct(&al, 4096);
_test_allocator((allocator_t*)&al); _test_allocator((allocator_ptr)&al);
StackingAllocator_destruct(&al); StackingAllocator_destruct(&al);
); );
} }

View File

@@ -16,7 +16,7 @@ i64 _autoarrVsVector(u16 chunkCount, u16 chunkLength){
t=Autoarr_get(ar, op_i)); t=Autoarr_get(ar, op_i));
optime("vector_get", count, optime("vector_get", count,
t=vec[op_i]); t=vec[op_i]);
Autoarr_free(ar, true); Autoarr_destruct(ar, true);
return t; return t;
} }

View File

@@ -47,7 +47,7 @@ void test_autoarr(){
resetar(ar); resetar(ar);
kprintf("\e[92mautoarr values reset\n"); kprintf("\e[92mautoarr values reset\n");
printallval(ar); printallval(ar);
Autoarr_free(ar, true); Autoarr_destruct(ar, true);
kprintf("\e[92mautoarr deleted\n"); kprintf("\e[92mautoarr deleted\n");
); );
} }

View File

@@ -151,4 +151,4 @@ void test_cptr(){
// TODO cptr_replace // TODO cptr_replace
); );
} }

View File

@@ -52,7 +52,7 @@ void test_dtsod(){
tryLast(DtsodV24_serialize(dtsod),r,;) tryLast(DtsodV24_serialize(dtsod),r,;)
s=r.value.VoidPtr; s=r.value.VoidPtr;
); );
DtsodV24_free(dtsod); DtsodV24_destruct(dtsod);
kprintf("\e[92m%s",s); kprintf("\e[92m%s",s);
optime("reserialize",10, optime("reserialize",10,
@@ -61,9 +61,9 @@ void test_dtsod(){
free(s); free(s);
tryLast(DtsodV24_serialize(dtsod),rr,;) tryLast(DtsodV24_serialize(dtsod),rr,;)
s=rr.value.VoidPtr; s=rr.value.VoidPtr;
DtsodV24_free(dtsod); DtsodV24_destruct(dtsod);
); );
free(s); free(s);
); );
} }

View File

@@ -33,7 +33,7 @@ char data[]="iojihiojopijiugbjmoihftytryfdrh";
} \ } \
kprintf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS); \ kprintf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS); \
); \ ); \
Autoarr_free(hashes, true); \ Autoarr_destruct(hashes, true); \
kprintf("\e[96m--------------------------------------\n"); \ kprintf("\e[96m--------------------------------------\n"); \
} }
@@ -43,4 +43,4 @@ void test_hash_functions(){
test_hashfunc(u32, hash_crc32); test_hashfunc(u32, hash_crc32);
test_hashfunc(u32, hash_sdbm32); test_hashfunc(u32, hash_sdbm32);
); );
} }

View File

@@ -13,7 +13,7 @@ void print_hashtable(Hashtable* ht){
ht->rows); ht->rows);
} }
void printrowgraph(Hashtable* ht){ void printrowgraph(allocator_ptr al, Hashtable* ht){
kprintf("\e[94mrow length graph:\n"); kprintf("\e[94mrow length graph:\n");
u16 lgs_l=1000; u16 lgs_l=1000;
u32 lgs[lgs_l]; u32 lgs[lgs_l];
@@ -26,36 +26,33 @@ void printrowgraph(Hashtable* ht){
} }
for(u32 i=0; i<lgs_l; i++) for(u32 i=0; i<lgs_l; i++)
if(lgs[i]>0) { if(lgs[i]>0) {
char* str0=char_multiply(' ',i>=100?0:(i>=10?1:2)); char* str0=char_multiply(al, ' ',i>=100?0:(i>=10?1:2));
char* str1=char_multiply(' ',lgs[i]>=100?0:(lgs[i]>=10?1:2)); char* str1=char_multiply(al, ' ',lgs[i]>=100?0:(lgs[i]>=10?1:2));
char* str2=char_multiply('#',lgs[i]/100); char* str2=char_multiply(al, '#',lgs[i]/100);
kprintf("\e[94m length: \e[96m%u %s \e[94mfrequency: \e[96m%u %s \e[90m%s\n",i,str0,lgs[i],str1,str2); kprintf("\e[94m length: \e[96m%u %s \e[94mfrequency: \e[96m%u %s \e[90m%s\n",i,str0,lgs[i],str1,str2);
free(str0); allocator_free(al, str2);
free(str1); allocator_free(al, str1);
free(str2); allocator_free(al, str0);
} }
} }
char* genkey(u32 i){ char* genkey(allocator_ptr al, u32 i){
char* key=malloc(12); char* key=allocator_alloc(al, 16);
IFMSC( sprintf_s(key,16,"key_%u",i);
sprintf_s(key,12,"key_%u",i),
sprintf(key,"key_%u",i)
);
return key; return key;
} }
void fill(Hashtable* ht){ void fill(allocator_ptr al, Hashtable* ht){
for(u32 i=0;i<100000;i++) for(u32 i=0;i<100000;i++)
Hashtable_add(ht,genkey(i),UniUInt64(i)); Hashtable_add(ht,genkey(al, i), UniUInt64(i));
} }
Unitype gett(Hashtable* ht){ Unitype gett(allocator_ptr al, Hashtable* ht){
Unitype u; Unitype u;
for(u32 i=0;i<100000;i++){ for(u32 i=0;i<100000;i++){
char* key=genkey(i); char* key=genkey(al, i);
u=Hashtable_get(ht,key); u=Hashtable_get(ht,key);
free(key); allocator_free(al, key);
} }
return u; return u;
} }
@@ -64,14 +61,18 @@ Unitype gett(Hashtable* ht){
void test_hashtable(){ void test_hashtable(){
optime("test_hashtable",1, optime("test_hashtable",1,
kprintf("\e[96m-----------[test_hashtable]-----------\n"); kprintf("\e[96m-----------[test_hashtable]-----------\n");
StackingAllocator _al;
allocator_ptr al=(allocator_ptr)&_al;
StackingAllocator_construct(&_al, 4096);
Hashtable* ht=Hashtable_create(); Hashtable* ht=Hashtable_create();
kprintf("\e[92mhashtable created\n"); kprintf("\e[92mhashtable created\n");
print_hashtable(ht); print_hashtable(ht);
optime("fill",1,fill(ht)); optime("fill",1,fill(al, ht));
optime("get",1,gett(ht)); optime("get",1,gett(al, ht));
printrowgraph(ht); printrowgraph(al, ht);
print_hashtable(ht); print_hashtable(ht);
Hashtable_free(ht); Hashtable_destruct(ht);
kprintf("\e[92mhashtable freed\n"); kprintf("\e[92mhashtable freed\n");
StackingAllocator_destruct(&_al);
); );
} }

View File

@@ -1,9 +1,12 @@
#include "../src/Hashtable/KeyValuePair.h" #include "../src/Hashtable/KeyValuePair.h"
EXPORT void CALL test_marshalling(char* text, KVPair** kptr){ EXPORT void CALL test_marshalling(char* text, KVPair** kptr){
KVPair* k=malloc(sizeof(KVPair)); CstdAllocator _al;
allocator_ptr al=(allocator_ptr)&_al;
CstdAllocator_construct(&_al);
KVPair* k=allocator_alloc(al, sizeof(KVPair));
k->key="message"; k->key="message";
char* tc=cptr_copy(text); char* tc=cptr_copy(al, text);
Unitype u=UniHeapPtr(char,tc); Unitype u=UniHeapPtr(char,tc);
k->value=u; k->value=u;
*kptr=k; *kptr=k;

View File

@@ -1,45 +1,43 @@
#include "tests.h" #include "tests.h"
#include "../src/random/krandom.h" #include "../src/random/random.h"
#define test_alg(ALG, STATE_TYPE, EXPECTED_FROM_ZERO) { \
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO) { \
kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n"); \ kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n"); \
void* s= ALG##_init(0); \ STATE_TYPE##_state state; \
u##VALUE_SIZE r=ALG##_next(s); \ STATE_TYPE##_construct(&state, 0); \
u64 rn=ALG##_next(&state); \
kprintf("\e[97m next from zero seed:"); \ kprintf("\e[97m next from zero seed:"); \
if(r!=EXPECTED_FROM_ZERO){ \ if(rn != EXPECTED_FROM_ZERO){ \
kprintf("\e[91m " IFWIN("%llu\n","%lu\n"), (u64)r); \ kprintf("\e[91m %lu\n", rn); \
throw(ERR_UNEXPECTEDVAL); \ throw(ERR_UNEXPECTEDVAL); \
} \ } \
kprintf("\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r); \ kprintf("\e[92m %lu\n", rn); \
ALG##_free(s); \ STATE_TYPE##_construct(&state, random_seedFromTime()); \
s= ALG##_initFromTime(); \ rn=ALG##_next(&state); \
r=ALG##_next(s); \ kprintf("\e[97m next from time seed:\e[92m %lu\n", rn); \
ALG##_free(s); \
kprintf("\e[97m next from time seed:\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r); \
} }
void test_rng_algorithms(){ void test_rng_algorithms(){
optime("test_rng_algorithms",1, // optime("test_rng_algorithms",1,
kprintf("\e[96m--------[test_rng_algorithms]---------\n"); kprintf("\e[96m--------[test_rng_algorithms]---------\n");
// for ALG32 // splitmix64
// xoroshiro64 test_alg(splitmix64, splitmix64, 16294208416658607535ULL)
test_alg(xoroshiro64star, 32, 932574677ULL) // 32-bit
test_alg(xoroshiro64starstar, 32, 3183060286ULL) // xoroshiro64
// xoshiro128 test_alg(xoroshiro64star, xoroshiro64, 932574677ULL)
test_alg(xoshiro128plus, 32, 3918949401ULL) test_alg(xoroshiro64starstar, xoroshiro64, 3183060286ULL)
test_alg(xoshiro128plusplus, 32, 1179900579ULL) // xoshiro128
test_alg(xoshiro128starstar, 32, 3737715805ULL) test_alg(xoshiro128plus, xoshiro128, 3918949401ULL)
// for ALG64 test_alg(xoshiro128plusplus, xoshiro128, 1179900579ULL)
// xoroshiro128 test_alg(xoshiro128starstar, xoshiro128, 3737715805ULL)
test_alg(xoroshiro128plus, 64, 4778832803ULL) // 64-bit
test_alg(xoroshiro128plusplus, 64, 626373238705583ULL) // xoroshiro128
test_alg(xoroshiro128starstar, 64, 11897572417920ULL) test_alg(xoroshiro128plus, xoroshiro128, 4778832803ULL)
// xoshiro256 test_alg(xoroshiro128plusplus, xoroshiro128, 626373238705583ULL)
test_alg(xoshiro256plus, 64, 15757075719729598363ULL) test_alg(xoroshiro128starstar, xoroshiro128, 11897572417920ULL)
test_alg(xoshiro256plusplus, 64, 5987356902031041503ULL) // xoshiro256
test_alg(xoshiro256starstar, 64, 11091344671253066420ULL) test_alg(xoshiro256plus, xoshiro256, 15757075719729598363ULL)
// splitmix64 test_alg(xoshiro256plusplus, xoshiro256, 5987356902031041503ULL)
test_alg(splitmix64, 64, 16294208416658607535ULL) test_alg(xoshiro256starstar, xoshiro256, 11091344671253066420ULL)
); // );
} }

View File

@@ -34,10 +34,10 @@ void test_safethrow(){
Maybe e=test_maybe(); Maybe e=test_maybe();
kprintf("\e[94mthrow_error:\n\e[92m"); kprintf("\e[94mthrow_error:\n\e[92m");
printMaybe(e); printMaybe(e);
Maybe_free(e); Maybe_destruct(e);
kprintf("\e[94mthrow_errcode:\n\e[92m"); kprintf("\e[94mthrow_errcode:\n\e[92m");
e=a(); e=a();
printMaybe(e); printMaybe(e);
Maybe_free(e); Maybe_destruct(e);
); );
} }

View File

@@ -25,6 +25,9 @@ void printstnode(STNode* node){
void test_searchtree(){ void test_searchtree(){
optime("test_searchtree",1, optime("test_searchtree",1,
kprintf("\e[96m-----------[test_searchtree]----------\n"); kprintf("\e[96m-----------[test_searchtree]----------\n");
LinearAllocator _al;
LinearAllocator_construct(&_al, 1024);
allocator_ptr al=(allocator_ptr)&_al;
STNode* node=STNode_create(); STNode* node=STNode_create();
kprintf("\e[92mnode created\n"); kprintf("\e[92mnode created\n");
kprintf("push:\e[94m\n "); kprintf("push:\e[94m\n ");
@@ -44,7 +47,7 @@ void test_searchtree(){
printuni(u); printuni(u);
ST_push(node,"channel_id", u); ST_push(node,"channel_id", u);
kprintf(" -> channel_id\n "); kprintf(" -> channel_id\n ");
u=UniHeapPtr(char, cptr_copy("32.2004")); u=UniHeapPtr(char, cptr_copy(al, "32.2004"));
printuni(u); printuni(u);
ST_push(node,"message_id", u); ST_push(node,"message_id", u);
kprintf(" -> message_id\n "); kprintf(" -> message_id\n ");
@@ -68,7 +71,8 @@ void test_searchtree(){
kprintf("\n"); kprintf("\n");
kprintf("\e[92mfirst node: "); kprintf("\e[92mfirst node: ");
printstnode(node); printstnode(node);
STNode_free(node); STNode_destruct(node);
kprintf("\e[92mnode deleted\n"); kprintf("\e[92mnode deleted\n");
LinearAllocator_destruct(&_al);
); );
} }

View File

@@ -11,4 +11,4 @@ void test_string(){
kprintf("\e[94mstring_extract() -> \e[92m\"%s\"\n",p); kprintf("\e[94mstring_extract() -> \e[92m\"%s\"\n",p);
free(p); free(p);
); );
} }

View File

@@ -1,7 +1,7 @@
#include "tests.h" #include "tests.h"
void test_type_system(){ void test_type_system(){
for(ktid id=0; id<ktid_last; id++){ for(ktid id=0; id <= ktid_last; id++){
ktDescriptor* type=ktDescriptor_get(id); ktDescriptor* type=ktDescriptor_get(id);
kprintf("\e[37m{ id:%u name:%s size:%u freeMembers:%p toString:%p }\n", kprintf("\e[37m{ id:%u name:%s size:%u freeMembers:%p toString:%p }\n",
type->id, type->name, type->size, type->freeMembers, type->toString); type->id, type->name, type->size, type->freeMembers, type->toString);

View File

@@ -24,20 +24,20 @@ void test_type_system();
static inline void test_all(){ static inline void test_all(){
kprintf("\e[97mkerep tests are starting!\n"); kprintf("\e[97mkerep tests are starting!\n");
optime(__func__, 1, optime(__func__, 1,
// test_type_system();
test_allocators(); test_allocators();
/*test_cptr(); // test_kprint_colors();
test_string(); // test_kprint();
test_safethrow(); // test_safethrow();
test_searchtree(); // test_rng_algorithms();
test_autoarr(); // test_cptr();
test_hash_functions(); // test_string();
test_hashtable(); // test_searchtree();
test_dtsod(); // test_autoarr();
test_autoarrVsVector(); // test_autoarrVsVector();
test_rng_algorithms(); // test_hash_functions();
test_kprint_colors(); // test_hashtable();
test_kprint(); // test_dtsod();*/
test_type_system();*/
kprintf("\e[96m--------------------------------------\e[0m\n"); kprintf("\e[96m--------------------------------------\e[0m\n");
); );
} }