Compare commits
3 Commits
main
...
a983df1ac6
| Author | SHA1 | Date | |
|---|---|---|---|
| a983df1ac6 | |||
| 490d450a82 | |||
| 61da9ad161 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -6,10 +6,6 @@ obj/
|
|||||||
.old*/
|
.old*/
|
||||||
.vs/
|
.vs/
|
||||||
.vshistory/
|
.vshistory/
|
||||||
tmp/
|
|
||||||
temp/
|
|
||||||
*.tmp
|
|
||||||
*.temp
|
|
||||||
.editorconfig
|
.editorconfig
|
||||||
*.user
|
*.user
|
||||||
*.vcxproj.filters
|
*.vcxproj.filters
|
||||||
|
|||||||
4
.gitmodules
vendored
Normal file
4
.gitmodules
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[submodule "cbuild"]
|
||||||
|
path = cbuild
|
||||||
|
url = https://github.com/Timerix22/cbuild.git
|
||||||
|
branch = main
|
||||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
7
.idea/discord.xml
generated
7
.idea/discord.xml
generated
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="PROJECT_FILES" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
102
.idea/editor.xml
generated
102
.idea/editor.xml
generated
@@ -1,102 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="BackendCodeEditorSettings">
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
|
|
||||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
25
.idea/inspectionProfiles/Project_Default.xml
generated
25
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,6 +1,29 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="CodeBlock2Expr" enabled="true" level="TEXT ATTRIBUTES" enabled_by_default="true" editorAttributes="CONSIDERATION_ATTRIBUTES" />
|
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="clangTidyCheckOptions">
|
||||||
|
<list>
|
||||||
|
<ClangTidyCheckOption />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-not-null-terminated-result,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memory-comparison,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,modernize-avoid-bind,modernize-concat-nested-namespaces,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nodiscard,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-uncaught-exceptions,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="ClangdErrorsAndWarnings" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="EmptyDeclOrStmt" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="GrazieInspection" enabled="false" level="TYPO" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="Misra" enabled="false" level="WARNING" enabled_by_default="false">
|
||||||
|
<option name="myMisraCPPChecks" value="clion-misra-cpp2008-*,-clion-misra-cpp2008-11-0-1" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="OCUnusedGlobalDeclaration" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="ShellCheck" enabled="false" level="ERROR" enabled_by_default="false">
|
||||||
|
<shellcheck_settings value="SC2034,SC2035,SC2059,SC2061,SC2091,SC2155" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||||
|
<option name="processCode" value="true" />
|
||||||
|
<option name="processLiterals" value="true" />
|
||||||
|
<option name="processComments" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
||||||
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@@ -2,6 +2,5 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/cbuild" vcs="Git" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@@ -11,7 +11,19 @@
|
|||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"externalConsole": false,
|
"externalConsole": false,
|
||||||
"MIMode": "gdb",
|
"MIMode": "gdb",
|
||||||
"miDebuggerPath": "gdb"
|
"miDebuggerPath": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Set Disassembly Flavor to Intel",
|
||||||
|
"text": "-gdb-set disassembly-flavor intel",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "(gdb-pipe) Debug",
|
"name": "(gdb-pipe) Debug",
|
||||||
|
|||||||
85
Makefile
Normal file
85
Makefile
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
######################################
|
||||||
|
###### Build tasks #######
|
||||||
|
######################################
|
||||||
|
|
||||||
|
all: build_exec_dbg
|
||||||
|
|
||||||
|
# creates executable using profiling info generated by profile
|
||||||
|
build_exec: profile
|
||||||
|
@cbuild/call_task.sh build_exec 2>&1 | tee -a make_raw.log
|
||||||
|
|
||||||
|
# creates executable with debug info and no optimizations
|
||||||
|
build_exec_dbg:
|
||||||
|
@cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# creates shared library
|
||||||
|
build_shared_lib:
|
||||||
|
@cbuild/call_task.sh build_shared_lib 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# creates shared library with debug symbols and no optimizations
|
||||||
|
build_shared_lib_dbg:
|
||||||
|
@cbuild/call_task.sh build_shared_lib_dbg 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# creates static library
|
||||||
|
build_static_lib:
|
||||||
|
@cbuild/call_task.sh build_static_lib 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# creates static library with debug symbols and no optimizations
|
||||||
|
build_static_lib_dbg:
|
||||||
|
@cbuild/call_task.sh build_static_lib_dbg 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
######################################
|
||||||
|
###### Launch tasks #######
|
||||||
|
######################################
|
||||||
|
|
||||||
|
# executes $EXEC_FILE
|
||||||
|
exec: build_exec
|
||||||
|
@cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log
|
||||||
|
|
||||||
|
# executes $EXEC_FILE
|
||||||
|
exec_dbg: build_exec_dbg
|
||||||
|
@cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log
|
||||||
|
|
||||||
|
# executes $EXEC_FILE with valgrind memory checker
|
||||||
|
valgrind: build_exec_dbg
|
||||||
|
@cbuild/call_task.sh valgrind 2>&1 | tee -a make_raw.log
|
||||||
|
|
||||||
|
# generates profiling info
|
||||||
|
profile:
|
||||||
|
@cbuild/call_task.sh profile 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# compiles program with -pg and runs it with gprof
|
||||||
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
||||||
|
# requires graphviz (https://www.graphviz.org/download/source/)
|
||||||
|
gprof:
|
||||||
|
@cbuild/call_task.sh gprof 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# compiles program and runs it with callgrind (part of valgrind)
|
||||||
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
||||||
|
# requires graphviz (https://www.graphviz.org/download/source/)
|
||||||
|
# P.S. detailed rezults can be viewed in KCacheGrind
|
||||||
|
callgrind:
|
||||||
|
@cbuild/call_task.sh callgrind 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# compiles executable with sanitizers and executes it to find errors and warnings
|
||||||
|
sanitize:
|
||||||
|
@cbuild/call_task.sh sanitize 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
######################################
|
||||||
|
###### Other tasks #######
|
||||||
|
######################################
|
||||||
|
|
||||||
|
# deletes generated files
|
||||||
|
clean:
|
||||||
|
@cbuild/call_task.sh clean 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# removes all unreadable characters copied from stdio
|
||||||
|
fix_log:
|
||||||
|
sed 's/[^[:blank:][:print:]]//g' make_raw.log \
|
||||||
|
| sed 's/\[0;[0-9][0-9]m//g' \
|
||||||
|
| sed 's/\[0;[0-9]m//g' \
|
||||||
|
| sed 's/\[[0-9][0-9]m//g' \
|
||||||
|
| sed 's/\[[0-9]m//g' \
|
||||||
|
| sed 's/ H //g' \
|
||||||
|
| sed 's/\[3gH //g' \
|
||||||
|
> make_fixed.log
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# kerep
|
# kerep
|
||||||
My library written in C.
|
|
||||||
Requires [cbuild](https://timerix.ddns.net:3322/Timerix/cbuild).
|
My library written in C
|
||||||
|
|||||||
1
cbuild
Submodule
1
cbuild
Submodule
Submodule cbuild added at ef6a3f82c4
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
CBUILD_VERSION=2.1.1
|
CBUILD_VERSION=7
|
||||||
CONFIG_VERSION=9
|
CONFIG_VERSION=7
|
||||||
|
|
||||||
PROJECT="kerep"
|
PROJECT="kerep"
|
||||||
CMP_C="gcc"
|
CMP_C="gcc"
|
||||||
@@ -37,12 +37,10 @@ case "$OS" in
|
|||||||
WINDOWS)
|
WINDOWS)
|
||||||
EXEC_FILE="$PROJECT.exe"
|
EXEC_FILE="$PROJECT.exe"
|
||||||
SHARED_LIB_FILE="$PROJECT.dll"
|
SHARED_LIB_FILE="$PROJECT.dll"
|
||||||
LINKER_LIBS="-lpthread -lws2_32"
|
|
||||||
;;
|
;;
|
||||||
LINUX)
|
LINUX)
|
||||||
EXEC_FILE="$PROJECT"
|
EXEC_FILE="$PROJECT"
|
||||||
SHARED_LIB_FILE="$PROJECT.so"
|
SHARED_LIB_FILE="$PROJECT.so"
|
||||||
LINKER_LIBS=""
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "operating system $OS has no configuration variants"
|
error "operating system $OS has no configuration variants"
|
||||||
@@ -61,29 +59,25 @@ case "$TASK" in
|
|||||||
# -fdata-sections -ffunction-sections -Wl,--gc-sections removes unused code
|
# -fdata-sections -ffunction-sections -Wl,--gc-sections removes unused code
|
||||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections"
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
SRC_C+=" $TESTS_C"
|
|
||||||
SRC_CPP+=" $TESTS_CPP"
|
|
||||||
;;
|
;;
|
||||||
# creates executable with debug info and no optimizations
|
# creates executable with debug info and no optimizations
|
||||||
build_exec_dbg)
|
build_exec_dbg)
|
||||||
C_ARGS="-O0 -g3"
|
C_ARGS="-O0 -g3"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
SRC_C+=" $TESTS_C"
|
|
||||||
SRC_CPP+=" $TESTS_CPP"
|
|
||||||
;;
|
;;
|
||||||
# creates shared library
|
# creates shared library
|
||||||
build_shared_lib)
|
build_shared_lib)
|
||||||
C_ARGS="-O2 -fpic -flto -shared"
|
C_ARGS="-O2 -fpic -flto -shared"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE"
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
@@ -92,7 +86,7 @@ case "$TASK" in
|
|||||||
build_shared_lib_dbg)
|
build_shared_lib_dbg)
|
||||||
C_ARGS="-O0 -g3 -fpic -shared"
|
C_ARGS="-O0 -g3 -fpic -shared"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE"
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
@@ -119,7 +113,7 @@ case "$TASK" in
|
|||||||
;;
|
;;
|
||||||
# executes $EXEC_FILE with valgrind memory checker
|
# executes $EXEC_FILE with valgrind memory checker
|
||||||
valgrind)
|
valgrind)
|
||||||
VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$(pwd) --leak-check=full --show-leak-kinds=all"
|
VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/valgrind.sh
|
TASK_SCRIPT=cbuild/default_tasks/valgrind.sh
|
||||||
;;
|
;;
|
||||||
# generates profiling info
|
# generates profiling info
|
||||||
@@ -133,12 +127,10 @@ case "$TASK" in
|
|||||||
# -fprofile-prefix-path sets path where profiling info about objects will be saved
|
# -fprofile-prefix-path sets path where profiling info about objects will be saved
|
||||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
TASK_SCRIPT=cbuild/default_tasks/profile.sh
|
TASK_SCRIPT=cbuild/default_tasks/profile.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
SRC_C+=" $TESTS_C"
|
|
||||||
SRC_CPP+=" $TESTS_CPP"
|
|
||||||
;;
|
;;
|
||||||
# compiles program with -pg and runs it with gprof
|
# compiles program with -pg and runs it with gprof
|
||||||
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
||||||
@@ -148,47 +140,41 @@ case "$TASK" in
|
|||||||
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
||||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -pg"
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -pg"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
TASK_SCRIPT=cbuild/default_tasks/gprof.sh
|
TASK_SCRIPT=cbuild/default_tasks/gprof.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
SRC_C+=" $TESTS_C"
|
|
||||||
SRC_CPP+=" $TESTS_CPP"
|
|
||||||
;;
|
;;
|
||||||
# compiles program and runs it with callgrind (part of valgrind)
|
# compiles program and runs it with callgrind (part of valgrind)
|
||||||
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
||||||
# requires graphviz (https://www.graphviz.org/download/source/)
|
# requires graphviz (https://www.graphviz.org/download/source/)
|
||||||
# P.S. detailed results can be viewed in KCacheGrind
|
# P.S. detailed rezults can be viewed in KCacheGrind
|
||||||
callgrind)
|
callgrind)
|
||||||
OUTDIR="$OUTDIR/callgrind"
|
OUTDIR="$OUTDIR/callgrind"
|
||||||
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
||||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin"
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
PRE_TASK_SCRIPT=tasks/pre_build.sh
|
PRE_TASK_SCRIPT=tasks/pre_build.sh
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
POST_TASK_SCRIPT=cbuild/default_tasks/callgrind.sh
|
POST_TASK_SCRIPT=cbuild/default_tasks/callgrind.sh
|
||||||
SRC_C+=" $TESTS_C"
|
|
||||||
SRC_CPP+=" $TESTS_CPP"
|
|
||||||
;;
|
;;
|
||||||
# compiles executable with sanitizers and executes it to find errors and warnings
|
# compiles executable with sanitizers and executes it to find errors and warnings
|
||||||
sanitize)
|
sanitize)
|
||||||
OUTDIR="$OUTDIR/sanitize"
|
OUTDIR="$OUTDIR/sanitize"
|
||||||
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
SRC_C+=" $TESTS_C"
|
|
||||||
SRC_CPP+=" $TESTS_CPP"
|
|
||||||
;;
|
;;
|
||||||
# deletes generated files
|
# deletes generated files
|
||||||
clean)
|
clean)
|
||||||
TASK_SCRIPT=cbuild/default_tasks/clean.sh
|
TASK_SCRIPT=cbuild/default_tasks/clean.sh
|
||||||
;;
|
;;
|
||||||
# nothing to do
|
# nothing to do
|
||||||
"" | no_task)
|
no_task)
|
||||||
;;
|
;;
|
||||||
# unknown task
|
# unknown task
|
||||||
*)
|
*)
|
||||||
@@ -24,15 +24,15 @@ Autoarr_declare(u64)
|
|||||||
Autoarr_declare(Unitype)
|
Autoarr_declare(Unitype)
|
||||||
|
|
||||||
#define Autoarr_foreach(ar, elem, codeblock...) { \
|
#define Autoarr_foreach(ar, elem, codeblock...) { \
|
||||||
if(ar->blocks_count>0) { \
|
if(ar->chunks_count>0) { \
|
||||||
typeof(**ar->values) elem; \
|
typeof(**ar->chunks) elem; \
|
||||||
for(u16 blockI=0;blockI<ar->blocks_count-1;blockI++) \
|
for(u16 chunkI=0;chunkI<ar->chunks_count-1;chunkI++) \
|
||||||
for(u32 elemI=0;elemI<ar->max_block_length;elemI++){ \
|
for(u32 elemI=0;elemI<ar->max_chunk_length;elemI++){ \
|
||||||
elem=ar->values[blockI][elemI]; \
|
elem=ar->chunks[chunkI][elemI]; \
|
||||||
{ codeblock; } \
|
{ codeblock; } \
|
||||||
} \
|
} \
|
||||||
for(u16 elemI=0;elemI<ar->block_length;elemI++){ \
|
for(u16 elemI=0;elemI<ar->chunk_length;elemI++){ \
|
||||||
elem=ar->values[ar->blocks_count-1][elemI]; \
|
elem=ar->chunks[ar->chunks_count-1][elemI]; \
|
||||||
{ codeblock; } \
|
{ codeblock; } \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ extern "C" {
|
|||||||
#include "Autoarr.h"
|
#include "Autoarr.h"
|
||||||
#include "../Hashtable/KeyValuePair.h"
|
#include "../Hashtable/KeyValuePair.h"
|
||||||
|
|
||||||
EXPORT void CALL kerep_Autoarr_KVPair_create(u16 max_blocks_count, u16 max_block_length, Autoarr_KVPair** output){
|
EXPORT void CALL kerep_Autoarr_KVPair_create(u16 max_chunks_count, u16 max_chunk_length, Autoarr_KVPair** output){
|
||||||
*output=Autoarr_create(KVPair, max_blocks_count, max_block_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_free(Autoarr_KVPair* ar){
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ extern "C" {
|
|||||||
|
|
||||||
#include "Autoarr.h"
|
#include "Autoarr.h"
|
||||||
|
|
||||||
EXPORT void CALL kerep_Autoarr_Unitype_create(u16 max_blocks_count, u16 max_block_length, Autoarr_Unitype** output){
|
EXPORT void CALL kerep_Autoarr_Unitype_create(u16 max_chunks_count, u16 max_chunk_length, Autoarr_Unitype** output){
|
||||||
*output=Autoarr_create(Unitype, max_blocks_count, max_block_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_free(Autoarr_Unitype* ar){
|
||||||
|
|||||||
@@ -23,22 +23,22 @@ typedef struct __Autoarr_##type##_functions_list_t { \
|
|||||||
extern __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list; \
|
extern __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list; \
|
||||||
\
|
\
|
||||||
STRUCT(Autoarr_##type, \
|
STRUCT(Autoarr_##type, \
|
||||||
u16 blocks_count; \
|
u16 chunks_count; \
|
||||||
u16 max_blocks_count; \
|
u16 max_chunks_count; \
|
||||||
u16 block_length; \
|
u16 chunk_length; \
|
||||||
u16 max_block_length; \
|
u16 max_chunk_length; \
|
||||||
type** values; \
|
type** chunks; \
|
||||||
__Autoarr_##type##_functions_list_t* functions; \
|
__Autoarr_##type##_functions_list_t* functions; \
|
||||||
) \
|
) \
|
||||||
\
|
\
|
||||||
Autoarr_##type* __Autoarr_##type##_create(u16 max_blocks_count, u16 max_block_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##_freeWithMembers(Autoarr_##type* ar, bool freePtr); \
|
||||||
void ____Autoarr_##type##_freeWithMembers(void* ar);
|
void ____Autoarr_##type##_freeWithMembers(void* ar);
|
||||||
|
|
||||||
#define Autoarr(type) Autoarr_##type
|
#define Autoarr(type) Autoarr_##type
|
||||||
|
|
||||||
#define Autoarr_create(type, max_blocks_count, max_block_length) \
|
#define Autoarr_create(type, max_chunks_count, max_chunk_length) \
|
||||||
__Autoarr_##type##_create(max_blocks_count, max_block_length)
|
__Autoarr_##type##_create(max_chunks_count, max_chunk_length)
|
||||||
#define Autoarr_add(autoarr, element) \
|
#define Autoarr_add(autoarr, element) \
|
||||||
autoarr->functions->add(autoarr, element)
|
autoarr->functions->add(autoarr, element)
|
||||||
#define Autoarr_get(autoarr, index) \
|
#define Autoarr_get(autoarr, index) \
|
||||||
@@ -55,18 +55,18 @@ void ____Autoarr_##type##_freeWithMembers(void* ar);
|
|||||||
autoarr->functions->toArray(autoarr)
|
autoarr->functions->toArray(autoarr)
|
||||||
|
|
||||||
#define Autoarr_length(autoarr) \
|
#define Autoarr_length(autoarr) \
|
||||||
(u32)(!autoarr->blocks_count ? 0 : \
|
(u32)(!autoarr->chunks_count ? 0 : \
|
||||||
autoarr->max_block_length*(autoarr->blocks_count-1)+autoarr->block_length)
|
autoarr->max_chunk_length*(autoarr->chunks_count-1)+autoarr->chunk_length)
|
||||||
#define Autoarr_max_length(autoarr) \
|
#define Autoarr_max_length(autoarr) \
|
||||||
(u32)(autoarr->max_block_length*autoarr->max_blocks_count)
|
(u32)(autoarr->max_chunk_length*autoarr->max_chunks_count)
|
||||||
|
|
||||||
#define Autoarr_pop(AR){ \
|
#define Autoarr_pop(AR){ \
|
||||||
if(AR->block_length==1){ \
|
if(AR->chunk_length==1){ \
|
||||||
AR->blocks_count--; \
|
AR->chunks_count--; \
|
||||||
AR->block_length=AR->max_block_length; \
|
AR->chunk_length=AR->max_chunk_length; \
|
||||||
free(AR->values[AR->blocks_count]); \
|
free(AR->chunks[AR->chunks_count]); \
|
||||||
} \
|
} \
|
||||||
else AR->block_length--; \
|
else AR->chunk_length--; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
@@ -11,40 +11,40 @@ extern "C" {
|
|||||||
kt_define(Autoarr_##type, ____Autoarr_##type##_freeWithMembers, NULL); \
|
kt_define(Autoarr_##type, ____Autoarr_##type##_freeWithMembers, NULL); \
|
||||||
\
|
\
|
||||||
void __Autoarr_##type##_add(Autoarr_##type* ar, type element){ \
|
void __Autoarr_##type##_add(Autoarr_##type* ar, type element){ \
|
||||||
if(!ar->values){ \
|
if(!ar->chunks){ \
|
||||||
ar->values=malloc(ar->max_blocks_count*sizeof(type*)); \
|
ar->chunks=malloc(ar->max_chunks_count*sizeof(type*)); \
|
||||||
goto create_block; \
|
goto create_chunk; \
|
||||||
} \
|
} \
|
||||||
if(ar->block_length==ar->max_block_length){ \
|
if(ar->chunk_length==ar->max_chunk_length){ \
|
||||||
if (ar->blocks_count>=ar->max_blocks_count) throw(ERR_MAXLENGTH); \
|
if (ar->chunks_count>=ar->max_chunks_count) throw(ERR_MAXLENGTH); \
|
||||||
ar->block_length=0; \
|
ar->chunk_length=0; \
|
||||||
create_block: \
|
create_chunk: \
|
||||||
ar->values[ar->blocks_count]=malloc(ar->max_block_length*sizeof(type)); \
|
ar->chunks[ar->chunks_count]=malloc(ar->max_chunk_length*sizeof(type)); \
|
||||||
ar->blocks_count++; \
|
ar->chunks_count++; \
|
||||||
} \
|
} \
|
||||||
ar->values[ar->blocks_count-1][ar->block_length]=element; \
|
ar->chunks[ar->chunks_count-1][ar->chunk_length]=element; \
|
||||||
ar->block_length++; \
|
ar->chunk_length++; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
type __Autoarr_##type##_get(Autoarr_##type* ar, u32 index){ \
|
type __Autoarr_##type##_get(Autoarr_##type* ar, u32 index){ \
|
||||||
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
||||||
return ar->values[index/ar->max_block_length][index%ar->max_block_length]; \
|
return ar->chunks[index/ar->max_chunk_length][index%ar->max_chunk_length]; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
type* __Autoarr_##type##_getPtr(Autoarr_##type* ar, u32 index){ \
|
type* __Autoarr_##type##_getPtr(Autoarr_##type* ar, u32 index){ \
|
||||||
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
||||||
return ar->values[index/ar->max_block_length]+(index%ar->max_block_length); \
|
return ar->chunks[index/ar->max_chunk_length]+(index%ar->max_chunk_length); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void __Autoarr_##type##_set(Autoarr_##type* ar, u32 index, type element){ \
|
void __Autoarr_##type##_set(Autoarr_##type* ar, u32 index, type element){ \
|
||||||
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
||||||
ar->values[index/ar->max_block_length][index%ar->max_block_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##_freeWithoutMembers(Autoarr_##type* ar, bool freePtr){ \
|
||||||
for(u16 i=0; i<ar->blocks_count;i++) \
|
for(u16 i=0; i<ar->chunks_count;i++) \
|
||||||
free(ar->values[i]); \
|
free(ar->chunks[i]); \
|
||||||
free(ar->values); \
|
free(ar->chunks); \
|
||||||
if(freePtr) free(ar); \
|
if(freePtr) free(ar); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -82,14 +82,14 @@ __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list={ \
|
|||||||
&__Autoarr_##type##_toArray \
|
&__Autoarr_##type##_toArray \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
Autoarr_##type* __Autoarr_##type##_create(u16 max_blocks_count, u16 max_block_length){ \
|
Autoarr_##type* __Autoarr_##type##_create(u16 max_chunks_count, u16 max_chunk_length){ \
|
||||||
Autoarr_##type* ar=malloc(sizeof(Autoarr_##type)); \
|
Autoarr_##type* ar=malloc(sizeof(Autoarr_##type)); \
|
||||||
*ar=(Autoarr_##type){ \
|
*ar=(Autoarr_##type){ \
|
||||||
.max_blocks_count=max_blocks_count, \
|
.max_chunks_count=max_chunks_count, \
|
||||||
.blocks_count=0, \
|
.chunks_count=0, \
|
||||||
.max_block_length=max_block_length, \
|
.max_chunk_length=max_chunk_length, \
|
||||||
.block_length=0, \
|
.chunk_length=0, \
|
||||||
.values=NULL, \
|
.chunks=NULL, \
|
||||||
.functions=&__Autoarr_##type##_functions_list \
|
.functions=&__Autoarr_##type##_functions_list \
|
||||||
}; \
|
}; \
|
||||||
return ar; \
|
return ar; \
|
||||||
|
|||||||
@@ -44,10 +44,16 @@ 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];
|
||||||
ksprintf(errmsg,1024, "unexpected <%c> at:\n"
|
IFMSC(
|
||||||
|
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__); }
|
||||||
@@ -186,7 +192,10 @@ 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];
|
||||||
ksprintf(err,64,"can't parse to int: <%s>",_c);
|
IFMSC(
|
||||||
|
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);
|
||||||
@@ -199,7 +208,10 @@ 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];
|
||||||
ksprintf(err,64,"can't parse to int: <%s>",_c);
|
IFMSC(
|
||||||
|
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);
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ Maybe dir_create(const char* path){
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
char err[512];
|
char err[512];
|
||||||
ksprintf(err, 512, "can't create dicectory <%s>", path);
|
IFWIN(
|
||||||
|
sprintf_s(err, 512, "can't create dicectory <%s>", path),
|
||||||
|
sprintf(err, "can't create dicectory <%s>", path));
|
||||||
safethrow(err,;);
|
safethrow(err,;);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,64 +64,64 @@ Maybe file_close(FileHandle file){
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ioWriteCheck() \
|
#define ioWriteCheck() \
|
||||||
if(result==EOF) \
|
if(rezult==EOF) \
|
||||||
safethrow(ERR_IO_EOF,;); \
|
safethrow(ERR_IO_EOF,;); \
|
||||||
if(result!=0) \
|
if(rezult!=0) \
|
||||||
safethrow(ERR_IO,;);
|
safethrow(ERR_IO,;);
|
||||||
|
|
||||||
Maybe file_writeChar(FileHandle file, char byte){
|
Maybe file_writeChar(FileHandle file, char byte){
|
||||||
i32 result=fputc(byte, file);
|
i32 rezult=fputc(byte, file);
|
||||||
ioWriteCheck();
|
ioWriteCheck();
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_writeBuffer(FileHandle file, char* buffer, u64 length){
|
Maybe file_writeBuffer(FileHandle file, char* buffer, u64 length){
|
||||||
i32 result=0;
|
i32 rezult=0;
|
||||||
for(u64 i=0; i<length && !result; i++)
|
for(u64 i=0; i<length && !rezult; i++)
|
||||||
result=fputc(buffer[i], file);
|
rezult=fputc(buffer[i], file);
|
||||||
ioWriteCheck();
|
ioWriteCheck();
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_writeCptr(FileHandle file, char* cptr){
|
Maybe file_writeCptr(FileHandle file, char* cptr){
|
||||||
i32 result=fputs(cptr, file);
|
i32 rezult=fputs(cptr, file);
|
||||||
ioWriteCheck();
|
ioWriteCheck();
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Maybe file_readChar(FileHandle file){
|
Maybe file_readChar(FileHandle file){
|
||||||
i32 result=fgetc(file);
|
i32 rezult=fgetc(file);
|
||||||
if(feof(file)) safethrow(ERR_IO_EOF,;);
|
if(feof(file)) safethrow(ERR_IO_EOF,;);
|
||||||
if(ferror(file)) safethrow(ERR_IO,;);
|
if(ferror(file)) safethrow(ERR_IO,;);
|
||||||
return SUCCESS(UniUInt64(result));
|
return SUCCESS(UniUInt64(rezult));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_readBuffer(FileHandle file, char* buffer, u64 length){
|
Maybe file_readBuffer(FileHandle file, char* buffer, u64 length){
|
||||||
i32 result=0;
|
i32 rezult=0;
|
||||||
u64 i=0;
|
u64 i=0;
|
||||||
for(; i<length && result!=EOF; i++){
|
for(; i<length && rezult!=EOF; i++){
|
||||||
result=fgetc(file);
|
rezult=fgetc(file);
|
||||||
buffer[i]=(char)result;
|
buffer[i]=(char)rezult;
|
||||||
}
|
}
|
||||||
if(ferror(file)) safethrow(ERR_IO,;);
|
if(ferror(file)) safethrow(ERR_IO,;);
|
||||||
return SUCCESS(UniUInt64(i));
|
return SUCCESS(UniUInt64(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_readAll(FileHandle file, char** allBytes){
|
Maybe file_readAll(FileHandle file, char** allBytes){
|
||||||
i32 result=0;
|
i32 rezult=0;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
string bufStr={.ptr=buffer, .length=sizeof(buffer)};
|
string bufStr={.ptr=buffer, .length=sizeof(buffer)};
|
||||||
StringBuilder* sb=StringBuilder_create();
|
StringBuilder* sb=StringBuilder_create();
|
||||||
u64 i=0;
|
u64 i=0;
|
||||||
while(true){
|
while(true){
|
||||||
result=fgetc(file);
|
rezult=fgetc(file);
|
||||||
if(result==EOF){
|
if(rezult==EOF){
|
||||||
if(ferror(file))
|
if(ferror(file))
|
||||||
safethrow(ERR_IO, StringBuilder_free(sb));
|
safethrow(ERR_IO, StringBuilder_free(sb));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer[i%sizeof(buffer)]=(char)result;
|
buffer[i%sizeof(buffer)]=(char)rezult;
|
||||||
i++;
|
i++;
|
||||||
if(!(i%sizeof(buffer)))
|
if(!(i%sizeof(buffer)))
|
||||||
StringBuilder_append_string(sb,bufStr);
|
StringBuilder_append_string(sb,bufStr);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ char* __path_concat(u32 n, ...){
|
|||||||
const char* output=totality;
|
const char* output=totality;
|
||||||
totality[totalLength]=0;
|
totality[totalLength]=0;
|
||||||
|
|
||||||
// copying content of all strings to result
|
// copying content of all strings to rezult
|
||||||
u16 k=0;
|
u16 k=0;
|
||||||
for(; k<n-1; k++){
|
for(; k<n-1; k++){
|
||||||
memcpy(totality, parts[k], lengths[k]);
|
memcpy(totality, parts[k], lengths[k]);
|
||||||
@@ -74,11 +74,11 @@ char* path_parentDir(char* dir){
|
|||||||
|
|
||||||
char* path_basename(char* path, bool with_extension){
|
char* path_basename(char* path, bool with_extension){
|
||||||
i32 nameIndex=cptr_lastIndexOfChar(path, path_sep)+1;
|
i32 nameIndex=cptr_lastIndexOfChar(path, path_sep)+1;
|
||||||
string result=string_fromCptr(path+nameIndex);
|
string rezult=string_fromCptr(path+nameIndex);
|
||||||
if(!with_extension){
|
if(!with_extension){
|
||||||
i32 extIndex=cptr_lastIndexOfChar(result.ptr, '.');
|
i32 extIndex=cptr_lastIndexOfChar(rezult.ptr, '.');
|
||||||
if(extIndex!=0 && extIndex!=-1)
|
if(extIndex!=0 && extIndex!=-1)
|
||||||
result.length=extIndex;
|
rezult.length=extIndex;
|
||||||
}
|
}
|
||||||
return string_extract(result);
|
return string_extract(rezult);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
# kerep network
|
|
||||||
|
|
||||||
Don't forget to call `kn_tryInit()` before doint anything with network.
|
|
||||||
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#include "network_internal.h"
|
|
||||||
|
|
||||||
Maybe kn_tryInit(){
|
|
||||||
#if _WIN32
|
|
||||||
// Initialize Winsock
|
|
||||||
WSADATA wsaData = {0};
|
|
||||||
int startupResult = WSAStartup(MAKEWORD(2,2), &wsaData);
|
|
||||||
if (startupResult != 0) {
|
|
||||||
char* errcode = toString_hex(&startupResult, sizeof(int), 0 , 1, 1);
|
|
||||||
safethrow(cptr_concat("WSAStartup failed with error: ", errcode), ;);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return SUCCESS(UniNull);
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe kt_tryDispose(){
|
|
||||||
#if _WIN32
|
|
||||||
// Deinitialize Winsock
|
|
||||||
int cleanupResult = WSACleanup();
|
|
||||||
if (cleanupResult != 0) {
|
|
||||||
char* errcode = toString_hex(&cleanupResult, sizeof(int), 0, 1, 1);
|
|
||||||
safethrow(cptr_concat("WSAStartup failed with error: ", errcode), ;);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return SUCCESS(UniNull);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Maybe __kn_StdSocket_shutdown(i64 socketfd, knShutdownType direction){
|
|
||||||
if(shutdown(socketfd, (int)direction) == -1)
|
|
||||||
safethrow("can't shutdown socket", ;);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe __kn_StdSocket_close(i64 socketfd){
|
|
||||||
#if KN_USE_WINSOCK
|
|
||||||
if(closesocket(socketfd) == -1)
|
|
||||||
#else
|
|
||||||
if(close(socketfd) == -1)
|
|
||||||
#endif
|
|
||||||
safethrow("can't close socket", ;);
|
|
||||||
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../base/base.h"
|
|
||||||
|
|
||||||
#include "network_types.h"
|
|
||||||
#include "sockets/knSocketTCP.h"
|
|
||||||
#include "sockets/knSocketUDP.h"
|
|
||||||
#include "sockets/knSocketChanneled.h"
|
|
||||||
|
|
||||||
Maybe kn_tryInit();
|
|
||||||
Maybe kt_tryDispose();
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "network.h"
|
|
||||||
#include "socket_impl_includes.h"
|
|
||||||
|
|
||||||
/// shutdown TCP/UDP/other std socket
|
|
||||||
Maybe __kn_StdSocket_shutdown(i64 socketfd, knShutdownType direction);
|
|
||||||
|
|
||||||
/// close TCP/UDP/other std socket
|
|
||||||
Maybe __kn_StdSocket_close(i64 socketfd);
|
|
||||||
|
|
||||||
static inline struct sockaddr_in knIPV4Endpoint_toSockaddr(knIPV4Endpoint end){
|
|
||||||
struct sockaddr_in saddr = {0};
|
|
||||||
saddr.sin_family = AF_INET;
|
|
||||||
saddr.sin_addr.s_addr = end.address.UintBigEndian;
|
|
||||||
saddr.sin_port = htons(end.port); /* transforms port number to big endian (network order) */
|
|
||||||
return saddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline knIPV4Endpoint knIPV4Endpoint_fromSockaddr(struct sockaddr_in saddr_ptr){
|
|
||||||
knIPV4Address ipv4 = knIPV4Address_fromU32(saddr_ptr.sin_addr.s_addr);
|
|
||||||
u16 port = ntohs(saddr_ptr.sin_port); /* transforms port number to little endian (normal order) */
|
|
||||||
return knIPV4Endpoint_create(ipv4, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
#include "network_types.h"
|
|
||||||
|
|
||||||
char* __knIPV4Address_toString(void* p, u32 f){ return knIPV4Address_toString(*(knIPV4Address*)p); }
|
|
||||||
char* __knIPV4Endpoint_toString(void* p, u32 f){ return knIPV4Endpoint_toString(*(knIPV4Endpoint*)p); }
|
|
||||||
|
|
||||||
kt_define(knIPV4Address, NULL, __knIPV4Address_toString);
|
|
||||||
kt_define(knIPV4Endpoint, NULL, __knIPV4Endpoint_toString);
|
|
||||||
|
|
||||||
|
|
||||||
Maybe knIPV4Address_fromStr(char* addrStr, knIPV4Address* addrVal){
|
|
||||||
char* addrStr_src=addrStr;
|
|
||||||
char* errmsg_extra="wrong char";
|
|
||||||
u8 c;
|
|
||||||
knIPV4Address addr;
|
|
||||||
addr.UintBigEndian=0;
|
|
||||||
u16 n=0;
|
|
||||||
for(u8 i=0; i<4; ){
|
|
||||||
c=*addrStr++;
|
|
||||||
switch (c){
|
|
||||||
case '\0':
|
|
||||||
if(i<3){
|
|
||||||
errmsg_extra="end of string";
|
|
||||||
goto default_case;
|
|
||||||
}
|
|
||||||
|
|
||||||
addr.bytes[i++]=n;
|
|
||||||
n=0;
|
|
||||||
break;
|
|
||||||
case '.':
|
|
||||||
addr.bytes[i++]=n;
|
|
||||||
n=0;
|
|
||||||
break;
|
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
|
||||||
n=n*10+c-'0';
|
|
||||||
if(n>255) {
|
|
||||||
errmsg_extra="one part of address > 255";
|
|
||||||
goto default_case;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default_case:
|
|
||||||
default:
|
|
||||||
u32 errmsgL=cptr_length(addrStr) + 80;
|
|
||||||
char* errmsg=malloc(errmsgL);
|
|
||||||
ksprintf(errmsg, errmsgL, "wrong ip address string: %s\n %s", addrStr_src, errmsg_extra);
|
|
||||||
safethrow(errmsg,;);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*addrVal=addr;
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* knIPV4Address_toString(knIPV4Address address) {
|
|
||||||
char* a = toString_u64(address.bytes[0], 0, 0);
|
|
||||||
char* b = toString_u64(address.bytes[1], 0, 0);
|
|
||||||
char* c = toString_u64(address.bytes[2], 0, 0);
|
|
||||||
char* d = toString_u64(address.bytes[3], 0, 0);
|
|
||||||
char* s = cptr_concat(a,".",b,".",c,".",d);
|
|
||||||
free(a);
|
|
||||||
free(b);
|
|
||||||
free(c);
|
|
||||||
free(d);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Maybe knIPV4Endpoint_fromStr(char* endStr, knIPV4Endpoint* endVal){
|
|
||||||
i32 sep_i = cptr_seekChar(endStr, ':', 0, 48);
|
|
||||||
if(sep_i < 7)
|
|
||||||
safethrow(cptr_concat("can't find ':' in '", endStr, "'"), ;);
|
|
||||||
const char* portBegin = endStr+sep_i+1;
|
|
||||||
u64 port = knPort_INVALID;
|
|
||||||
if(sscanf(portBegin, IFWIN("%llu", "%lu"), &port)!=1)
|
|
||||||
safethrow(cptr_concat("can't recognise port number in '", portBegin, "'"), ;)
|
|
||||||
|
|
||||||
knIPV4Address addr = knIPV4Address_INVALID;
|
|
||||||
char* addrStr = cptr_copy(endStr);
|
|
||||||
addrStr[sep_i] = 0;
|
|
||||||
try(knIPV4Address_fromStr(addrStr, &addr), _m865, ;);
|
|
||||||
free(addrStr);
|
|
||||||
|
|
||||||
*endVal = knIPV4Endpoint_create(addr, port);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* knIPV4Endpoint_toString(knIPV4Endpoint end) {
|
|
||||||
char* a = knIPV4Address_toString(end.address);
|
|
||||||
char* p = toString_u64(end.port, 0, 0);
|
|
||||||
char* s = cptr_concat(a,":",p);
|
|
||||||
free(a);
|
|
||||||
free(p);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../base/base.h"
|
|
||||||
|
|
||||||
typedef u16 knPort;
|
|
||||||
#define knPort_INVALID ((knPort)~0)
|
|
||||||
#define knPort_isINVALID(PORT) (PORT == knPort_INVALID)
|
|
||||||
|
|
||||||
typedef union knIPV4Address {
|
|
||||||
u32 UintBigEndian;
|
|
||||||
u8 bytes[4];
|
|
||||||
} knIPV4Address;
|
|
||||||
kt_declare(knIPV4Address);
|
|
||||||
|
|
||||||
#define knIPV4Address_fromBytes(A, B, C, D) ((knIPV4Address){.bytes={A,B,C,D}})
|
|
||||||
#define knIPV4Address_fromU32(N) ((knIPV4Address){.UintBigEndian=N})
|
|
||||||
|
|
||||||
|
|
||||||
#define knIPV4Address_ANY knIPV4Address_fromBytes(0,0,0,0)
|
|
||||||
#define knIPV4Address_LOOPBACK knIPV4Address_fromBytes(127,0,0,1)
|
|
||||||
#define knIPV4Address_INVALID knIPV4Address_fromBytes(255,255,255,255)
|
|
||||||
#define knIPV4Address_isINVALID(ADDR) (ADDR.UintBigEndian == (u32)~0)
|
|
||||||
|
|
||||||
///@return Maybe<null>
|
|
||||||
Maybe knIPV4Address_fromStr(char* addrStr, knIPV4Address* addrPtr);
|
|
||||||
|
|
||||||
char* knIPV4Address_toString(knIPV4Address address);
|
|
||||||
|
|
||||||
|
|
||||||
STRUCT(knIPV4Endpoint,
|
|
||||||
knIPV4Address address;
|
|
||||||
knPort port;
|
|
||||||
)
|
|
||||||
|
|
||||||
#define knIPV4Endpoint_create(ADDR, PORT) ((knIPV4Endpoint){ADDR, PORT})
|
|
||||||
|
|
||||||
#define knIPV4Endpoint_INVALID knIPV4Endpoint_create(knIPV4Address_INVALID, knPort_INVALID)
|
|
||||||
#define knIPV4Endpoint_isINVALID(ENDP) (knIPV4Address_isINVALID(ENDP.address) || knPort_isINVALID(ENDP.port))
|
|
||||||
|
|
||||||
///@return Maybe<null>
|
|
||||||
Maybe knIPV4Endpoint_fromStr(char* endStr, knIPV4Endpoint* endVal);
|
|
||||||
|
|
||||||
char* knIPV4Endpoint_toString(knIPV4Endpoint end);
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum knShutdownType {
|
|
||||||
knShutdownType_Receive = 0,
|
|
||||||
knShutdownType_Send = 1,
|
|
||||||
knShutdownType_Both = 2,
|
|
||||||
} knShutdownType;
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
|
||||||
#define KN_USE_WINSOCK 1
|
|
||||||
#else
|
|
||||||
#define KN_USE_WINSOCK 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KN_USE_WINSOCK
|
|
||||||
#include <winsock2.h>
|
|
||||||
// #include <ws2tcpip.h>
|
|
||||||
#else
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#include "../network_internal.h"
|
|
||||||
|
|
||||||
void __knSocketChanneled_close(void* p){ knSocketChanneled_close(p); }
|
|
||||||
|
|
||||||
kt_define(knPackage, NULL, NULL);
|
|
||||||
kt_define(knPackageQueueElem, NULL, NULL);
|
|
||||||
kt_define(knChannel, NULL, NULL);
|
|
||||||
kt_define(knSocketChanneled, __knSocketChanneled_close, NULL);
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_open(){
|
|
||||||
knSocketChanneled* newSocket=malloc(sizeof(knSocketChanneled));
|
|
||||||
newSocket->localEndpoint=knIPV4Endpoint_INVALID;
|
|
||||||
newSocket->remoteEndpoint=knIPV4Endpoint_INVALID;
|
|
||||||
newSocket->channels=NULL;
|
|
||||||
newSocket->channelsAmount=0;
|
|
||||||
return SUCCESS(UniHeapPtr(knSocketChanneled, newSocket));
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_close(knSocketChanneled* socket){
|
|
||||||
try(__kn_StdSocket_close(socket->socketfd), _m762, ;);
|
|
||||||
free(socket);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
knChannel* __createChannel(){
|
|
||||||
knChannel* ch=malloc(sizeof(knChannel));
|
|
||||||
ch->queueStart=NULL;
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_createChannel(knSocketChanneled* socket){
|
|
||||||
if(socket->channelsAmount == 65535)
|
|
||||||
safethrow("max amount of channels",;);
|
|
||||||
u16 channelsAmountPrev=socket->channelsAmount;
|
|
||||||
socket->channelsAmount++;
|
|
||||||
if(channelsAmountPrev==0)
|
|
||||||
socket->channels=malloc(sizeof(knChannel*));
|
|
||||||
else
|
|
||||||
socket->channels=realloc(socket->channels, socket->channelsAmount*sizeof(knChannel*));
|
|
||||||
socket->channels[channelsAmountPrev]=__createChannel();
|
|
||||||
return SUCCESS(UniUInt64(channelsAmountPrev));
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_listen(knSocketChanneled* socket, knIPV4Endpoint localEndp);
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_connect(knSocketChanneled* socket, knIPV4Endpoint remoteEndp);
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_accept(knSocketChanneled* socket);
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_send(knSocketChanneled* socket, u16 destinationIndex, u8* data, u32 dataLength);
|
|
||||||
|
|
||||||
Maybe knSocketChanneled_receive(knSocketChanneled* socket, u16 destinationIndex, u8* buffer, u32 bufferLength);
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../network_types.h"
|
|
||||||
|
|
||||||
#define KNPAC_MAX_DATA_SIZE (65535-sizeof(knPackage)+sizeof(u8*))
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum __attribute__((__packed__)) knPacVersion {
|
|
||||||
knPac_V1=1
|
|
||||||
} knPacVersion;
|
|
||||||
|
|
||||||
static const char knPacHeader[5]={'k','n','p','a','c'};
|
|
||||||
|
|
||||||
STRUCT(knPackage,
|
|
||||||
char header[5]; /* knpac */
|
|
||||||
knPacVersion version; /* protocol version */
|
|
||||||
u16 data_size; /* size of data block in bytes (1-KNPAC_MAX_DATA_SIZE) */
|
|
||||||
u32 channel_id; /* id of knChannel in socket */
|
|
||||||
u32 package_num; /* number in sequence of sent packages */
|
|
||||||
u64 data_hash; /* hash64 of data */
|
|
||||||
u8* data; /* ptr to data */
|
|
||||||
)
|
|
||||||
|
|
||||||
STRUCT(knPackageQueueElem,
|
|
||||||
knPackage package;
|
|
||||||
knPackageQueueElem* previousElem;
|
|
||||||
knPackageQueueElem* nextElem;
|
|
||||||
)
|
|
||||||
|
|
||||||
STRUCT(knChannel,
|
|
||||||
knPackageQueueElem* queueStart;
|
|
||||||
)
|
|
||||||
|
|
||||||
STRUCT(knSocketChanneled,
|
|
||||||
i64 socketfd;
|
|
||||||
knIPV4Endpoint localEndpoint;
|
|
||||||
knIPV4Endpoint remoteEndpoint;
|
|
||||||
u16 channelsAmount;
|
|
||||||
knChannel** channels;
|
|
||||||
)
|
|
||||||
|
|
||||||
///@return Maybe<knSocketChanneled*> new socket
|
|
||||||
Maybe knSocketChanneled_open();
|
|
||||||
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketChanneled_close(knSocketChanneled* socket);
|
|
||||||
|
|
||||||
///@return Maybe<u64> channel index
|
|
||||||
Maybe knSocketChanneled_createChannel(knSocketChanneled* socket);
|
|
||||||
|
|
||||||
///start listening at local endpoint
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketChanneled_listen(knSocketChanneled* socket, knIPV4Endpoint localEndp);
|
|
||||||
|
|
||||||
///sets socket remote endpoint
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketChanneled_connect(knSocketChanneled* socket, knIPV4Endpoint remoteEndp);
|
|
||||||
|
|
||||||
///@return Maybe<knSocketChanneled*> new socket connected to client
|
|
||||||
Maybe knSocketChanneled_accept(knSocketChanneled* socket);
|
|
||||||
|
|
||||||
///@param dataLength 0-4294967295
|
|
||||||
///@return Maybe<void>
|
|
||||||
Maybe knSocketChanneled_send(knSocketChanneled* socket, u16 destinationIndex, u8* data, u32 dataLength);
|
|
||||||
|
|
||||||
///@param buffer buffer for receiving data
|
|
||||||
///@param bufferLength 0-4294967295
|
|
||||||
///@return Maybe<u64> received bytes amount
|
|
||||||
Maybe knSocketChanneled_receive(knSocketChanneled* socket, u16 destinationIndex, u8* buffer, u32 bufferLength);
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
#include "../network_internal.h"
|
|
||||||
|
|
||||||
void __knSocketTCP_close(void* p){ knSocketTCP_close(p); }
|
|
||||||
|
|
||||||
kt_define(knSocketTCP, __knSocketTCP_close, NULL);
|
|
||||||
|
|
||||||
Maybe knSocketTCP_open(bool allowReuse){
|
|
||||||
knSocketTCP* newSocket=malloc(sizeof(knSocketTCP));
|
|
||||||
newSocket->localEndpoint=knIPV4Endpoint_INVALID;
|
|
||||||
newSocket->remoteEndpoint=knIPV4Endpoint_INVALID;
|
|
||||||
newSocket->socketfd=socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
if(newSocket->socketfd==-1 || newSocket->socketfd == ~0)
|
|
||||||
safethrow("can't create socket", free(newSocket));
|
|
||||||
|
|
||||||
// set value of REUSEADDR socket option
|
|
||||||
int opt_val = allowReuse;
|
|
||||||
if(setsockopt(newSocket->socketfd, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(opt_val)) != 0)
|
|
||||||
safethrow("can't set socket options", knSocketTCP_close(newSocket));
|
|
||||||
|
|
||||||
return SUCCESS(UniHeapPtr(knSocketTCP, newSocket));
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_shutdown(knSocketTCP* socket, knShutdownType direction){
|
|
||||||
try(__kn_StdSocket_shutdown(socket->socketfd, direction), _m875, ;);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_close(knSocketTCP* socket){
|
|
||||||
try(__kn_StdSocket_close(socket->socketfd), _m875, ;);
|
|
||||||
free(socket);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_bind(knSocketTCP* socket, knIPV4Endpoint localEndp){
|
|
||||||
struct sockaddr_in servaddr = knIPV4Endpoint_toSockaddr(localEndp);
|
|
||||||
if(bind(socket->socketfd, (void*)&servaddr, sizeof(servaddr)) != 0)
|
|
||||||
safethrow("socket bind failed", ;);
|
|
||||||
|
|
||||||
socket->localEndpoint = localEndp;
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_listen(knSocketTCP* socket){
|
|
||||||
if(listen(socket->socketfd, 1024) != 0)
|
|
||||||
safethrow("socket listen failed", ;);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_connect(knSocketTCP* socket, knIPV4Endpoint remoteEnd){
|
|
||||||
struct sockaddr_in localAddr = {0};
|
|
||||||
struct sockaddr_in remoteAddr = knIPV4Endpoint_toSockaddr(remoteEnd);
|
|
||||||
u64 sockaddr_size = sizeof(localAddr);
|
|
||||||
|
|
||||||
if(connect(socket->socketfd, (struct sockaddr*)&remoteAddr, sizeof(remoteAddr)) != 0)
|
|
||||||
safethrow("socket connect failed", ;);
|
|
||||||
|
|
||||||
if(getsockname(socket->socketfd, (struct sockaddr*)&localAddr, (void*)&sockaddr_size) != 0)
|
|
||||||
safethrow("can't get connected socket local address", ;);
|
|
||||||
|
|
||||||
socket->localEndpoint = knIPV4Endpoint_fromSockaddr(localAddr);
|
|
||||||
socket->remoteEndpoint = remoteEnd;
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_accept(knSocketTCP* socket){
|
|
||||||
struct sockaddr_in localAddr = {0};
|
|
||||||
struct sockaddr_in remoteAddr = {0};
|
|
||||||
u64 sockaddr_size = sizeof(localAddr);
|
|
||||||
|
|
||||||
i64 client_fd = accept(socket->socketfd, (struct sockaddr*)&remoteAddr, (void*)&sockaddr_size);
|
|
||||||
if(client_fd == -1 || client_fd == ~0)
|
|
||||||
safethrow("can't accept client connection", ;);
|
|
||||||
|
|
||||||
if(getsockname(client_fd, (struct sockaddr*)&localAddr, (void*)&sockaddr_size) != 0)
|
|
||||||
safethrow("can't get accepted socket local address", __kn_StdSocket_close(client_fd));
|
|
||||||
|
|
||||||
// if accept() didn't set remoteAddr for some reason
|
|
||||||
if(remoteAddr.sin_addr.s_addr == 0 && remoteAddr.sin_port == 0 && remoteAddr.sin_family == 0){
|
|
||||||
if(getpeername(client_fd, (struct sockaddr*)&remoteAddr, (void*)&sockaddr_size) != 0)
|
|
||||||
safethrow("can't get accepted socket remote address", __kn_StdSocket_close(client_fd));
|
|
||||||
}
|
|
||||||
|
|
||||||
knSocketTCP* clientSocket = malloc(sizeof(knSocketTCP));
|
|
||||||
clientSocket->socketfd = client_fd;
|
|
||||||
clientSocket->localEndpoint = knIPV4Endpoint_fromSockaddr(localAddr);
|
|
||||||
clientSocket->remoteEndpoint = knIPV4Endpoint_fromSockaddr(remoteAddr);
|
|
||||||
return SUCCESS(UniHeapPtr(knSocketTCP, clientSocket));
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_send(knSocketTCP* socket, void* _buf, u32 dataLength){
|
|
||||||
char* buf = _buf;
|
|
||||||
u32 sentTotal = 0;
|
|
||||||
while(sentTotal < dataLength){
|
|
||||||
int sentCount = send(socket->socketfd, buf+sentTotal, dataLength-sentTotal, 0);
|
|
||||||
if(sentCount == -1){
|
|
||||||
safethrow(
|
|
||||||
cptr_concat("can't send ", toString_u64(dataLength-sentTotal,0,0),
|
|
||||||
" bytes out of ", toString_u64(dataLength,0,0),
|
|
||||||
" at index ", toString_u64(sentTotal,0,0)
|
|
||||||
),
|
|
||||||
;);
|
|
||||||
}
|
|
||||||
sentTotal += sentCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_receive(knSocketTCP* socket, void* _buf, u32 bufferLength){
|
|
||||||
char* buf = _buf;
|
|
||||||
int receivedCount = recv(socket->socketfd, buf, bufferLength, 0);
|
|
||||||
if(receivedCount == -1 || receivedCount == 0)
|
|
||||||
safethrow("can't receive data from socket", ;)
|
|
||||||
|
|
||||||
return SUCCESS(UniUInt64(receivedCount));
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketTCP_receiveN(knSocketTCP* socket, void* _buf, u32 bufsize, u32 n){
|
|
||||||
char* buf = _buf;
|
|
||||||
if(bufsize < n)
|
|
||||||
safethrow(ERR_UNEXPECTEDVAL, ;);
|
|
||||||
|
|
||||||
u32 receivedTotal = 0;
|
|
||||||
while(receivedTotal < n) {
|
|
||||||
try(knSocketTCP_receive(socket, buf+receivedTotal, n-receivedTotal), m_receivedCount, ;);
|
|
||||||
receivedTotal += m_receivedCount.value.UInt64;
|
|
||||||
}
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../network_types.h"
|
|
||||||
|
|
||||||
STRUCT(knSocketTCP,
|
|
||||||
i64 socketfd;
|
|
||||||
knIPV4Endpoint localEndpoint;
|
|
||||||
knIPV4Endpoint remoteEndpoint;
|
|
||||||
/* TODO socket status enum */
|
|
||||||
)
|
|
||||||
|
|
||||||
///@note EXAMPLE 1: socket = open(false); bind(socket, localhost:8080); close(socket); - the socket on port 8080 still unavaliable for several minutes
|
|
||||||
///@note EXAMPLE 2: socket = open(true); bind(socket, localhost:8080); close(socket); - the socket on port 8080 can be opened again
|
|
||||||
///@param allowReuse enables binding multiple sockets to single port. Set to TRUE on a listening socket if you want to bind it to the same port after close.
|
|
||||||
///@return Maybe<knSocketTCP*> new socket
|
|
||||||
Maybe knSocketTCP_open(bool allowReuse);
|
|
||||||
|
|
||||||
///@param direction receive/send/both
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketTCP_shutdown(knSocketTCP* socket, knShutdownType direction);
|
|
||||||
|
|
||||||
/// closes file descriptor and frees socket pointer
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketTCP_close(knSocketTCP* socket);
|
|
||||||
|
|
||||||
/// binds socket to a local endpoint
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketTCP_bind(knSocketTCP* socket, knIPV4Endpoint localEndp);
|
|
||||||
|
|
||||||
/// begins listening for incoming TCP connections
|
|
||||||
Maybe knSocketTCP_listen(knSocketTCP* socket);
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
|
|
||||||
/// establishes TCP connection with a remote endpoint
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketTCP_connect(knSocketTCP* socket, knIPV4Endpoint remoteEnd);
|
|
||||||
|
|
||||||
///@return Maybe<knSocketTCP*> new socket connected to client
|
|
||||||
Maybe knSocketTCP_accept(knSocketTCP* socket);
|
|
||||||
|
|
||||||
/// sends <dataLength> bytes from buffer
|
|
||||||
///@param buffer buffer for receiving data
|
|
||||||
///@param dataLength 0-4294967295
|
|
||||||
///@return Maybe<void>
|
|
||||||
Maybe knSocketTCP_send(knSocketTCP* socket, void* buffer, u32 dataLength);
|
|
||||||
|
|
||||||
/// receives a package of any size
|
|
||||||
/// (by TCP 32 bytes han be sent as 32x1byte, 4x8byte, 32x1byte or in any other combination)
|
|
||||||
///@param buffer buffer for receiving data
|
|
||||||
///@param bufferLength 0-4294967295
|
|
||||||
///@return Maybe<u64> received bytes amount
|
|
||||||
Maybe knSocketTCP_receive(knSocketTCP* socket, void* buffer, u32 bufferLength);
|
|
||||||
|
|
||||||
/// receives a package of size n
|
|
||||||
///@return Maybe<void>
|
|
||||||
Maybe knSocketTCP_receiveN(knSocketTCP* socket, void* buf, u32 bufsize, u32 n);
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
#include "../network_internal.h"
|
|
||||||
|
|
||||||
void __knSocketUDP_close(void* p){ knSocketUDP_close(p); }
|
|
||||||
|
|
||||||
kt_define(knSocketUDP, __knSocketUDP_close, NULL);
|
|
||||||
|
|
||||||
Maybe knSocketUDP_open(bool allowReuse){
|
|
||||||
knSocketUDP* newSocket=malloc(sizeof(knSocketUDP));
|
|
||||||
newSocket->localEndpoint=knIPV4Endpoint_INVALID;
|
|
||||||
newSocket->socketfd=socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
if(newSocket->socketfd==-1 || newSocket->socketfd == ~0)
|
|
||||||
safethrow("can't create socket", free(newSocket));
|
|
||||||
|
|
||||||
// set value of REUSEADDR socket option
|
|
||||||
int opt_val = allowReuse;
|
|
||||||
if(setsockopt(newSocket->socketfd, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(opt_val)) != 0)
|
|
||||||
safethrow("can't set socket options", knSocketUDP_close(newSocket));
|
|
||||||
|
|
||||||
return SUCCESS(UniHeapPtr(knSocketUDP, newSocket));
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketUDP_shutdown(knSocketUDP* socket, knShutdownType direction){
|
|
||||||
try(__kn_StdSocket_shutdown(socket->socketfd, direction), _m875, ;);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketUDP_close(knSocketUDP* socket){
|
|
||||||
try(__kn_StdSocket_close(socket->socketfd), _m875, ;);
|
|
||||||
free(socket);
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketUDP_bind(knSocketUDP* socket, knIPV4Endpoint localEndp){
|
|
||||||
struct sockaddr_in servaddr = {
|
|
||||||
.sin_family = AF_INET,
|
|
||||||
.sin_addr.s_addr = localEndp.address.UintBigEndian,
|
|
||||||
.sin_port = htons(localEndp.port) /* transforms port to big endian */
|
|
||||||
};
|
|
||||||
|
|
||||||
if(bind(socket->socketfd, (void*)&servaddr, sizeof(servaddr)) != 0)
|
|
||||||
safethrow("socket bind failed", ;);
|
|
||||||
|
|
||||||
socket->localEndpoint = localEndp;
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketUDP_sendTo(knSocketUDP* socket, char* buffer, u32 dataLength, knIPV4Endpoint destEnd){
|
|
||||||
struct sockaddr_in dest_saddr = knIPV4Endpoint_toSockaddr(destEnd);
|
|
||||||
u32 sentCount = sendto(
|
|
||||||
socket->socketfd,
|
|
||||||
buffer,
|
|
||||||
dataLength,
|
|
||||||
0,
|
|
||||||
(struct sockaddr*)&dest_saddr,
|
|
||||||
sizeof(struct sockaddr_in)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(sentCount != dataLength) {
|
|
||||||
safethrow(
|
|
||||||
cptr_concat("can't send ", toString_u64(dataLength-sentCount,0,0),
|
|
||||||
" bytes out of ", toString_u64(dataLength,0,0)
|
|
||||||
),
|
|
||||||
;);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_in localAddr = {0};
|
|
||||||
u64 sockaddr_size = sizeof(localAddr);
|
|
||||||
|
|
||||||
if(getsockname(socket->socketfd, (struct sockaddr*)&localAddr, (void*)&sockaddr_size) != 0)
|
|
||||||
safethrow("can't get implicitely bound socket local address", ;);
|
|
||||||
|
|
||||||
socket->localEndpoint = knIPV4Endpoint_fromSockaddr(localAddr);
|
|
||||||
|
|
||||||
return MaybeNull;
|
|
||||||
}
|
|
||||||
|
|
||||||
Maybe knSocketUDP_receiveAny(knSocketUDP* socket, char* buffer, u32 bufferLength, knIPV4Endpoint* senderEnd){
|
|
||||||
struct sockaddr_in remote_saddr = {0};
|
|
||||||
u64 remote_saddr_size = sizeof(remote_saddr);
|
|
||||||
int receivedCount = recvfrom(
|
|
||||||
socket->socketfd,
|
|
||||||
buffer,
|
|
||||||
bufferLength,
|
|
||||||
0,
|
|
||||||
(struct sockaddr*)&remote_saddr,
|
|
||||||
(void*)&remote_saddr_size
|
|
||||||
);
|
|
||||||
|
|
||||||
if(receivedCount == -1 || receivedCount == 0)
|
|
||||||
safethrow("can't receive data from socket", ;)
|
|
||||||
|
|
||||||
*senderEnd = knIPV4Endpoint_fromSockaddr(remote_saddr);
|
|
||||||
return SUCCESS(UniUInt64(receivedCount));
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../network_types.h"
|
|
||||||
|
|
||||||
STRUCT(knSocketUDP,
|
|
||||||
i64 socketfd;
|
|
||||||
knIPV4Endpoint localEndpoint;
|
|
||||||
/* TODO socket status enum */
|
|
||||||
)
|
|
||||||
|
|
||||||
///@note EXAMPLE 1: socket = open(false); bind(socket, localhost:8080); close(socket); - the socket on port 8080 still unavaliable for several minutes
|
|
||||||
///@note EXAMPLE 2: socket = open(true); bind(socket, localhost:8080); close(socket); - the socket on port 8080 can be opened again
|
|
||||||
///@param allowReuse enables binding multiple sockets to single port. Set to TRUE on a listening socket if you want to bind it to the same port after close.
|
|
||||||
///@return Maybe<knSocketUDP*> new socket
|
|
||||||
Maybe knSocketUDP_open(bool allowReuse);
|
|
||||||
|
|
||||||
///@param direction receive/send/both
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketUDP_shutdown(knSocketUDP* socket, knShutdownType direction);
|
|
||||||
|
|
||||||
/// closes file descriptor and frees socket pointer
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketUDP_close(knSocketUDP* socket);
|
|
||||||
|
|
||||||
/// binds socket to a local endpoint
|
|
||||||
///@return Maybe<void> error or nothing
|
|
||||||
Maybe knSocketUDP_bind(knSocketUDP* socket, knIPV4Endpoint localEndp);
|
|
||||||
|
|
||||||
/// sends one package to destination endpoint
|
|
||||||
///@param buffer buffer for receiving data
|
|
||||||
///@param dataLength 0-64k
|
|
||||||
///@param destEnd destination endpoint
|
|
||||||
///@return Maybe<void>
|
|
||||||
Maybe knSocketUDP_sendTo(knSocketUDP* socket, char* buffer, u32 dataLength, knIPV4Endpoint destEnd);
|
|
||||||
|
|
||||||
/// receives one package from anywhere
|
|
||||||
///@param buffer buffer for receiving data
|
|
||||||
///@param bufferLength 0-64k
|
|
||||||
///@param senderEnd [OUT] endpoint UPD package was sent from
|
|
||||||
///@return Maybe<u64> received bytes amount
|
|
||||||
Maybe knSocketUDP_receiveAny(knSocketUDP* socket, char* buffer, u32 bufferLength, knIPV4Endpoint* senderEnd);
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -22,7 +22,7 @@ void complete_buf(StringBuilder* b){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void try_complete_buf(StringBuilder* b){
|
void try_complete_buf(StringBuilder* b){
|
||||||
if(b->curr_buf->blocks_count==BL_C)
|
if(b->curr_buf->chunks_count==BL_C)
|
||||||
complete_buf(b);
|
complete_buf(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ string StringBuilder_build(StringBuilder* b){
|
|||||||
|
|
||||||
|
|
||||||
void StringBuilder_rmchar(StringBuilder* b){
|
void StringBuilder_rmchar(StringBuilder* b){
|
||||||
if(b->curr_buf->block_length!=0)
|
if(b->curr_buf->chunk_length!=0)
|
||||||
Autoarr_pop(b->curr_buf)
|
Autoarr_pop(b->curr_buf)
|
||||||
else {
|
else {
|
||||||
if(!b->compl_bufs) throw(ERR_NULLPTR);
|
if(!b->compl_bufs) throw(ERR_NULLPTR);
|
||||||
@@ -139,6 +139,9 @@ 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];
|
||||||
ksprintf(buf,32,"%lf",a);
|
IFMSC(
|
||||||
|
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)});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ extern "C" {
|
|||||||
#include "type_system/type_system.h"
|
#include "type_system/type_system.h"
|
||||||
#include "../kprint/kprintf.h"
|
#include "../kprint/kprintf.h"
|
||||||
#include "endian.h"
|
#include "endian.h"
|
||||||
|
#include "memory/memory.h"
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ u32 cptr_length(const char* str){
|
|||||||
char* cptr_copy(const char* src){
|
char* cptr_copy(const char* src){
|
||||||
u32 len=cptr_length(src)+1;
|
u32 len=cptr_length(src)+1;
|
||||||
char* dst=malloc(len);
|
char* dst=malloc(len);
|
||||||
while(len--!=0)
|
memcpy(dst, src, len);
|
||||||
dst[len]=src[len];
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +152,7 @@ char* __cptr_concat(u32 n, ...){
|
|||||||
char* output=totality;
|
char* output=totality;
|
||||||
totality[totalLength]=0;
|
totality[totalLength]=0;
|
||||||
|
|
||||||
// copying content of all strings to result
|
// copying content of all strings to rezult
|
||||||
for(u16 k=0; k<n; k++){
|
for(u16 k=0; k<n; k++){
|
||||||
memcpy(totality, strs[k], lengths[k]);
|
memcpy(totality, strs[k], lengths[k]);
|
||||||
totality+=lengths[k];
|
totality+=lengths[k];
|
||||||
@@ -205,6 +204,6 @@ char* cptr_replaceIn(const char* src, const char* str_old, const char* str_new,
|
|||||||
u32 src_remains_len=cptr_length(src);
|
u32 src_remains_len=cptr_length(src);
|
||||||
if(src_remains_len>0)
|
if(src_remains_len>0)
|
||||||
StringBuilder_append_string(sb, (string){.ptr=(char*)src, .length=src_remains_len});
|
StringBuilder_append_string(sb, (string){.ptr=(char*)src, .length=src_remains_len});
|
||||||
string result=StringBuilder_build(sb);
|
string rezult=StringBuilder_build(sb);
|
||||||
return result.ptr;
|
return rezult.ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,11 +63,7 @@ static inline i32 cptr_lastIndexOfChar(const char* src, char fragment)
|
|||||||
|
|
||||||
|
|
||||||
static inline bool cptr_contains(const char* src, const char* fragment){
|
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;
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool cptr_containsChar(const char* src, char c){
|
|
||||||
return cptr_seekChar(src, c, 0, -1) != -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* __cptr_concat(u32 n, ...);
|
char* __cptr_concat(u32 n, ...);
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
#include "base.h"
|
#include "std.h"
|
||||||
|
#include "errors.h"
|
||||||
|
#include "cptr.h"
|
||||||
|
#include "../kprint/kprintf.h"
|
||||||
|
|
||||||
char* errname(ErrorId err){
|
char* errname(ErrorId err){
|
||||||
switch(err){
|
switch(err){
|
||||||
@@ -18,21 +21,27 @@ char* errname(ErrorId err){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ERRMSG_MAXLENGTH 4096
|
#define ERRMSG_MAXLENGTH 1024
|
||||||
|
|
||||||
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* result=malloc(bufsize);
|
char* rezult=malloc(bufsize);
|
||||||
ksprintf(result,bufsize,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg);
|
IFMSC(
|
||||||
return result;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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* result=malloc(bufsize);
|
char* rezult=malloc(bufsize);
|
||||||
ksprintf(result,bufsize,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname);
|
IFMSC(
|
||||||
|
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 result;
|
return rezult;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Maybe_free(Maybe e){
|
void Maybe_free(Maybe e){
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ char* __unknownErr( );
|
|||||||
__RETURN_EXCEPTION(((char*)__genErrMsg(E, __FILE__,__LINE__,__func__))); \
|
__RETURN_EXCEPTION(((char*)__genErrMsg(E, __FILE__,__LINE__,__func__))); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define try_cpp(_funcCall, _result, freeMem) Maybe _result=_funcCall; if(_result.errmsg){ \
|
#define try_cpp(_funcCall, _rezult, freeMem) Maybe _rezult=_funcCall; if(_rezult.errmsg){ \
|
||||||
freeMem; \
|
freeMem; \
|
||||||
_result.errmsg=__extendErrMsg(_result.errmsg, __FILE__,__LINE__,__func__); \
|
_rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__); \
|
||||||
return _result; \
|
return _rezult; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -73,17 +73,16 @@ char* __unknownErr( );
|
|||||||
__RETURN_EXCEPTION(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__))); \
|
__RETURN_EXCEPTION(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__))); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define try(_funcCall, _result, freeMem) Maybe _result=_funcCall; if(_result.errmsg){ \
|
#define try(_funcCall, _rezult, freeMem) Maybe _rezult=_funcCall; if(_rezult.errmsg){ \
|
||||||
freeMem; \
|
freeMem; \
|
||||||
_result.errmsg=__extendErrMsg(_result.errmsg, __FILE__,__LINE__,__func__); \
|
_rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__); \
|
||||||
return _result; \
|
return _rezult; \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define tryLast(_funcCall, _result, ON_EXIT) Maybe _result=_funcCall; if(_result.errmsg){ \
|
#define tryLast(_funcCall, _rezult, ON_EXIT) Maybe _rezult=_funcCall; if(_rezult.errmsg){ \
|
||||||
ON_EXIT; \
|
_rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__); \
|
||||||
_result.errmsg=__extendErrMsg(_result.errmsg, __FILE__,__LINE__,__func__); \
|
__EXIT(_rezult.errmsg); \
|
||||||
__EXIT(_result.errmsg); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
18
src/base/memory/CstdAllocator.c
Normal file
18
src/base/memory/CstdAllocator.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include "allocators_internal.h"
|
||||||
|
|
||||||
|
void* CstdAllocator_alloc(allocator_t* self, size_t size){
|
||||||
|
assert(size>0);
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CstdAllocator_free(allocator_t* self, void* ptr){
|
||||||
|
assert(ptr!=NULL);
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CstdAllocator_construct(CstdAllocator* self){
|
||||||
|
self->base.alloc_f=CstdAllocator_alloc;
|
||||||
|
self->base.free_f=CstdAllocator_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
kt_define(CstdAllocator, NULL, NULL);
|
||||||
84
src/base/memory/LinearAllocator.c
Normal file
84
src/base/memory/LinearAllocator.c
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include "allocators_internal.h"
|
||||||
|
|
||||||
|
#define chunks_per_allocation 16
|
||||||
|
#define default_chunk_size add_padding(1024)
|
||||||
|
#define chunk_alloc(SZ, OCCUPIED) (MemoryChunk){ .data=malloc(SZ), .size=SZ, .occupied_size=OCCUPIED }
|
||||||
|
#define curr_chunk (self->chunks+self->curr_chunk_i)
|
||||||
|
|
||||||
|
__attribute__ ((noinline)) void* ___alloc_realloc_chunk(LinearAllocator* self, size_t size){
|
||||||
|
free(curr_chunk->data);
|
||||||
|
*curr_chunk=chunk_alloc(size, size);
|
||||||
|
return curr_chunk->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((noinline)) void* __alloc_new_chunk(LinearAllocator* self, size_t size){
|
||||||
|
self->curr_chunk_i++;
|
||||||
|
// next chunk has been already allocated
|
||||||
|
if(self->curr_chunk_i < self->chunks_count)
|
||||||
|
return curr_chunk->data;
|
||||||
|
|
||||||
|
// self->chunks array is full
|
||||||
|
if(self->chunks_count == self->max_chunks_count){
|
||||||
|
self->max_chunks_count += chunks_per_allocation;
|
||||||
|
self->chunks = realloc(self->chunks, sizeof(MemoryChunk) * self->max_chunks_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
// new chunk allocation
|
||||||
|
self->chunks_count++;
|
||||||
|
size_t new_chunk_size=default_chunk_size > size ? size : default_chunk_size;
|
||||||
|
*curr_chunk=chunk_alloc(new_chunk_size, new_chunk_size);
|
||||||
|
return curr_chunk->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* LinearAllocator_alloc(allocator_t* _self, size_t size){
|
||||||
|
// assert(_self!=NULL);
|
||||||
|
// assert(size>0);
|
||||||
|
LinearAllocator* self = (LinearAllocator*)_self;
|
||||||
|
size=add_padding(size);
|
||||||
|
|
||||||
|
// aligned size can fit into the current chunk
|
||||||
|
if(curr_chunk->occupied_size + size <= curr_chunk->size){
|
||||||
|
void* data_ptr=curr_chunk->data + curr_chunk->occupied_size;
|
||||||
|
curr_chunk->occupied_size += size;
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
// reallocation of current chunk because it is clean
|
||||||
|
if(curr_chunk->occupied_size == 0){
|
||||||
|
// It is very unefficient operation.
|
||||||
|
// If it happens not only in the first chunk, code have to be refactored
|
||||||
|
assert(self->curr_chunk_i==0);
|
||||||
|
return ___alloc_realloc_chunk(self, size);
|
||||||
|
}
|
||||||
|
// creation of a new chunk
|
||||||
|
else {
|
||||||
|
return __alloc_new_chunk(self, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinearAllocator_free(allocator_t* _self, void* ptr){
|
||||||
|
// LinearAllocator can't free pointers
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinearAllocator_destruct(LinearAllocator* self){
|
||||||
|
// assert(_self!=NULL);
|
||||||
|
for(u16 chunk_i=0; chunk_i < self->chunks_count; chunk_i++){
|
||||||
|
free(self->chunks[chunk_i].data);
|
||||||
|
}
|
||||||
|
free(self->chunks);
|
||||||
|
self->chunks=NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinearAllocator_construct(LinearAllocator* self, size_t starting_size){
|
||||||
|
assert(self!=NULL);
|
||||||
|
assert(starting_size>0);
|
||||||
|
self->base.alloc_f=LinearAllocator_alloc;
|
||||||
|
self->base.free_f=LinearAllocator_free;
|
||||||
|
|
||||||
|
self->curr_chunk_i=0;
|
||||||
|
self->chunks_count=1;
|
||||||
|
self->max_chunks_count=chunks_per_allocation;
|
||||||
|
self->chunks=malloc(sizeof(*self->chunks) * chunks_per_allocation);
|
||||||
|
self->chunks[0]=chunk_alloc(starting_size, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
kt_define(LinearAllocator, (freeMembers_t)LinearAllocator_destruct, NULL)
|
||||||
58
src/base/memory/StackingAllocator.c
Normal file
58
src/base/memory/StackingAllocator.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "allocators_internal.h"
|
||||||
|
|
||||||
|
#define chunk_alloc(SZ) (MemoryChunk){ .data=malloc(SZ), .size=SZ, .occupied_size=0 }
|
||||||
|
#define linear self->base
|
||||||
|
#define curr_chunk (linear.chunks+linear.curr_chunk_i)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
size_t data_size;
|
||||||
|
} AllocationHeader;
|
||||||
|
|
||||||
|
void* StackingAllocator_alloc(allocator_t* _self, size_t size){
|
||||||
|
assert(_self!=NULL);
|
||||||
|
assert(size>0);
|
||||||
|
StackingAllocator* self = (StackingAllocator*)_self;
|
||||||
|
size=add_padding(size);
|
||||||
|
|
||||||
|
// allocates memory with header struct before data
|
||||||
|
AllocationHeader* header_ptr=LinearAllocator_alloc(_self, sizeof(AllocationHeader) + size);
|
||||||
|
void* data_ptr = (void*)header_ptr + sizeof(AllocationHeader);
|
||||||
|
header_ptr->data_size = size;
|
||||||
|
|
||||||
|
self->allocations_count++;
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StackingAllocator_free(allocator_t* _self, void* data_ptr){
|
||||||
|
assert(_self!=NULL);
|
||||||
|
assert(data_ptr!=NULL);
|
||||||
|
StackingAllocator* self = (StackingAllocator*)_self;
|
||||||
|
AllocationHeader* header_ptr = data_ptr - sizeof(AllocationHeader);
|
||||||
|
|
||||||
|
// chunk is empty
|
||||||
|
if(curr_chunk->occupied_size==0){
|
||||||
|
// isn't the first chunk
|
||||||
|
assert(linear.curr_chunk_i>0);
|
||||||
|
linear.curr_chunk_i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t allocation_size=header_ptr->data_size+sizeof(*header_ptr);
|
||||||
|
// data must fit in chunk
|
||||||
|
assert(allocation_size <= curr_chunk->occupied_size);
|
||||||
|
curr_chunk->occupied_size -= allocation_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StackingAllocator_destruct(StackingAllocator* self){
|
||||||
|
LinearAllocator_destruct(&self->base);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StackingAllocator_construct(StackingAllocator* self, size_t starting_size){
|
||||||
|
assert(self!=NULL);
|
||||||
|
assert(starting_size>0);
|
||||||
|
LinearAllocator_construct(&linear, starting_size);
|
||||||
|
linear.base.alloc_f=StackingAllocator_alloc;
|
||||||
|
linear.base.free_f=StackingAllocator_free;
|
||||||
|
self->allocations_count=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
kt_define(StackingAllocator, (freeMembers_t)StackingAllocator_destruct, NULL)
|
||||||
9
src/base/memory/allocators.c
Normal file
9
src/base/memory/allocators.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
void* allocator_transfer(allocator_t* src, allocator_t* dest, void* data, size_t data_size)
|
||||||
|
{
|
||||||
|
void* transfered=allocator_alloc(dest, data_size);
|
||||||
|
memcpy(transfered, data, data_size);
|
||||||
|
allocator_free(src, data);
|
||||||
|
return transfered;
|
||||||
|
}
|
||||||
91
src/base/memory/allocators.h
Normal file
91
src/base/memory/allocators.h
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../std.h"
|
||||||
|
#include "../type_system/ktDescriptor.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 //
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// Just wrapper for malloc() and free() //
|
||||||
|
///////////////////////////////////////////
|
||||||
|
|
||||||
|
STRUCT(CstdAllocator,
|
||||||
|
allocator_t base;
|
||||||
|
);
|
||||||
|
|
||||||
|
void CstdAllocator_construct(CstdAllocator* self);
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// LinearAllocator //
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// Can't free allocated memory. //
|
||||||
|
// Allocates new memory chunk when the //
|
||||||
|
// current is full. //
|
||||||
|
///////////////////////////////////////////
|
||||||
|
|
||||||
|
typedef struct MemoryChunk {
|
||||||
|
void* data;
|
||||||
|
size_t size;
|
||||||
|
size_t occupied_size; /* free memory position in the current chunk. */
|
||||||
|
} MemoryChunk;
|
||||||
|
|
||||||
|
STRUCT(LinearAllocator,
|
||||||
|
allocator_t base;
|
||||||
|
MemoryChunk* chunks; /* MemoryChunk[max_chunks_count] */
|
||||||
|
u16 chunks_count; /* allocated chunks */
|
||||||
|
u16 max_chunks_count; /* chunks that can be allocated without reallocating .chunks */
|
||||||
|
u16 curr_chunk_i; /* index of current chunk in .chunks, can be < .chunks_count */
|
||||||
|
);
|
||||||
|
|
||||||
|
void LinearAllocator_construct(LinearAllocator* self, size_t starting_size);
|
||||||
|
void LinearAllocator_destruct(LinearAllocator* self);
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// StackingAllocator //
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// The same as Linear, but can free //
|
||||||
|
// allocations in reverse order //
|
||||||
|
///////////////////////////////////////////
|
||||||
|
|
||||||
|
STRUCT(StackingAllocator,
|
||||||
|
LinearAllocator base;
|
||||||
|
u32 allocations_count;
|
||||||
|
);
|
||||||
|
|
||||||
|
void StackingAllocator_construct(StackingAllocator* self, size_t starting_size);
|
||||||
|
void StackingAllocator_destruct(StackingAllocator* self);
|
||||||
|
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
4
src/base/memory/allocators_internal.h
Normal file
4
src/base/memory/allocators_internal.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
void* LinearAllocator_alloc(allocator_t* _self, size_t size);
|
||||||
6
src/base/memory/memory.h
Normal file
6
src/base/memory/memory.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "allocators.h"
|
||||||
|
|
||||||
|
// addresses must be aligned to this value
|
||||||
|
#define memory_align sizeof(void*)
|
||||||
|
// adds padding if memory_align if N isn't a multiple of memory_aligh
|
||||||
|
#define add_padding(N) (N + (N%memory_align != 0)*(memory_align - N%memory_align))
|
||||||
@@ -14,7 +14,6 @@ extern "C" {
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
typedef int8_t i8;
|
typedef int8_t i8;
|
||||||
typedef uint8_t u8;
|
typedef uint8_t u8;
|
||||||
@@ -39,6 +38,10 @@ typedef u8 bool;
|
|||||||
#define false 0
|
#define false 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef memcpy
|
||||||
|
extern void* memcpy(void *dest, const void * src, size_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
#define dbg(N) kprintf("\e[95m%d\n",N)
|
#define dbg(N) kprintf("\e[95m%d\n",N)
|
||||||
|
|
||||||
#define nameof(V) #V
|
#define nameof(V) #V
|
||||||
|
|||||||
@@ -70,7 +70,10 @@ char* toString_u64(u64 n, bool withPostfix, bool uppercase){
|
|||||||
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 = sprintf_s(str, bufsize, "%.*f", precision, n); \
|
i32 cn=IFMSC( \
|
||||||
|
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--; \
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "../../Hashtable/Hashtable.h"
|
#include "../../Hashtable/Hashtable.h"
|
||||||
#include "../../String/StringBuilder.h"
|
#include "../../String/StringBuilder.h"
|
||||||
#include "../../Filesystem/filesystem.h"
|
#include "../../Filesystem/filesystem.h"
|
||||||
#include "../../Network/network.h"
|
|
||||||
#include "base_toString.h"
|
#include "base_toString.h"
|
||||||
|
|
||||||
void kt_initKerepTypes(){
|
void kt_initKerepTypes(){
|
||||||
@@ -83,13 +82,6 @@ void kt_initKerepTypes(){
|
|||||||
// StringBuilder
|
// StringBuilder
|
||||||
kt_register(StringBuilder);
|
kt_register(StringBuilder);
|
||||||
|
|
||||||
// File
|
//File
|
||||||
kt_register(FileHandle);
|
kt_register(FileHandle);
|
||||||
|
|
||||||
// Network
|
|
||||||
kt_register(knIPV4Address);
|
|
||||||
kt_register(knIPV4Endpoint);
|
|
||||||
kt_register(knSocketTCP);
|
|
||||||
kt_register(knSocketUDP);
|
|
||||||
kt_register(knSocketChanneled);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,14 +52,9 @@ ktid ktid_last=-1;
|
|||||||
ENUM(ktDescriptorsState,
|
ENUM(ktDescriptorsState,
|
||||||
NotInitialized, Initializing, Initialized
|
NotInitialized, Initializing, Initialized
|
||||||
)
|
)
|
||||||
|
|
||||||
ktDescriptorsState initState=NotInitialized;
|
ktDescriptorsState initState=NotInitialized;
|
||||||
|
|
||||||
bool _printDebugMessages = false;
|
void kt_beginInit(){
|
||||||
|
|
||||||
void kt_beginInit(bool printDebugMessages){
|
|
||||||
_printDebugMessages = printDebugMessages;
|
|
||||||
if(printDebugMessages)
|
|
||||||
kprintf("\e[94mtype descriptors initializing...\n");
|
kprintf("\e[94mtype descriptors initializing...\n");
|
||||||
__descriptorPointers=Autoarr_create(Pointer, 256, 256);
|
__descriptorPointers=Autoarr_create(Pointer, 256, 256);
|
||||||
}
|
}
|
||||||
@@ -70,7 +65,6 @@ void kt_endInit(){
|
|||||||
typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers);
|
typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers);
|
||||||
Autoarr_free(__descriptorPointers,true);
|
Autoarr_free(__descriptorPointers,true);
|
||||||
if(typeDescriptors==NULL) throw(ERR_NULLPTR);
|
if(typeDescriptors==NULL) throw(ERR_NULLPTR);
|
||||||
if(_printDebugMessages)
|
|
||||||
kprintf("\e[92minitialized %u type descriptors\n", ktid_last);
|
kprintf("\e[92minitialized %u type descriptors\n", ktid_last);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,9 +74,10 @@ void __kt_register(ktDescriptor* descriptor){
|
|||||||
}
|
}
|
||||||
|
|
||||||
ktDescriptor* ktDescriptor_get(ktid id){
|
ktDescriptor* ktDescriptor_get(ktid id){
|
||||||
if(id>ktid_last || id==ktid_undefined)
|
if(id>ktid_last || id==ktid_undefined) {
|
||||||
throw(cptr_concat("invalid type id ", toString_i64(id)));
|
kprintf("\ntype id: %u\n",id);
|
||||||
|
throw("invalid type id");
|
||||||
|
}
|
||||||
return typeDescriptors[id];
|
return typeDescriptors[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ void __kt_register(ktDescriptor* descriptor);
|
|||||||
__kt_register(&ktDescriptor_##TYPE##_Ptr); \
|
__kt_register(&ktDescriptor_##TYPE##_Ptr); \
|
||||||
ktid_##TYPE##_Ptr=ktid_last;
|
ktid_##TYPE##_Ptr=ktid_last;
|
||||||
|
|
||||||
void kt_beginInit(bool printDebugMessages);
|
void kt_beginInit();
|
||||||
void kt_endInit();
|
void kt_endInit();
|
||||||
|
|
||||||
/// @param id id of registered type
|
/// @param id id of registered type
|
||||||
|
|||||||
@@ -85,11 +85,11 @@ char *Unitype_toString(Unitype u, u32 fmt)
|
|||||||
valuestr = type->toString(u.VoidPtr, fmt);
|
valuestr = type->toString(u.VoidPtr, fmt);
|
||||||
else
|
else
|
||||||
valuestr = "ERR_NO_TOSTRING_FUNC";
|
valuestr = "ERR_NO_TOSTRING_FUNC";
|
||||||
char *result = cptr_concat("{ type: ", type->name, ", allocated on heap: ", (u.allocatedInHeap ? "true" : "false"),
|
char *rezult = cptr_concat("{ type: ", type->name, ", allocated on heap: ", (u.allocatedInHeap ? "true" : "false"),
|
||||||
", value:", valuestr, " }");
|
", value:", valuestr, " }");
|
||||||
if (type->toString)
|
if (type->toString)
|
||||||
free(valuestr);
|
free(valuestr);
|
||||||
return result;
|
return rezult;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printuni(Unitype v)
|
void printuni(Unitype v)
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ Maybe __next_toString(kp_fmt f, void* object){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Maybe check_argsN(u8 n){
|
Maybe check_argsN(u8 n){
|
||||||
if(n%2 != 0) safethrow("kprint received non-even number of arguments",;);
|
if(n%2 != 0) safethrow("kprint recieved non-even number of arguments",;);
|
||||||
if(n > 32) safethrow("kprint received >32 number of arguments",;);
|
if(n > 32) safethrow("kprint recieved >32 number of arguments",;);
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,8 +53,8 @@ Maybe __ksprint(u8 n, kp_fmt* formats, __kp_value_union* objects){
|
|||||||
StringBuilder_append_cptr(strb, mStr.value.VoidPtr);
|
StringBuilder_append_cptr(strb, mStr.value.VoidPtr);
|
||||||
Unitype_free(mStr.value);
|
Unitype_free(mStr.value);
|
||||||
}
|
}
|
||||||
char* result=StringBuilder_build(strb).ptr;
|
char* rezult=StringBuilder_build(strb).ptr;
|
||||||
return SUCCESS(UniHeapPtr(char, result));
|
return SUCCESS(UniHeapPtr(char, rezult));
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
||||||
@@ -90,6 +90,7 @@ void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){
|
|||||||
#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);
|
||||||
switch(f){
|
switch(f){
|
||||||
case kp_fgBlack: return 0;
|
case kp_fgBlack: return 0;
|
||||||
case kp_fgRedD: return FOREGROUND_RED;
|
case kp_fgRedD: return FOREGROUND_RED;
|
||||||
@@ -112,6 +113,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);
|
||||||
switch(f){
|
switch(f){
|
||||||
case kp_bgBlack: return 0;
|
case kp_bgBlack: return 0;
|
||||||
case kp_bgRedD: return BACKGROUND_RED;
|
case kp_bgRedD: return BACKGROUND_RED;
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../base/type_system/typedef_macros.h"
|
|
||||||
|
|
||||||
// 10000000 00000000 00000000 00000000
|
// 10000000 00000000 00000000 00000000
|
||||||
// ^ ^^^^
|
// ^ ^^^^
|
||||||
// | color num
|
// | color num
|
||||||
|
|||||||
@@ -45,90 +45,91 @@ WORD unixColorToWin(u8 c){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
i32 _kprintf(const char* format, const i32 args_count, ...){
|
void kprintf(const char* format, ...){
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, args_count);
|
va_start(vl, format);
|
||||||
i32 i = 0;
|
u32 i=0;
|
||||||
i32 args_left = args_count;
|
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=='%'){
|
||||||
if(args_left-- == 0)
|
char* argstr=NULL;
|
||||||
return kprintf_NOT_ENOUGH_ARGUMENTS;
|
bool l=false;
|
||||||
|
c=format[i++];
|
||||||
char* argstr = NULL;
|
|
||||||
bool l = false;
|
|
||||||
c = format[i++];
|
|
||||||
format_escape_seq:
|
format_escape_seq:
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'u':
|
case 'u':
|
||||||
argstr = toString_u64(
|
argstr=toString_u64(
|
||||||
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(
|
||||||
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(va_arg(vl, f64), toString_float_default_precision,0,0);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
l = true;
|
l=true;
|
||||||
if((c = format[i++]))
|
if((c=format[i++]))
|
||||||
goto format_escape_seq;
|
goto format_escape_seq;
|
||||||
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(&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(&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(&xhex,getEndian()==LittleEndian,sizeof(xhex),0,1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's': ;
|
case 's': ;
|
||||||
char* cptr = va_arg(vl,char*);
|
char* cptr=va_arg(vl,char*);
|
||||||
if(!cptr)
|
if(!cptr)
|
||||||
cptr = "<nullstr>";
|
cptr="<nullstr>";
|
||||||
if(*cptr)
|
if(*cptr)
|
||||||
fputs(cptr, stdout);
|
fputs(cptr, stdout);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
putc((char)va_arg(vl,int), stdout);
|
argstr=malloc(2);
|
||||||
|
argstr[0]=(char)va_arg(vl,int);
|
||||||
|
argstr[1]=0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fputs("<INCORRECT FORMAT STRING>", stdout);
|
putc('\n',stdout);
|
||||||
return kprintf_INVALID_FORMAT;
|
putc('<',stdout);
|
||||||
|
putc(c,stdout);
|
||||||
|
putc('>',stdout);
|
||||||
|
throw(ERR_FORMAT);
|
||||||
}
|
}
|
||||||
if(argstr){
|
if(argstr){
|
||||||
fputs(argstr, stdout);
|
fputs(argstr, stdout);
|
||||||
free(argstr);
|
free(argstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// escape sequences
|
// escape sequences
|
||||||
else if(c == '\e'){
|
else if(c=='\e'){
|
||||||
//////////////////// WINDOWS ////////////////////
|
IFWIN(
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
/* WINDOWS */
|
||||||
if((c = format[i++]) == '['){
|
({
|
||||||
u8 colorUnix = 0;
|
if((c=format[i++])=='['){
|
||||||
for(i8 n = 0; n<6 && c != 0; n++){
|
u8 colorUnix=0;
|
||||||
c = format[i++];
|
for(i8 n=0; n<6 && c!=0; n++){
|
||||||
|
c=format[i++];
|
||||||
switch (c){
|
switch (c){
|
||||||
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':
|
||||||
colorUnix = colorUnix*10+c-'0';
|
colorUnix=colorUnix*10+c-'0';
|
||||||
break;
|
break;
|
||||||
case 'm': ;
|
case 'm': ;
|
||||||
WORD colorWin = unixColorToWin(colorUnix);
|
WORD colorWin=unixColorToWin(colorUnix);
|
||||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
SetConsoleTextAttribute(hConsole, colorWin);
|
SetConsoleTextAttribute(hConsole, colorWin);
|
||||||
goto end_iteration;
|
goto end_iteration;
|
||||||
@@ -137,12 +138,11 @@ i32 _kprintf(const char* format, const i32 args_count, ...){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
////////////////////// UNIX //////////////////////
|
}),
|
||||||
#else
|
/* UNIX */
|
||||||
putc(c,stdout);
|
putc(c,stdout);
|
||||||
#endif
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// common characters
|
// common characters
|
||||||
else {
|
else {
|
||||||
putc(c,stdout);
|
putc(c,stdout);
|
||||||
@@ -152,112 +152,4 @@ i32 _kprintf(const char* format, const i32 args_count, ...){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
va_end(vl);
|
va_end(vl);
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
i32 _ksprintf(char* buffer, i32 buffer_size, const char* format, const i32 args_count, ...){
|
|
||||||
if(buffer == NULL)
|
|
||||||
return kprintf_BUFFER_IS_NULL;
|
|
||||||
|
|
||||||
va_list vl;
|
|
||||||
va_start(vl, args_count);
|
|
||||||
i32 i = 0;
|
|
||||||
i32 written = 0;
|
|
||||||
i32 args_left = args_count;
|
|
||||||
for(char c = format[i++]; c != 0; c = format[i++]){
|
|
||||||
// value format specifiers
|
|
||||||
if(c == '%'){
|
|
||||||
if(args_left-- == 0)
|
|
||||||
return kprintf_NOT_ENOUGH_ARGUMENTS;
|
|
||||||
|
|
||||||
char* argstr = NULL;
|
|
||||||
bool l = false;
|
|
||||||
c = format[i++];
|
|
||||||
format_escape_seq:
|
|
||||||
switch (c) {
|
|
||||||
case 'u':
|
|
||||||
argstr = toString_u64(
|
|
||||||
l ? va_arg(vl, u64) : va_arg(vl, u32)
|
|
||||||
,0,0);
|
|
||||||
break;
|
|
||||||
case 'i': case 'd':
|
|
||||||
argstr = toString_i64(
|
|
||||||
l ? va_arg(vl, i64) : va_arg(vl, i32)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
// f32 is promoted to f64 when passed through '...'
|
|
||||||
argstr = toString_f64(va_arg(vl, f64), toString_float_default_precision,0,0);
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
l = true;
|
|
||||||
if((c = format[i++]))
|
|
||||||
goto format_escape_seq;
|
|
||||||
break;
|
|
||||||
case 'p': ;
|
|
||||||
void* phex = va_arg(vl, void*);
|
|
||||||
argstr = toString_hex(&phex,getEndian() == LittleEndian,sizeof(phex),1,0);
|
|
||||||
break;
|
|
||||||
case 'x': ;
|
|
||||||
if(l){
|
|
||||||
u64 xhex = va_arg(vl, u64);
|
|
||||||
argstr = toString_hex(&xhex,getEndian() == LittleEndian,sizeof(xhex),0,1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
u32 xhex = va_arg(vl, u32);
|
|
||||||
argstr = toString_hex(&xhex,getEndian() == LittleEndian,sizeof(xhex),0,1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 's': ;
|
|
||||||
char* cptr = va_arg(vl,char*);
|
|
||||||
if(!cptr)
|
|
||||||
cptr = "<nullstr>";
|
|
||||||
if(*cptr){
|
|
||||||
i32 str_length = cptr_length(cptr);
|
|
||||||
if(written + str_length > buffer_size)
|
|
||||||
return kprintf_BUFFER_IS_TOO_SMALL;
|
|
||||||
|
|
||||||
memcpy(buffer + written, cptr, str_length);
|
|
||||||
written += str_length;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'c': ;
|
|
||||||
char ch = (char)va_arg(vl,int);
|
|
||||||
if(written > buffer_size)
|
|
||||||
return kprintf_BUFFER_IS_TOO_SMALL;
|
|
||||||
|
|
||||||
buffer[written++] = ch;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
const char errformat_str[] = "<INCORRECT FORMAT STRING>";
|
|
||||||
if(written + (i32)sizeof(errformat_str) <= buffer_size)
|
|
||||||
memcpy(buffer + written, errformat_str, sizeof(errformat_str));
|
|
||||||
return kprintf_INVALID_FORMAT;
|
|
||||||
}
|
|
||||||
if(argstr){
|
|
||||||
i32 str_length = cptr_length(argstr);
|
|
||||||
if(written + str_length > buffer_size)
|
|
||||||
return kprintf_BUFFER_IS_TOO_SMALL;
|
|
||||||
|
|
||||||
memcpy(buffer + written, argstr, str_length);
|
|
||||||
written += str_length;
|
|
||||||
free(argstr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// common characters
|
|
||||||
else {
|
|
||||||
if(written > buffer_size)
|
|
||||||
return kprintf_BUFFER_IS_TOO_SMALL;
|
|
||||||
|
|
||||||
buffer[written++] = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(vl);
|
|
||||||
if(written > buffer_size)
|
|
||||||
return kprintf_BUFFER_IS_TOO_SMALL;
|
|
||||||
buffer[written] = '\0';
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,63 +6,8 @@ extern "C" {
|
|||||||
|
|
||||||
#include "../base/type_system/base_toString.h"
|
#include "../base/type_system/base_toString.h"
|
||||||
|
|
||||||
#define kprintf_INVALID_FORMAT -1
|
// cross-platform printf analog
|
||||||
#define kprintf_NOT_ENOUGH_ARGUMENTS -2
|
void kprintf(const char* format, ...);
|
||||||
#define kprintf_BUFFER_IS_TOO_SMALL -3
|
|
||||||
#define kprintf_BUFFER_IS_NULL -4
|
|
||||||
|
|
||||||
/// cross-platform printf analog
|
|
||||||
///@return number of processed format string characters or error code
|
|
||||||
i32 _kprintf(const char* format, const i32 args_count, ...);
|
|
||||||
#define kprintf(FORMAT, ARGS... ) _kprintf(FORMAT, count_args(ARGS) ,##ARGS)
|
|
||||||
|
|
||||||
/// @return number of processed format string characters or error code
|
|
||||||
i32 _ksprintf(char* buffer, i32 buffer_size, const char* format, const i32 args_count, ...);
|
|
||||||
#define ksprintf(BUFFER, BUFFER_SIZE, FORMAT, ARGS... ) _ksprintf(BUFFER, BUFFER_SIZE, FORMAT, count_args(ARGS) ,##ARGS)
|
|
||||||
|
|
||||||
|
|
||||||
// printf format terminal color sequence
|
|
||||||
#define _PRINTF_COLOR(N) "\e["#N"m"
|
|
||||||
|
|
||||||
// foreground dark color codes
|
|
||||||
#define FBLK _PRINTF_COLOR(30)
|
|
||||||
#define FREDD _PRINTF_COLOR(31)
|
|
||||||
#define FGRND _PRINTF_COLOR(32)
|
|
||||||
#define FYELD _PRINTF_COLOR(33)
|
|
||||||
#define FBLUD _PRINTF_COLOR(34)
|
|
||||||
#define FMAGD _PRINTF_COLOR(35)
|
|
||||||
#define FCYND _PRINTF_COLOR(36)
|
|
||||||
#define FGRY _PRINTF_COLOR(37)
|
|
||||||
|
|
||||||
// foreground bright color codes
|
|
||||||
#define FGRYD _PRINTF_COLOR(90)
|
|
||||||
#define FRED _PRINTF_COLOR(91)
|
|
||||||
#define FGRN _PRINTF_COLOR(92)
|
|
||||||
#define FYEL _PRINTF_COLOR(93)
|
|
||||||
#define FBLU _PRINTF_COLOR(94)
|
|
||||||
#define FMAG _PRINTF_COLOR(95)
|
|
||||||
#define FCYN _PRINTF_COLOR(96)
|
|
||||||
#define FWHI _PRINTF_COLOR(97)
|
|
||||||
|
|
||||||
// background dark color codes
|
|
||||||
#define BBLK _PRINTF_COLOR(40)
|
|
||||||
#define BREDD _PRINTF_COLOR(41)
|
|
||||||
#define BGRND _PRINTF_COLOR(42)
|
|
||||||
#define BYELD _PRINTF_COLOR(43)
|
|
||||||
#define BBLUD _PRINTF_COLOR(44)
|
|
||||||
#define BMAGD _PRINTF_COLOR(45)
|
|
||||||
#define BCYND _PRINTF_COLOR(46)
|
|
||||||
#define BGRY _PRINTF_COLOR(47)
|
|
||||||
|
|
||||||
// background bright color codes
|
|
||||||
#define BGRYD _PRINTF_COLOR(100)
|
|
||||||
#define BRED _PRINTF_COLOR(101)
|
|
||||||
#define BGRN _PRINTF_COLOR(102)
|
|
||||||
#define BYEL _PRINTF_COLOR(103)
|
|
||||||
#define BBLU _PRINTF_COLOR(104)
|
|
||||||
#define BMAG _PRINTF_COLOR(105)
|
|
||||||
#define BCYN _PRINTF_COLOR(106)
|
|
||||||
#define BWHI _PRINTF_COLOR(107)
|
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ static inline i32 krand_next32(krand_statePtr state, i32 from, i32 to) __krand_n
|
|||||||
static inline i64 krand_next64(krand_statePtr state, i64 from, i64 to) __krand_next_definition(64)
|
static inline i64 krand_next64(krand_statePtr state, i64 from, i64 to) __krand_next_definition(64)
|
||||||
|
|
||||||
// divides random number by 2^64 to return a value between 0 and 1
|
// divides random number by 2^64 to return a value between 0 and 1
|
||||||
static inline f32 krand_nextFloat32(krand_statePtr state) {return (f32)KRAND_ALG32_next(state) / (u32)(-1); }
|
static inline f32 krand_nextFloat32(krand_statePtr state) {return (u32)KRAND_ALG32_next(state)/0xffffffff; }
|
||||||
static inline f64 krand_nextFloat64(krand_statePtr state) {return (f64)KRAND_ALG64_next(state) / (u64)(-1); }
|
static inline f64 krand_nextFloat64(krand_statePtr state) {return KRAND_ALG64_next(state)/0xffffffff; }
|
||||||
|
|
||||||
|
|
||||||
///@param chance (0-1.0) is probability of success
|
///@param chance (0-1.0) is probability of success
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
// posix version definition to use clock_gettime
|
|
||||||
#ifndef _XOPEN_SOURCE
|
|
||||||
#if __STDC_VERSION__ >= 199901L
|
|
||||||
#define _XOPEN_SOURCE 600
|
|
||||||
#else
|
|
||||||
#define _XOPEN_SOURCE 500
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "time.h"
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define K 1000
|
|
||||||
#define M 1000000
|
|
||||||
#define G 1000000000
|
|
||||||
|
|
||||||
nsec_t getTimeNsec(){
|
|
||||||
struct timespec t;
|
|
||||||
if(clock_gettime(CLOCK_REALTIME, &t) != 0)
|
|
||||||
throw(ERR_UNEXPECTEDVAL);
|
|
||||||
u64 n = t.tv_sec * G + t.tv_nsec;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
usec_t getTimeUsec(){
|
|
||||||
struct timespec t;
|
|
||||||
if(clock_gettime(CLOCK_REALTIME, &t) != 0)
|
|
||||||
throw(ERR_UNEXPECTEDVAL);
|
|
||||||
u64 n = t.tv_sec * M + t.tv_nsec / K;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleepNsec(nsec_t time){
|
|
||||||
struct timespec t = {
|
|
||||||
.tv_sec = time / G,
|
|
||||||
.tv_nsec = time % G
|
|
||||||
};
|
|
||||||
if(nanosleep(&t, NULL) != 0)
|
|
||||||
throw(ERR_UNEXPECTEDVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleepUsec(usec_t time){
|
|
||||||
sleepNsec(time * K);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleepMsec(msec_t time){
|
|
||||||
sleepNsec(time * M);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../base/base.h"
|
|
||||||
|
|
||||||
/// nanoseconds
|
|
||||||
typedef u64 nsec_t;
|
|
||||||
/// microseconds
|
|
||||||
typedef u64 usec_t;
|
|
||||||
/// miliseconds
|
|
||||||
typedef u64 msec_t;
|
|
||||||
|
|
||||||
/// system time now in nanoseconds
|
|
||||||
///@return u64 will overflow in 13 years
|
|
||||||
nsec_t getTimeNsec();
|
|
||||||
|
|
||||||
/// system time now in microseconds
|
|
||||||
///@return u64 will overflow in 58494 years
|
|
||||||
usec_t getTimeUsec();
|
|
||||||
|
|
||||||
void sleepNsec(nsec_t time);
|
|
||||||
void sleepUsec(usec_t time);
|
|
||||||
void sleepMsec(msec_t time);
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -3,11 +3,11 @@
|
|||||||
i32 main(){
|
i32 main(){
|
||||||
if(setlocale(LC_CTYPE, "C.UTF-8")!=0)
|
if(setlocale(LC_CTYPE, "C.UTF-8")!=0)
|
||||||
kprintf("\e[93msetlocale failed\n");
|
kprintf("\e[93msetlocale failed\n");
|
||||||
kt_beginInit(true);
|
kt_beginInit();
|
||||||
kt_initKerepTypes();
|
kt_initKerepTypes();
|
||||||
kt_endInit();
|
kt_endInit();
|
||||||
test_all();
|
test_all();
|
||||||
kt_free();
|
kt_free();
|
||||||
kprintf("\e[37m\n");
|
kprintf("\e[0m\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
47
tests/test_allocators.c
Normal file
47
tests/test_allocators.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include "tests.h"
|
||||||
|
|
||||||
|
void _test_allocator(allocator_t* al){
|
||||||
|
void* ptr=allocator_alloc(al, 1);
|
||||||
|
allocator_free(al, ptr);
|
||||||
|
ptr=allocator_alloc(al, 5);
|
||||||
|
allocator_free(al, ptr);
|
||||||
|
ptr=allocator_alloc(al, 41);
|
||||||
|
allocator_free(al, ptr);
|
||||||
|
ptr=allocator_alloc(al, 19);
|
||||||
|
void* ptr1=allocator_alloc(al, 1);
|
||||||
|
void* ptr2=allocator_alloc(al, 5);
|
||||||
|
// allocator_free(al, ptr); // temp case
|
||||||
|
allocator_free(al, ptr2);
|
||||||
|
allocator_free(al, ptr1);
|
||||||
|
allocator_free(al, ptr);
|
||||||
|
ptr=allocator_alloc(al, 500);
|
||||||
|
ptr1=allocator_alloc(al, 1025);
|
||||||
|
allocator_free(al, ptr1);
|
||||||
|
allocator_free(al, ptr);/*
|
||||||
|
ptr=allocator_alloc(al, 5000);
|
||||||
|
ptr1=allocator_alloc(al, 5000000);
|
||||||
|
allocator_free(al, ptr1);
|
||||||
|
allocator_free(al, ptr);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_allocators(){
|
||||||
|
kprintf("\e[96m----------[test_allocators]-----------\n");
|
||||||
|
optime("test CstdAllocator", 10000,
|
||||||
|
CstdAllocator al;
|
||||||
|
CstdAllocator_construct(&al);
|
||||||
|
_test_allocator((allocator_t*)&al);
|
||||||
|
);
|
||||||
|
optime("test LinearAllocator", 10000,
|
||||||
|
LinearAllocator al;
|
||||||
|
LinearAllocator_construct(&al, 4096);
|
||||||
|
_test_allocator((allocator_t*)&al);
|
||||||
|
LinearAllocator_destruct(&al);
|
||||||
|
);
|
||||||
|
optime("test StackingAllocator", 10000,
|
||||||
|
StackingAllocator al;
|
||||||
|
StackingAllocator_construct(&al, 4096);
|
||||||
|
_test_allocator((allocator_t*)&al);
|
||||||
|
StackingAllocator_destruct(&al);
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
#include "../src/Autoarr/Autoarr.h"
|
#include "../src/Autoarr/Autoarr.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
i64 _autoarrVsVector(u16 blockCount, u16 blockLength){
|
i64 _autoarrVsVector(u16 chunkCount, u16 chunkLength){
|
||||||
u32 count=blockLength*blockCount;
|
u32 count=chunkLength*chunkCount;
|
||||||
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (u64)count);
|
kprintf("\e[94mchunk count: %u chunk length: %u count: " IFWIN("%llu", "%lu") "\n", chunkCount, chunkLength, (u64)count);
|
||||||
Autoarr_i64* ar=Autoarr_create(i64, blockCount, blockLength);
|
Autoarr_i64* ar=Autoarr_create(i64, chunkCount, chunkLength);
|
||||||
std::vector<i64> vec=std::vector<i64>();
|
std::vector<i64> vec=std::vector<i64>();
|
||||||
optime("Autoarr_add", count,
|
optime("Autoarr_add", count,
|
||||||
Autoarr_add(ar, op_i));
|
Autoarr_add(ar, op_i));
|
||||||
|
|||||||
@@ -4,17 +4,17 @@
|
|||||||
static void printautoarr(Autoarr(u16)* ar){
|
static void printautoarr(Autoarr(u16)* ar){
|
||||||
kprintf("\e[94mAutoarr(u16): "
|
kprintf("\e[94mAutoarr(u16): "
|
||||||
IFWIN("%llu", "%lu")
|
IFWIN("%llu", "%lu")
|
||||||
"\n max_blocks_count: %u\n"
|
"\n max_chunks_count: %u\n"
|
||||||
" blocks_count: %u\n"
|
" chunks_count: %u\n"
|
||||||
" max_block_length: %u\n"
|
" max_chunk_length: %u\n"
|
||||||
" block_length: %u\n"
|
" chunk_length: %u\n"
|
||||||
" max_length: %u\n"
|
" max_length: %u\n"
|
||||||
" length: %u\n",
|
" length: %u\n",
|
||||||
sizeof(Autoarr(u16)),
|
sizeof(Autoarr(u16)),
|
||||||
ar->max_blocks_count,
|
ar->max_chunks_count,
|
||||||
ar->blocks_count,
|
ar->chunks_count,
|
||||||
ar->max_block_length,
|
ar->max_chunk_length,
|
||||||
ar->block_length,
|
ar->chunk_length,
|
||||||
Autoarr_max_length(ar),
|
Autoarr_max_length(ar),
|
||||||
Autoarr_length(ar));
|
Autoarr_length(ar));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ void printrowgraph(Hashtable* ht){
|
|||||||
|
|
||||||
char* genkey(u32 i){
|
char* genkey(u32 i){
|
||||||
char* key=malloc(12);
|
char* key=malloc(12);
|
||||||
ksprintf(key,12,"key_%u",i);
|
IFMSC(
|
||||||
|
sprintf_s(key,12,"key_%u",i),
|
||||||
|
sprintf(key,"key_%u",i)
|
||||||
|
);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ void test_kprint(){
|
|||||||
//int
|
//int
|
||||||
kprint(kp_fgCyan|
|
kprint(kp_fgCyan|
|
||||||
kp_i,-8888, kp_c,' ', kp_i,0, kp_c,' ', kp_i,1234567890987654321LL,kp_s,"\n");
|
kp_i,-8888, kp_c,' ', kp_i,0, kp_c,' ', kp_i,1234567890987654321LL,kp_s,"\n");
|
||||||
//uint
|
//u
|
||||||
kprint(kp_fgGreen|
|
kprint(kp_fgGreen|
|
||||||
kp_u|kp_post,-8888, kp_c|kp_post|kp_upper,' ', kp_u,0, kp_c,' ',
|
kp_u|kp_post,-8888, kp_c|kp_post|kp_upper,' ', kp_u,0, kp_c,' ',
|
||||||
kp_u,1234567890987654321LL, kp_c,'\n');
|
kp_u,1234567890987654321LL, kp_c,'\n');
|
||||||
@@ -15,7 +15,7 @@ void test_kprint(){
|
|||||||
kp_f,-1.0f, kp_c,' ', kp_f,0.0f, kp_c,' ', kp_f,1.0f, kp_c,'\n',
|
kp_f,-1.0f, kp_c,' ', kp_f,0.0f, kp_c,' ', kp_f,1.0f, kp_c,'\n',
|
||||||
kp_f|kp_post,0.000020004f, kp_c,' ',
|
kp_f|kp_post,0.000020004f, kp_c,' ',
|
||||||
kp_f|kp_post|kp_upper,4000.0109f, kp_c,'\n');
|
kp_f|kp_post|kp_upper,4000.0109f, kp_c,'\n');
|
||||||
//double
|
//f64
|
||||||
kprint(kp_fgYellowD|
|
kprint(kp_fgYellowD|
|
||||||
kp_f,-4000.0109, kp_c,' ', kp_f,-0.000020004, kp_c,'\n',
|
kp_f,-4000.0109, kp_c,' ', kp_f,-0.000020004, kp_c,'\n',
|
||||||
kp_f,-1.0, kp_c,' ', kp_f,0.0, kp_c,' ', kp_f,1.0, kp_c,'\n',
|
kp_f,-1.0, kp_c,' ', kp_f,0.0, kp_c,' ', kp_f,1.0, kp_c,'\n',
|
||||||
|
|||||||
@@ -1,240 +0,0 @@
|
|||||||
#include "tests.h"
|
|
||||||
#include "../src/Network/network.h"
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
static void __test_knIPV4Address_fromStr(char* addrStr, u8 a, u8 b, u8 c, u8 d){
|
|
||||||
knIPV4Address addr;
|
|
||||||
tryLast(knIPV4Address_fromStr(addrStr, &addr), maybeAddr, ;)
|
|
||||||
kprintf("\e[92mknIPV4Address_fromStr(\e[96m%s\e[92m) -> ", addrStr);
|
|
||||||
if(addr.UintBigEndian != knIPV4Address_fromBytes(a,b,c,d).UintBigEndian){
|
|
||||||
kprintf("\e[91m%u.%u.%u.%u\n",
|
|
||||||
(u8)addr.bytes[0], (u8)addr.bytes[1], (u8)addr.bytes[2], (u8)addr.bytes[3]);
|
|
||||||
throw("knIPV4Address_fromStr returned wrong value");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
kprintf("\e[94m%u.%u.%u.%u\n",
|
|
||||||
(u8)addr.bytes[0], (u8)addr.bytes[1], (u8)addr.bytes[2], (u8)addr.bytes[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#define test_knIPV4Address_fromStr(a,b,c,d) __test_knIPV4Address_fromStr(#a"."#b"."#c"."#d, a,b,c,d)
|
|
||||||
|
|
||||||
static void test_network_types(){
|
|
||||||
PRINT_SIZEOF(knIPV4Address);
|
|
||||||
PRINT_SIZEOF(knPort);
|
|
||||||
PRINT_SIZEOF(knIPV4Endpoint);
|
|
||||||
PRINT_SIZEOF(knSocketTCP);
|
|
||||||
PRINT_SIZEOF(knSocketUDP);
|
|
||||||
PRINT_SIZEOF(knPackage);
|
|
||||||
PRINT_SIZEOF(knChannel);
|
|
||||||
|
|
||||||
test_knIPV4Address_fromStr(127,0,0,1);
|
|
||||||
test_knIPV4Address_fromStr(34,255,45,0);
|
|
||||||
test_knIPV4Address_fromStr(3,3,3,128);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
static pthread_mutex_t stdout_mutex = {0};
|
|
||||||
|
|
||||||
// thread-safe print
|
|
||||||
#define kprintf_safe(ARGS...) pthread_mutex_lock(&stdout_mutex); kprintf(ARGS); fflush(stdout); pthread_mutex_unlock(&stdout_mutex);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
knSocketTCP* socket_client;
|
|
||||||
knIPV4Endpoint serverEnd;
|
|
||||||
} tcp_client_connect_async_data;
|
|
||||||
|
|
||||||
void* tcp_client_connect_async(void* _data){
|
|
||||||
tcp_client_connect_async_data* data = _data;
|
|
||||||
tryLast(knSocketTCP_connect(data->socket_client, data->serverEnd), _m8531,;);
|
|
||||||
kprintf_safe("\e[92mclient socket connected to server\n");
|
|
||||||
|
|
||||||
char* adrstr = knIPV4Endpoint_toString(data->socket_client->localEndpoint);
|
|
||||||
kprintf("\e[92mclient socket was implicitely bound to %s\n\e[94m", adrstr);
|
|
||||||
free(adrstr);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_tcp(){
|
|
||||||
kprintf("\e[96m----------[test_network/tcp]----------\n");
|
|
||||||
knIPV4Endpoint serverEnd = knIPV4Endpoint_create(knIPV4Address_LOOPBACK, 4444);
|
|
||||||
knSocketTCP *socket_server, *clientConnection, *socket_client;
|
|
||||||
// server
|
|
||||||
{
|
|
||||||
tryLast(knSocketTCP_open(true), m_socketS, ;);
|
|
||||||
socket_server=m_socketS.value.VoidPtr;
|
|
||||||
kprintf("\e[92mTCP server socket created\n");
|
|
||||||
|
|
||||||
tryLast(knSocketTCP_bind(socket_server, serverEnd), _m81775, ;)
|
|
||||||
tryLast(knSocketTCP_listen(socket_server), _m88775, ;)
|
|
||||||
kprintf("\e[92mserver socket is listening\n");
|
|
||||||
}
|
|
||||||
// client
|
|
||||||
{
|
|
||||||
tryLast(knSocketTCP_open(false), m_socketC, ;);
|
|
||||||
socket_client=m_socketC.value.VoidPtr;
|
|
||||||
kprintf("\e[92mTCP client socket created\n");
|
|
||||||
|
|
||||||
tcp_client_connect_async_data* client_connection_data = malloc(sizeof(tcp_client_connect_async_data));
|
|
||||||
client_connection_data->serverEnd = serverEnd;
|
|
||||||
client_connection_data->socket_client = socket_client;
|
|
||||||
pthread_t client_connection_thread;
|
|
||||||
fflush(stdout);
|
|
||||||
if(pthread_create(&client_connection_thread, NULL, tcp_client_connect_async, client_connection_data) != 0)
|
|
||||||
throw("can't create client connection thread");
|
|
||||||
if(pthread_detach(client_connection_thread) != 0)
|
|
||||||
throw("can't detatch client connection thread");
|
|
||||||
}
|
|
||||||
// server
|
|
||||||
{
|
|
||||||
tryLast(knSocketTCP_accept(socket_server), m_connection, ;);
|
|
||||||
clientConnection = m_connection.value.VoidPtr;
|
|
||||||
kprintf_safe("\e[92mserver accepted client connection\n");
|
|
||||||
}
|
|
||||||
// client
|
|
||||||
{
|
|
||||||
const char client_msg[] = "ping";
|
|
||||||
tryLast(knSocketTCP_send(socket_client, client_msg, sizeof(client_msg)), _mu75q2, ;);
|
|
||||||
kprintf("\e[92mmessage sent to server\n\e[94m");
|
|
||||||
}
|
|
||||||
// server
|
|
||||||
{
|
|
||||||
char received_client_msg[32];
|
|
||||||
tryLast(knSocketTCP_receive(clientConnection, received_client_msg, sizeof(received_client_msg)), m_recCount, ;);
|
|
||||||
u64 recCount = m_recCount.value.UInt64;
|
|
||||||
fwrite(received_client_msg, sizeof(char), recCount, stdout);
|
|
||||||
fputc('\n', stdout);
|
|
||||||
if(!cptr_equals(received_client_msg, "ping"))
|
|
||||||
throw("received_client_msg != \"ping\"");
|
|
||||||
kprintf("\e[92mmessage received by server\n");
|
|
||||||
|
|
||||||
const char server_msg[] = "pong";
|
|
||||||
tryLast(knSocketTCP_send(clientConnection, server_msg, sizeof(server_msg)), _mu75q2, ;);
|
|
||||||
kprintf("\e[92mmessage sent to client\n\e[94m");
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
// client
|
|
||||||
{
|
|
||||||
char received_server_msg[32];
|
|
||||||
tryLast(knSocketTCP_receive(socket_client, received_server_msg, sizeof(received_server_msg)), m_recCount, ;);
|
|
||||||
u64 recCount = m_recCount.value.UInt64;
|
|
||||||
fwrite(received_server_msg, sizeof(char), recCount, stdout);
|
|
||||||
fputc('\n', stdout);
|
|
||||||
if(!cptr_equals(received_server_msg, "pong"))
|
|
||||||
throw("received_server_msg != \"pong\"");
|
|
||||||
kprintf("\e[92mmessage received by client\n");
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
// server
|
|
||||||
{
|
|
||||||
tryLast(knSocketTCP_shutdown(clientConnection, knShutdownType_Both), _m2351, ;);
|
|
||||||
tryLast(knSocketTCP_close(clientConnection), _m9776, ;);
|
|
||||||
kprintf("\e[92mclient connection closed\n");
|
|
||||||
|
|
||||||
tryLast(knSocketTCP_close(socket_server), _m676, ;);
|
|
||||||
kprintf("\e[92mTCP server socket closed\n");
|
|
||||||
}
|
|
||||||
// client
|
|
||||||
{
|
|
||||||
tryLast(knSocketTCP_close(socket_client), _m964, ;);
|
|
||||||
kprintf("\e[92mTCP client socket closed\n");
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_udp(){
|
|
||||||
kprintf("\e[96m----------[test_network/udp]----------\n");
|
|
||||||
knIPV4Endpoint serverEnd = knIPV4Endpoint_create(knIPV4Address_LOOPBACK, 4444);
|
|
||||||
knSocketUDP *socket_server, *socket_client;
|
|
||||||
// server
|
|
||||||
{
|
|
||||||
tryLast(knSocketUDP_open(true), m_socketS, ;);
|
|
||||||
socket_server=m_socketS.value.VoidPtr;
|
|
||||||
kprintf("\e[92mUDP server socket created\n");
|
|
||||||
|
|
||||||
tryLast(knSocketUDP_bind(socket_server, serverEnd), _m81775, ;)
|
|
||||||
kprintf("\e[92mserver socket is bound\n");
|
|
||||||
}
|
|
||||||
// client
|
|
||||||
{
|
|
||||||
tryLast(knSocketUDP_open(false), m_socketC, ;);
|
|
||||||
socket_client=m_socketC.value.VoidPtr;
|
|
||||||
kprintf("\e[92mUDP client socket created\n");
|
|
||||||
|
|
||||||
const char client_msg[] = "ping";
|
|
||||||
tryLast(knSocketUDP_sendTo(socket_client, client_msg, sizeof(client_msg), serverEnd), _mu75q2, ;);
|
|
||||||
kprintf("\e[92mmessage sent to server\n\e[94m");
|
|
||||||
|
|
||||||
char* adrstr = knIPV4Endpoint_toString(socket_client->localEndpoint);
|
|
||||||
kprintf("\e[92mclient socket was implicitely bound to %s\n\e[94m", adrstr);
|
|
||||||
free(adrstr);
|
|
||||||
}
|
|
||||||
// server
|
|
||||||
{
|
|
||||||
char received_client_msg[32];
|
|
||||||
knIPV4Endpoint clientEnd = knIPV4Endpoint_INVALID;
|
|
||||||
tryLast(knSocketUDP_receiveAny(socket_server, received_client_msg, sizeof(received_client_msg), &clientEnd), m_recCount, ;);
|
|
||||||
u64 recCount = m_recCount.value.UInt64;
|
|
||||||
fwrite(received_client_msg, sizeof(char), recCount, stdout);
|
|
||||||
fputc('\n', stdout);
|
|
||||||
if(!cptr_equals(received_client_msg, "ping"))
|
|
||||||
throw("received_client_msg != \"ping\"");
|
|
||||||
kprintf("\e[92mmessage received by server\n");
|
|
||||||
|
|
||||||
const char server_msg[] = "pong";
|
|
||||||
tryLast(knSocketUDP_sendTo(socket_server, server_msg, sizeof(server_msg), clientEnd), _mu75q2, ;);
|
|
||||||
char* adrstr = knIPV4Endpoint_toString(clientEnd);
|
|
||||||
kprintf("\e[92mmessage sent to client (%s)\n\e[94m", adrstr);
|
|
||||||
free(adrstr);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
// client
|
|
||||||
{
|
|
||||||
char received_server_msg[32];
|
|
||||||
knIPV4Endpoint senderEnd = knIPV4Endpoint_INVALID;
|
|
||||||
tryLast(knSocketUDP_receiveAny(socket_client, received_server_msg, sizeof(received_server_msg), &senderEnd), m_recCount, ;);
|
|
||||||
u64 recCount = m_recCount.value.UInt64;
|
|
||||||
fwrite(received_server_msg, sizeof(char), recCount, stdout);
|
|
||||||
fputc('\n', stdout);
|
|
||||||
if(!cptr_equals(received_server_msg, "pong"))
|
|
||||||
throw("received_server_msg != \"pong\"");
|
|
||||||
char* adrstr = knIPV4Endpoint_toString(serverEnd);
|
|
||||||
kprintf("\e[92mmessage received by client (%s)\n", adrstr);
|
|
||||||
free(adrstr);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
// server
|
|
||||||
{
|
|
||||||
tryLast(knSocketUDP_close(socket_server), _m676, ;);
|
|
||||||
kprintf("\e[92mUDP server socket closed\n");
|
|
||||||
}
|
|
||||||
// client
|
|
||||||
{
|
|
||||||
tryLast(knSocketUDP_close(socket_client), _m964, ;);
|
|
||||||
kprintf("\e[92mUDP client socket closed\n");
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_network(){
|
|
||||||
optime(__func__,1,({
|
|
||||||
kprintf("\e[96m------------[test_network]------------\n");
|
|
||||||
tryLast(kn_tryInit(), _mjj64g, ;);
|
|
||||||
kprintf("\e[92mkerepNetwork initialized\n");
|
|
||||||
|
|
||||||
if(pthread_mutex_init(&stdout_mutex, NULL) != 0)
|
|
||||||
throw("can't init mutex");
|
|
||||||
|
|
||||||
test_network_types();
|
|
||||||
test_tcp();
|
|
||||||
test_udp();
|
|
||||||
|
|
||||||
if(pthread_mutex_destroy(&stdout_mutex) != 0)
|
|
||||||
throw("can't destroy mutex");
|
|
||||||
|
|
||||||
tryLast(kt_tryDispose(), _m88ag, ;);
|
|
||||||
kprintf("\e[92mkerepNetwork disposed\n");
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void test_allocators();
|
||||||
void test_cptr();
|
void test_cptr();
|
||||||
void test_string();
|
void test_string();
|
||||||
void test_safethrow();
|
void test_safethrow();
|
||||||
@@ -19,25 +20,24 @@ void test_rng_algorithms();
|
|||||||
void test_kprint_colors();
|
void test_kprint_colors();
|
||||||
void test_kprint();
|
void test_kprint();
|
||||||
void test_type_system();
|
void test_type_system();
|
||||||
void test_network();
|
|
||||||
|
|
||||||
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_cptr();
|
test_allocators();
|
||||||
test_type_system();
|
/*test_cptr();
|
||||||
test_string();
|
test_string();
|
||||||
test_safethrow();
|
test_safethrow();
|
||||||
test_searchtree();
|
test_searchtree();
|
||||||
test_autoarr();
|
test_autoarr();
|
||||||
|
test_hash_functions();
|
||||||
|
test_hashtable();
|
||||||
|
test_dtsod();
|
||||||
test_autoarrVsVector();
|
test_autoarrVsVector();
|
||||||
test_rng_algorithms();
|
test_rng_algorithms();
|
||||||
test_kprint_colors();
|
test_kprint_colors();
|
||||||
test_kprint();
|
test_kprint();
|
||||||
test_hash_functions();
|
test_type_system();*/
|
||||||
test_hashtable();
|
|
||||||
test_dtsod();
|
|
||||||
test_network();
|
|
||||||
kprintf("\e[96m--------------------------------------\e[0m\n");
|
kprintf("\e[96m--------------------------------------\e[0m\n");
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user