Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap
1 result
Show changes
Commits on Source (18)
Showing
with 4172 additions and 950 deletions
[submodule "test/libdap-test"]
path = test/libdap-test
url = https://github.com/cellframe/libdap-test
url = https://gitlab.demlabs.net/cellframe/libdap-test.git
branch = master
......@@ -4,17 +4,91 @@ project (dap_core)
# fix implicit declaration warnings
add_definitions ("-D_GNU_SOURCE")
set(CMAKE_C_FLAGS "-std=c11 -Wall -Wextra")
if(UNIX)
file(GLOB CORE_SRCS
src/*.c
src/etc/*.c
src/rpmalloc/*.c
)
file(GLOB CORE_HEADERS
include/*.h
include/unix/*.h
include/unix/linux/*.h
)
endif()
if(WIN32)
file(GLOB CORE_SRCS
src/*.c
src/etc/*.c
src/win32/*.c
src/rpmalloc/*.c
)
file(GLOB CORE_HEADERS
include/*.h
src/win32/*.h
src/win32/*.h
)
endif()
if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
set(SUBMODULES_NO_BUILD ON)
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
set(DEFAULT_BUILD_64 ON)
else()
set(DEFAULT_BUILD_64 OFF)
endif()
option(BUILD_64 "Build for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_BUILD_64})
add_definitions ("-DDAP_SERVER")
add_definitions ("-DNODE_NETNAME=\"kelvin\"")
if(WIN32)
add_definitions ("-DUNDEBUG")
add_definitions ("-DNDEBUG")
add_definitions ("-DWIN32")
add_definitions ("-D_WINDOWS")
add_definitions ("-D__WINDOWS__")
add_definitions ("-D_CRT_SECURE_NO_WARNINGS")
# if(DAP_RELEASE)
set(_CCOPT "-mconsole -static -Wall -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
# else()
# set(_CCOPT "-mconsole -static -Wall -pg")
# set(_LOPT "-mconsole -static -pg")
# endif()
file(GLOB CORE_SRCS src/*.c)
file(GLOB CORE_HEADERS include/*.h include/unix/*.h include/unix/linux/*.h )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${_LOPT}")
endif()
if(UNIX)
add_definitions ("-DDAP_OS_LINUX")
if(DAP_RELEASE)
set(_CCOPT "-Wall -O3 -fPIC -fno-pie -no-pie -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
else()
set(_CCOPT "-Wall -pg -fPIC -fno-pie -no-pie")
set(_LOPT "-pg")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${_LOPT}")
endif()
endif()
add_library(${PROJECT_NAME} STATIC ${CORE_SRCS} ${CORE_UNIX_SRCS})
#This paths will be used by project-dependent project libraries
target_include_directories(${PROJECT_NAME} INTERFACE include/)
target_include_directories(${PROJECT_NAME} INTERFACE include/ src/rpmalloc/)
if(WIN32)
include_directories(include/)
endif()
if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set(LINUX "Linux")
......@@ -30,9 +104,7 @@ if(DARWIN)
target_link_libraries(${PROJECT_NAME} dap_core_darwin)
endif()
if(BUILD_DAP_TESTS)
enable_testing()
add_subdirectory(test)
endif()
......@@ -89,7 +89,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
<div class="title">dap_common.h</div> </div>
</div><!--header-->
<div class="contents">
<a href="dap__common_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment"> * Authors:</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment"> * Dmitriy A. Gearasimov &lt;kahovski@gmail.com&gt;</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment"> * DeM Labs Inc. https://demlabs.net</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="comment"> * DeM Labs Open source community https://github.com/demlabsinc</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="comment"> * Copyright (c) 2017-2018</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="comment"> * All rights reserved.</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="comment"> This file is part of DAP (Deus Applications Prototypes) the open source project</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="comment"> DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="comment"> it under the terms of the GNU General Public License as published by</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;<span class="comment"> the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="comment"> (at your option) any later version.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="comment"> DAP is distributed in the hope that it will be useful,</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;<span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="comment"> GNU General Public License for more details.</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="comment"> You should have received a copy of the GNU General Public License</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;<span class="comment"> along with any DAP based project. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="comment">*/</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="preprocessor">#pragma once</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="preprocessor">#include &lt;stdarg.h&gt;</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="preprocessor">#include &lt;stddef.h&gt;</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="preprocessor">#include &lt;time.h&gt;</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a74a9d9e85c7cc12c155f147d9a971cad"> 30</a></span>&#160;<span class="preprocessor">#define DAP_NEW(a) ( (a*) malloc(sizeof(a)))</span></div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a80373ba28489011c16cd76f6d0ba5b53"> 31</a></span>&#160;<span class="preprocessor">#define DAP_NEW_SIZE(a,b) ( (a*) malloc(b))</span></div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9270d1341aa00be475591ecfa8985c08"> 32</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z(a) ( (a*) calloc(1,sizeof(a)))</span></div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ad0f1f3c74154c73a5dfd33598dfd375b"> 33</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z_SIZE(a,b) ( (a*) calloc(1,b))</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="dap__common_8h.html#abc94d3603906f97d0ce7368f44eebf8b"> 35</a></span>&#160;<span class="preprocessor">#define DAP_DELETE(a) free(a)</span></div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a7303c16a9766b284e07bd6790d65b59e"> 36</a></span>&#160;<span class="preprocessor">#define DAP_DUP(a) (__typeof(a) ret = memcpy(ret,a,sizeof(*a)) )</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9757f0cc77df1fd0759b1b91a9f63ff0"> 38</a></span>&#160;<span class="preprocessor">#define DAP_PROTOCOL_VERSION 21</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="preprocessor">#if defined(__GNUC__) ||defined (__clang__)</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="preprocessor">#define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e"> 47</a></span>&#160;<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>{<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ead95cd234638314479dea217167c37e4a">L_CRITICAL</a>=5,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15">L_ERROR</a>=4, <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea83e54d43eb3fd145052377ecd43932a1">L_WARNING</a>=3,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eac0e398e95a19b2d3e23eb0620e91a515">L_NOTICE</a>=2,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eae580867d0ddde34905fea2f8669839b7">L_INFO</a>=1,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a>=0};</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160;<span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aff6dc9e558a255f56618643f5be92b08">dap_common_init</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> * a_log_file );</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab96d7e843bc09468220a7d264295cf69">dap_common_deinit</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#acbe3239b788dc1105a094596354a7e42">_log_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format,...);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab3ae03011f7dfbbf40dce01f7bdd4157">_vlog_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format, va_list ap );</div><div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="dap__common_8h.html#acd8f4f3ce595157ca36ce6b61ca4195e"> 58</a></span>&#160;<span class="preprocessor">#define log_it(_log_level,...) _log_it(LOG_TAG,_log_level,##__VA_ARGS__)</span></div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ab53061ef6723b1e4a233022ef9f33c76"> 59</a></span>&#160;<span class="preprocessor">#define vlog_it(a_log_level,a_format,a_ap) _vlog_it(LOG_TAG,a_log_level,a_format,a_ap)</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160;<span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa76592df3b155b21f4d05cbd042db5f7">log_error</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a98de0fce0a8fb5c3b0cfe80bebe8f691">set_log_level</a>(<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a> ll);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ac8d0df7015664c720b27ee4f6e660479">dap_set_log_tag_width</a>(<span class="keywordtype">size_t</span> width);</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160;<span class="preprocessor">#ifdef __GNUC__</span></div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160;<span class="keywordtype">char</span> *<a class="code" href="dap__common_8c.html#a9c7174a7bbe81eedbd86ded2e247eee7">itoa</a>(<span class="keywordtype">int</span> i);</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160;<span class="preprocessor">#elif _MSC_VER</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160;<span class="keywordtype">char</span> *strndup(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keywordtype">size_t</span> n);</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#a6ab10606e8ac33dd93a0526933b192c8">time_to_rfc822</a>(<span class="keywordtype">char</span> * out, <span class="keywordtype">size_t</span> out_size_max, time_t t);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#ab027eeb728bcf25f75bc592fc627e4fe">get_select_breaker</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aa3c5a3515672b9ecc8d114af678cb0a4">send_select_break</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#a00992fd7732b0ff40ce020728f84bc3a">exec_with_ret</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa4a4c13332f14e44630f5e269048249a">exec_with_ret_multistring</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aabbc0306fee1c3a56540b1604bbb516c">dap_random_string_create_alloc</a>(<span class="keywordtype">size_t</span> a_length);</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a3fa34950395c0139c5c95510de7119a8">dap_random_string_fill</a>(<span class="keywordtype">char</span> *str, <span class="keywordtype">size_t</span> length);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160;}</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a></div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div>
<a href="dap__common_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment"> * Authors:</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment"> * Dmitriy A. Gearasimov &lt;kahovski@gmail.com&gt;</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment"> * DeM Labs Inc. https://demlabs.net</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="comment"> * DeM Labs Open source community https://gitlab.demlabs.net/cellframe</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="comment"> * Copyright (c) 2017-2018</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="comment"> * All rights reserved.</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="comment"> This file is part of DAP (Deus Applications Prototypes) the open source project</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="comment"> DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="comment"> it under the terms of the GNU General Public License as published by</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;<span class="comment"> the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="comment"> (at your option) any later version.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="comment"> DAP is distributed in the hope that it will be useful,</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;<span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="comment"> GNU General Public License for more details.</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="comment"> You should have received a copy of the GNU General Public License</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;<span class="comment"> along with any DAP based project. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="comment">*/</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="preprocessor">#pragma once</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="preprocessor">#include &lt;stdarg.h&gt;</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="preprocessor">#include &lt;stddef.h&gt;</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="preprocessor">#include &lt;time.h&gt;</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a74a9d9e85c7cc12c155f147d9a971cad"> 30</a></span>&#160;<span class="preprocessor">#define DAP_NEW(a) ( (a*) malloc(sizeof(a)))</span></div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a80373ba28489011c16cd76f6d0ba5b53"> 31</a></span>&#160;<span class="preprocessor">#define DAP_NEW_SIZE(a,b) ( (a*) malloc(b))</span></div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9270d1341aa00be475591ecfa8985c08"> 32</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z(a) ( (a*) calloc(1,sizeof(a)))</span></div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ad0f1f3c74154c73a5dfd33598dfd375b"> 33</a></span>&#160;<span class="preprocessor">#define DAP_NEW_Z_SIZE(a,b) ( (a*) calloc(1,b))</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="dap__common_8h.html#abc94d3603906f97d0ce7368f44eebf8b"> 35</a></span>&#160;<span class="preprocessor">#define DAP_DELETE(a) free(a)</span></div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a7303c16a9766b284e07bd6790d65b59e"> 36</a></span>&#160;<span class="preprocessor">#define DAP_DUP(a) (__typeof(a) ret = memcpy(ret,a,sizeof(*a)) )</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="dap__common_8h.html#a9757f0cc77df1fd0759b1b91a9f63ff0"> 38</a></span>&#160;<span class="preprocessor">#define DAP_PROTOCOL_VERSION 21</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="preprocessor">#if defined(__GNUC__) ||defined (__clang__)</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="preprocessor">#define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e"> 47</a></span>&#160;<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>{<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ead95cd234638314479dea217167c37e4a">L_CRITICAL</a>=5,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15">L_ERROR</a>=4, <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea83e54d43eb3fd145052377ecd43932a1">L_WARNING</a>=3,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eac0e398e95a19b2d3e23eb0620e91a515">L_NOTICE</a>=2,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eae580867d0ddde34905fea2f8669839b7">L_INFO</a>=1,<a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a>=0};</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160;<span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aff6dc9e558a255f56618643f5be92b08">dap_common_init</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> * a_log_file );</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab96d7e843bc09468220a7d264295cf69">dap_common_deinit</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#acbe3239b788dc1105a094596354a7e42">_log_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format,...);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ab3ae03011f7dfbbf40dce01f7bdd4157">_vlog_it</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * log_tag, <span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> * format, va_list ap );</div><div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="dap__common_8h.html#acd8f4f3ce595157ca36ce6b61ca4195e"> 58</a></span>&#160;<span class="preprocessor">#define log_it(_log_level,...) _log_it(LOG_TAG,_log_level,##__VA_ARGS__)</span></div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="dap__common_8h.html#ab53061ef6723b1e4a233022ef9f33c76"> 59</a></span>&#160;<span class="preprocessor">#define vlog_it(a_log_level,a_format,a_ap) _vlog_it(LOG_TAG,a_log_level,a_format,a_ap)</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160;<span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa76592df3b155b21f4d05cbd042db5f7">log_error</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a98de0fce0a8fb5c3b0cfe80bebe8f691">set_log_level</a>(<span class="keyword">enum</span> <a class="code" href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a> ll);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#ac8d0df7015664c720b27ee4f6e660479">dap_set_log_tag_width</a>(<span class="keywordtype">size_t</span> width);</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160;<span class="preprocessor">#ifdef __GNUC__</span></div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160;<span class="keywordtype">char</span> *<a class="code" href="dap__common_8c.html#a9c7174a7bbe81eedbd86ded2e247eee7">itoa</a>(<span class="keywordtype">int</span> i);</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160;<span class="preprocessor">#elif _MSC_VER</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160;<span class="keywordtype">char</span> *strndup(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keywordtype">size_t</span> n);</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#a6ab10606e8ac33dd93a0526933b192c8">time_to_rfc822</a>(<span class="keywordtype">char</span> * out, <span class="keywordtype">size_t</span> out_size_max, time_t t);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#ab027eeb728bcf25f75bc592fc627e4fe">get_select_breaker</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160;<span class="keywordtype">int</span> <a class="code" href="dap__common_8h.html#aa3c5a3515672b9ecc8d114af678cb0a4">send_select_break</a>(<span class="keywordtype">void</span>);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#a00992fd7732b0ff40ce020728f84bc3a">exec_with_ret</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aa4a4c13332f14e44630f5e269048249a">exec_with_ret_multistring</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * a_cmd);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160;<span class="keywordtype">char</span> * <a class="code" href="dap__common_8h.html#aabbc0306fee1c3a56540b1604bbb516c">dap_random_string_create_alloc</a>(<span class="keywordtype">size_t</span> a_length);</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160;<span class="keywordtype">void</span> <a class="code" href="dap__common_8h.html#a3fa34950395c0139c5c95510de7119a8">dap_random_string_fill</a>(<span class="keywordtype">char</span> *str, <span class="keywordtype">size_t</span> length);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160;<span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160;}</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748eabef96148470abb1ed19980e5b5c40ad4">L_DEBUG</a></div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div>
<div class="ttc" id="dap__common_8h_html_ac8d0df7015664c720b27ee4f6e660479"><div class="ttname"><a href="dap__common_8h.html#ac8d0df7015664c720b27ee4f6e660479">dap_set_log_tag_width</a></div><div class="ttdeci">void dap_set_log_tag_width(size_t width)</div><div class="ttdoc">dap_set_log_tag_width Sets the length of the label </div><div class="ttdef"><b>Definition:</b> dap_common.c:77</div></div>
<div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748ea5aa6d01f59e4b628af96f650fc5ecc15">L_ERROR</a></div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div>
<div class="ttc" id="dap__common_8h_html_ac91d55174d383848b976a34de843748e"><div class="ttname"><a href="dap__common_8h.html#ac91d55174d383848b976a34de843748e">log_level</a></div><div class="ttdeci">log_level</div><div class="ttdoc">The log_level enum. </div><div class="ttdef"><b>Definition:</b> dap_common.h:47</div></div>
......
......@@ -3,7 +3,7 @@
* Dmitriy A. Gearasimov <kahovski@gmail.com>
* Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved.
......@@ -32,15 +32,7 @@
#include <stdlib.h>
#include <time.h>
#define DAP_NEW( a ) ( (a*) malloc(sizeof(a)) )
#define DAP_NEW_SIZE( a, b ) ( (a*) malloc(b) )
#define DAP_NEW_Z( a ) ( (a*) calloc(1,sizeof(a)) )
#define DAP_NEW_Z_SIZE( a, b )( (a*) calloc(1,b) )
#define DAP_REALLOC( a, b ) ( realloc(a,b) )
#define DAP_DELETE(a) free( a )
#define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
#define DAP_PROTOCOL_VERSION 22
#include "portable_endian.h"
#if defined(__GNUC__) ||defined (__clang__)
#define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))
......@@ -51,9 +43,11 @@
#ifdef _MSC_VER
#define DAP_STATIC_INLINE static __forceinline
#define DAP_INLINE __forceinline
#define DAP_ALIGNED(x) __declspec( align(x) )
#else
#define DAP_STATIC_INLINE static __attribute__((always_inline)) inline
#define DAP_INLINE __attribute__((always_inline)) inline
#define DAP_ALIGNED(x) __attribute__ ((aligned (x)))
#endif
#ifndef TRUE
......@@ -61,19 +55,152 @@
#define FALSE false
#endif
#ifndef ROUNDUP
#define ROUNDUP(n,width) (((n) + (width) - 1) & ~unsigned((width) - 1))
#endif
#if DAP_USE_RPMALLOC
#include "rpmalloc.h"
#define DAP_MALLOC(a) rpmalloc(a)
#define DAP_FREE(a) rpfree(a)
#define DAP_CALLOC(a, b) rpcalloc(a, b)
#define DAP_ALMALLOC(a, b) rpaligned_alloc(a, b)
#define DAP_ALREALLOC(a,b,c) rpaligned_realloc(a, b, c, 0, 0)
#define DAP_ALFREE(a) rpfree(a)
#define DAP_NEW(a) ((a*) rpmalloc(sizeof(a)))
#define DAP_NEW_SIZE(a, b) ((a*) rpmalloc(b))
#define DAP_NEW_Z(a) ((a*) rpcalloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) ((a*) rpcalloc(1,b))
#define DAP_REALLOC(a, b) rprealloc(a,b)
#define DAP_DELETE(a) rpfree(a)
#define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
#else
#define DAP_MALLOC(a) malloc(a)
#define DAP_FREE(a) free(a)
#define DAP_CALLOC(a, b) calloc(a, b)
#define DAP_ALMALLOC(a, b) _dap_aligned_alloc(a, b)
#define DAP_ALREALLOC(a, b) _dap_aligned_realloc(a, b)
#define DAP_ALFREE(a) _dap_aligned_free(a, b)
#define DAP_NEW( a ) ((a*) malloc(sizeof(a)))
#define DAP_NEW_SIZE(a, b) ((a*) malloc(b) )
#define DAP_NEW_Z( a ) ((a*) calloc(1,sizeof(a)))
#define DAP_NEW_Z_SIZE(a, b) ((a*) calloc(1,b))
#define DAP_REALLOC(a, b) realloc(a,b)
#define DAP_DELETE(a) free(a)
#define DAP_DUP(a) ( __typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
#endif
DAP_STATIC_INLINE void *_dap_aligned_alloc( uintptr_t alignment, uintptr_t size )
{
uintptr_t ptr = (uintptr_t) DAP_MALLOC( size + (alignment * 2) + sizeof(void *) );
if ( !ptr )
return (void *)ptr;
uintptr_t al_ptr = ( ptr + sizeof(void *) + alignment) & ~(alignment - 1 );
((uintptr_t *)al_ptr)[-1] = ptr;
return (void *)al_ptr;
}
DAP_STATIC_INLINE void *_dap_aligned_realloc( uintptr_t alignment, void *bptr, uintptr_t size )
{
uintptr_t ptr = (uintptr_t) DAP_REALLOC( bptr, size + (alignment * 2) + sizeof(void *) );
if ( !ptr )
return (void *)ptr;
uintptr_t al_ptr = ( ptr + sizeof(void *) + alignment) & ~(alignment - 1 );
((uintptr_t *)al_ptr)[-1] = ptr;
return (void *)al_ptr;
}
DAP_STATIC_INLINE void _dap_aligned_free( void *ptr )
{
if ( !ptr )
return;
void *base_ptr = (void *)((uintptr_t *)ptr)[-1];
DAP_FREE( base_ptr );
}
#define DAP_PROTOCOL_VERSION 22
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef min
#define min MIN
#endif
#ifndef max
#define max MAX
#endif
#ifndef LOWORD
#define LOWORD( l ) ((uint16_t) (((uintptr_t) (l)) & 0xFFFF))
#define HIWORD( l ) ((uint16_t) ((((uintptr_t) (l)) >> 16) & 0xFFFF))
#define LOBYTE( w ) ((uint8_t) (((uintptr_t) (w)) & 0xFF))
#define HIBYTE( w ) ((uint8_t) ((((uintptr_t) (w)) >> 8) & 0xFF))
#endif
#ifndef RGB
#define RGB(r,g,b) ((uint32_t)(((uint8_t)(r)|((uint16_t)((uint8_t)(g))<<8))|(((uint32_t)(uint8_t)(b))<<16)))
#define RGBA(r, g, b, a) ((uint32_t) ((uint32_t)RGB(r,g,b) | (uint32_t)(a) << 24))
#define GetRValue(rgb) (LOBYTE(rgb))
#define GetGValue(rgb) (LOBYTE(((uint16_t)(rgb)) >> 8))
#define GetBValue(rgb) (LOBYTE((rgb)>>16))
#define GetAValue(rgb) (LOBYTE((rgb)>>24))
#endif
#define QBYTE RGBA
#define DAP_LOG_HISTORY_STR_SIZE 128
#define DAP_LOG_HISTORY_MAX_STRINGS 1024
#define DAP_LOG_HISTORY_MAX_STRINGS 4096
#define DAP_LOG_HISTORY_BUFFER_SIZE (DAP_LOG_HISTORY_STR_SIZE * DAP_LOG_HISTORY_MAX_STRINGS)
#define DAP_LOG_HISTORY_M (DAP_LOG_HISTORY_MAX_STRINGS - 1)
#ifdef _WIN32
#define dap_sscanf __mingw_sscanf
#define dap_vsscanf __mingw_vsscanf
#define dap_scanf __mingw_scanf
#define dap_vscanf __mingw_vscanf
#define dap_fscanf __mingw_fscanf
#define dap_vfscanf __mingw_vfscanf
#define dap_sprintf __mingw_sprintf
#define dap_snprintf __mingw_snprintf
#define dap_printf __mingw_printf
#define dap_vprintf __mingw_vprintf
#define dap_fprintf __mingw_fprintf
#define dap_vfprintf __mingw_vfprintf
#define dap_vsprintf __mingw_vsprintf
#define dap_vsnprintf __mingw_vsnprintf
#define dap_asprintf __mingw_asprintf
#define dap_vasprintf __mingw_vasprintf
#else
#define dap_sscanf sscanf
#define dap_vsscanf vsscanf
#define dap_scanf scanf
#define dap_vscanf vscanf
#define dap_fscanf fscanf
#define dap_vfscanf vfscanf
#define dap_sprintf sprintf
#define dap_snprintf snprintf
#define dap_printf printf
#define dap_vprintf vprintf
#define dap_fprintf fprintf
#define dap_vfprintf vfprintf
#define dap_vsprintf vsprintf
#define dap_vsnprintf vsnprintf
#define dap_asprintf asprintf
#define dap_vasprintf vasprintf
#endif
/**
* @brief The log_level enum
*/
......@@ -83,7 +210,7 @@ typedef enum dap_log_level {
L_DEBUG = 0,
L_INFO = 1,
L_NOTICE = 2,
L_MESSAGE = 3,
L_MSG = 3,
L_DAP = 4,
L_WARNING = 5,
L_ATT = 6,
......@@ -105,6 +232,29 @@ typedef struct dap_log_str_s {
extern "C" {
#endif
extern uint16_t htoa_lut256[ 256 ];
#define dap_htoa64( out, in, len ) \
{\
uintptr_t _len = len; \
uint16_t *__restrict _out = (uint16_t *__restrict)out; \
uint64_t *__restrict _in = (uint64_t *__restrict)in;\
\
while ( _len ) {\
uint64_t _val = *_in ++;\
_out[0] = htoa_lut256[ _val & 0x00000000000000FF ];\
_out[1] = htoa_lut256[ (_val & 0x000000000000FF00) >> 8 ];\
_out[2] = htoa_lut256[ (_val & 0x0000000000FF0000) >> 16 ];\
_out[3] = htoa_lut256[ (_val & 0x00000000FF000000) >> 24 ];\
_out[4] = htoa_lut256[ (_val & 0x000000FF00000000) >> 32 ];\
_out[5] = htoa_lut256[ (_val & 0x0000FF0000000000) >> 40 ];\
_out[6] = htoa_lut256[ (_val & 0x00FF000000000000) >> 48 ];\
_out[7] = htoa_lut256[ (_val & 0xFF00000000000000) >> 56 ];\
_out += 8;\
_len -= 8;\
}\
}
typedef enum {
DAP_ASCII_ALNUM = 1 << 0,
DAP_ASCII_ALPHA = 1 << 1,
......@@ -144,7 +294,9 @@ static const uint16_t s_ascii_table_data[256] = {
#define dap_ascii_isspace(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_SPACE) != 0
#define dap_ascii_isalpha(c) (s_ascii_table_data[(unsigned char) (c)] & DAP_ASCII_ALPHA) != 0
int dap_common_init( const char * a_log_file );
//int dap_common_init( const char * a_log_file );
int dap_common_init( const char *console_title, const char *a_log_file );
void dap_common_deinit(void);
// set max items in log list
......@@ -153,10 +305,11 @@ void dap_log_set_max_item(unsigned int a_max);
char *dap_log_get_item(time_t a_start_time, int a_limit);
void _log_it(const char * log_tag, enum dap_log_level, const char * format,...);
void _vlog_it(const char * log_tag, enum dap_log_level, const char * format, va_list ap );
#define log_it(_log_level,...) _log_it(LOG_TAG,_log_level,##__VA_ARGS__)
#define vlog_it(a_log_level,a_format,a_ap) _vlog_it(LOG_TAG,a_log_level,a_format,a_ap)
void _log_it( const char * log_tag, enum dap_log_level, const char * format,... );
void _vlog_it( const char * log_tag, enum dap_log_level, const char * format, va_list ap );
#define log_it(_log_level,...) _log_it( LOG_TAG, _log_level, ##__VA_ARGS__)
#define vlog_it( a_log_level, a_format, a_ap ) _vlog_it( LOG_TAG, a_log_level, a_format, a_ap )
const char * log_error(void);
void dap_log_level_set(enum dap_log_level ll);
......@@ -179,6 +332,8 @@ void dap_dump_hex(const void* data, size_t size);
size_t dap_hex2bin(uint8_t *a_out, const char *a_in, size_t a_len);
size_t dap_bin2hex(char *a_out, const void *a_in, size_t a_len);
void dap_digit_from_string(const char *num_str, uint8_t *raw, size_t raw_len);
void dap_digit_from_string2(const char *num_str, uint8_t *raw, size_t raw_len);
#ifdef __MINGW32__
int exec_silent(const char *a_cmd);
......
......@@ -3,7 +3,7 @@
* Dmitriy A. Gearasimov <kahovski@gmail.com>
* Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved.
......
......@@ -2,7 +2,7 @@
* Authors:
* Aleksandr Lysikov <alexander.lysikov@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain
* Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved.
......
......@@ -2,7 +2,7 @@
* Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain
* Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2018
* All rights reserved.
......
......@@ -32,6 +32,12 @@
#undef clamp
#define clamp(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
#ifdef _WIN32
char *strptime( char *buff, const char *fmt, struct tm *tm );
#endif
size_t dap_strlen(const char *a_str);
// compare a_str1 and a_str2
int dap_strcmp(const char *a_str1, const char *a_str2);
......
// "License": Public Domain
// I, Mathias Panzenb?ck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
# define __WINDOWS__
#endif
#if defined(__linux__) || defined(__CYGWIN__)
# include <endian.h>
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define htobe16(x) OSSwapHostToBigInt16(x)
# define htole16(x) OSSwapHostToLittleInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x)
# define le16toh(x) OSSwapLittleToHostInt16(x)
# define htobe32(x) OSSwapHostToBigInt32(x)
# define htole32(x) OSSwapHostToLittleInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x)
# define htole64(x) OSSwapHostToLittleInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#elif defined(__OpenBSD__)
# include <sys/endian.h>
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/endian.h>
# define be16toh(x) betoh16(x)
# define le16toh(x) letoh16(x)
# define be32toh(x) betoh32(x)
# define le32toh(x) letoh32(x)
# define be64toh(x) betoh64(x)
# define le64toh(x) letoh64(x)
#elif defined(__WINDOWS__)
# include <windows.h>
# if BYTE_ORDER == LITTLE_ENDIAN
# if defined(_MSC_VER)
# include <stdlib.h>
# define htobe16(x) _byteswap_ushort(x)
# define htole16(x) (x)
# define be16toh(x) _byteswap_ushort(x)
# define le16toh(x) (x)
# define htobe32(x) _byteswap_ulong(x)
# define htole32(x) (x)
# define be32toh(x) _byteswap_ulong(x)
# define le32toh(x) (x)
# define htobe64(x) _byteswap_uint64(x)
# define htole64(x) (x)
# define be64toh(x) _byteswap_uint64(x)
# define le64toh(x) (x)
# elif defined(__GNUC__) || defined(__clang__)
# define htobe16(x) __builtin_bswap16(x)
# define htole16(x) (x)
# define be16toh(x) __builtin_bswap16(x)
# define le16toh(x) (x)
# define htobe32(x) __builtin_bswap32(x)
# define htole32(x) (x)
# define be32toh(x) __builtin_bswap32(x)
# define le32toh(x) (x)
# define htobe64(x) __builtin_bswap64(x)
# define htole64(x) (x)
# define be64toh(x) __builtin_bswap64(x)
# define le64toh(x) (x)
# else
# error platform not supported
# endif
# else
# error byte order not supported
# endif
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#else
# error platform not supported
#endif
#endif
......@@ -335,9 +335,9 @@ void circular_buffer_print(circular_buffer_t cBuf, bool hex)
c = b[i];
}
if(hex)
sprintf(str+i*2, "%02X|",c);
dap_sprintf(str+i*2, "%02X|",c);
else
sprintf(str+i*2, "%c|",c);
dap_sprintf(str+i*2, "%c|",c);
}
printf("CircularBuffer: %s <size %zu dataSize:%zu>\n",str,circular_buffer_get_capacity(cBuf),circular_buffer_get_data_size(cBuf));
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* Authors:
* Aleksandr Lysikov <alexander.lysikov@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain
* Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2018
* All rights reserved.
......
DAP_ALIGNED(16) uint16_t htoa_lut256[ 256 ] = {
0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830, 0x3930, 0x4130, 0x4230, 0x4330, 0x4430, 0x4530,
0x4630, 0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731, 0x3831, 0x3931, 0x4131, 0x4231, 0x4331, 0x4431,
0x4531, 0x4631, 0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732, 0x3832, 0x3932, 0x4132, 0x4232, 0x4332,
0x4432, 0x4532, 0x4632, 0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733, 0x3833, 0x3933, 0x4133, 0x4233,
0x4333, 0x4433, 0x4533, 0x4633, 0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734, 0x3834, 0x3934, 0x4134,
0x4234, 0x4334, 0x4434, 0x4534, 0x4634, 0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935,
0x4135, 0x4235, 0x4335, 0x4435, 0x4535, 0x4635, 0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836,
0x3936, 0x4136, 0x4236, 0x4336, 0x4436, 0x4536, 0x4636, 0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737,
0x3837, 0x3937, 0x4137, 0x4237, 0x4337, 0x4437, 0x4537, 0x4637, 0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638,
0x3738, 0x3838, 0x3938, 0x4138, 0x4238, 0x4338, 0x4438, 0x4538, 0x4638, 0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539,
0x3639, 0x3739, 0x3839, 0x3939, 0x4139, 0x4239, 0x4339, 0x4439, 0x4539, 0x4639, 0x3041, 0x3141, 0x3241, 0x3341, 0x3441,
0x3541, 0x3641, 0x3741, 0x3841, 0x3941, 0x4141, 0x4241, 0x4341, 0x4441, 0x4541, 0x4641, 0x3042, 0x3142, 0x3242, 0x3342,
0x3442, 0x3542, 0x3642, 0x3742, 0x3842, 0x3942, 0x4142, 0x4242, 0x4342, 0x4442, 0x4542, 0x4642, 0x3043, 0x3143, 0x3243,
0x3343, 0x3443, 0x3543, 0x3643, 0x3743, 0x3843, 0x3943, 0x4143, 0x4243, 0x4343, 0x4443, 0x4543, 0x4643, 0x3044, 0x3144,
0x3244, 0x3344, 0x3444, 0x3544, 0x3644, 0x3744, 0x3844, 0x3944, 0x4144, 0x4244, 0x4344, 0x4444, 0x4544, 0x4644, 0x3045,
0x3145, 0x3245, 0x3345, 0x3445, 0x3545, 0x3645, 0x3745, 0x3845, 0x3945, 0x4145, 0x4245, 0x4345, 0x4445, 0x4545, 0x4645,
0x3046, 0x3146, 0x3246, 0x3346, 0x3446, 0x3546, 0x3646, 0x3746, 0x3846, 0x3946, 0x4146, 0x4246, 0x4346, 0x4446, 0x4546,
0x4646
};
......@@ -2,7 +2,7 @@
* Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain
* Kelvin Project https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2018
* All rights reserved.
......
/* DAP String Functions */
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
//#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#endif
#include <stddef.h>
......@@ -14,7 +14,7 @@
#include "dap_strfuncs.h"
#ifdef _WIN32
char *strndup(char *str, int len) {
static inline char *strndup(char *str, int len) {
char *buf = (char*)malloc(len + 1);
memcpy(buf, str, len);
buf[len] = 0;
......@@ -22,6 +22,22 @@ char *strndup(char *str, int len) {
}
#endif
#ifdef _WIN32
char *strptime( char *buff, const char *fmt, struct tm *tm )
{
uint32_t len = strlen( buff );
dap_sscanf( buff,"%u.%u.%u_%u.%u.%u",&tm->tm_year, &tm->tm_mon, &tm->tm_mday, &tm->tm_hour, &tm->tm_min, &tm->tm_sec );
tm->tm_year += 2000;
return buff + len;
}
#endif
/**
* dap_strlen:
* @a_str: (nullable): the string
......@@ -113,7 +129,7 @@ char* dap_strdup(const char *a_str)
char* dap_strdup_vprintf(const char *a_format, va_list a_args)
{
char *l_string = NULL;
int len = vasprintf(&l_string, a_format, a_args);
int len = dap_vasprintf(&l_string, a_format, a_args);
if(len < 0)
l_string = NULL;
return l_string;
......
......@@ -833,7 +833,7 @@ void dap_string_append_vprintf(dap_string_t *string, const char *format, va_list
dap_return_if_fail(string != NULL);
dap_return_if_fail(format != NULL);
len = vasprintf(&buf, format, args);
len = dap_vasprintf(&buf, format, args);
if(len >= 0) {
dap_string_maybe_expand(string, len);
......
......@@ -2,7 +2,7 @@
* Authors:
* Anton Isaikin <anton.isaikin@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved.
......
This diff is collapsed.
/* rpmalloc.h - Memory allocator - Public Domain - 2016 Mattias Jansson
*
* This library provides a cross-platform lock free thread caching malloc implementation in C11.
* The latest source code is always available at
*
* https://github.com/mjansson/rpmalloc
*
* This library is put in the public domain; you can redistribute it and/or modify it without any restrictions.
*
*/
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__clang__) || defined(__GNUC__)
# define RPMALLOC_EXPORT __attribute__((visibility("default")))
# define RPMALLOC_ALLOCATOR
# define RPMALLOC_ATTRIB_MALLOC __attribute__((__malloc__))
# if defined(__clang_major__) && (__clang_major__ < 4)
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size)
# else
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size) __attribute__((alloc_size(size)))
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size) __attribute__((alloc_size(count, size)))
# endif
# define RPMALLOC_CDECL
#elif defined(_MSC_VER)
# define RPMALLOC_EXPORT
# define RPMALLOC_ALLOCATOR __declspec(allocator) __declspec(restrict)
# define RPMALLOC_ATTRIB_MALLOC
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size)
# define RPMALLOC_CDECL __cdecl
#else
# define RPMALLOC_EXPORT
# define RPMALLOC_ALLOCATOR
# define RPMALLOC_ATTRIB_MALLOC
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size)
# define RPMALLOC_CDECL
#endif
//! Define RPMALLOC_CONFIGURABLE to enable configuring sizes
#ifndef RPMALLOC_CONFIGURABLE
#define RPMALLOC_CONFIGURABLE 0
#endif
//! Flag to rpaligned_realloc to not preserve content in reallocation
#define RPMALLOC_NO_PRESERVE 1
typedef struct rpmalloc_global_statistics_t {
//! Current amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1)
size_t mapped;
//! Peak amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1)
size_t mapped_peak;
//! Current amount of memory in global caches for small and medium sizes (<32KiB)
size_t cached;
//! Current amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1)
size_t huge_alloc;
//! Peak amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1)
size_t huge_alloc_peak;
//! Total amount of memory mapped since initialization (only if ENABLE_STATISTICS=1)
size_t mapped_total;
//! Total amount of memory unmapped since initialization (only if ENABLE_STATISTICS=1)
size_t unmapped_total;
} rpmalloc_global_statistics_t;
typedef struct rpmalloc_thread_statistics_t {
//! Current number of bytes available in thread size class caches for small and medium sizes (<32KiB)
size_t sizecache;
//! Current number of bytes available in thread span caches for small and medium sizes (<32KiB)
size_t spancache;
//! Total number of bytes transitioned from thread cache to global cache (only if ENABLE_STATISTICS=1)
size_t thread_to_global;
//! Total number of bytes transitioned from global cache to thread cache (only if ENABLE_STATISTICS=1)
size_t global_to_thread;
//! Per span count statistics (only if ENABLE_STATISTICS=1)
struct {
//! Currently used number of spans
size_t current;
//! High water mark of spans used
size_t peak;
//! Number of spans transitioned to global cache
size_t to_global;
//! Number of spans transitioned from global cache
size_t from_global;
//! Number of spans transitioned to thread cache
size_t to_cache;
//! Number of spans transitioned from thread cache
size_t from_cache;
//! Number of spans transitioned to reserved state
size_t to_reserved;
//! Number of spans transitioned from reserved state
size_t from_reserved;
//! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls)
size_t map_calls;
} span_use[32];
//! Per size class statistics (only if ENABLE_STATISTICS=1)
struct {
//! Current number of allocations
size_t alloc_current;
//! Peak number of allocations
size_t alloc_peak;
//! Total number of allocations
size_t alloc_total;
//! Total number of frees
size_t free_total;
//! Number of spans transitioned to cache
size_t spans_to_cache;
//! Number of spans transitioned from cache
size_t spans_from_cache;
//! Number of spans transitioned from reserved state
size_t spans_from_reserved;
//! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls)
size_t map_calls;
} size_use[128];
} rpmalloc_thread_statistics_t;
typedef struct rpmalloc_config_t {
//! Map memory pages for the given number of bytes. The returned address MUST be
// aligned to the rpmalloc span size, which will always be a power of two.
// Optionally the function can store an alignment offset in the offset variable
// in case it performs alignment and the returned pointer is offset from the
// actual start of the memory region due to this alignment. The alignment offset
// will be passed to the memory unmap function. The alignment offset MUST NOT be
// larger than 65535 (storable in an uint16_t), if it is you must use natural
// alignment to shift it into 16 bits. If you set a memory_map function, you
// must also set a memory_unmap function or else the default implementation will
// be used for both.
void* (*memory_map)(size_t size, size_t* offset);
//! Unmap the memory pages starting at address and spanning the given number of bytes.
// If release is set to non-zero, the unmap is for an entire span range as returned by
// a previous call to memory_map and that the entire range should be released. The
// release argument holds the size of the entire span range. If release is set to 0,
// the unmap is a partial decommit of a subset of the mapped memory range.
// If you set a memory_unmap function, you must also set a memory_map function or
// else the default implementation will be used for both.
void (*memory_unmap)(void* address, size_t size, size_t offset, size_t release);
//! Size of memory pages. The page size MUST be a power of two. All memory mapping
// requests to memory_map will be made with size set to a multiple of the page size.
// Used if RPMALLOC_CONFIGURABLE is defined to 1, otherwise system page size is used.
size_t page_size;
//! Size of a span of memory blocks. MUST be a power of two, and in [4096,262144]
// range (unless 0 - set to 0 to use the default span size). Used if RPMALLOC_CONFIGURABLE
// is defined to 1.
size_t span_size;
//! Number of spans to map at each request to map new virtual memory blocks. This can
// be used to minimize the system call overhead at the cost of virtual memory address
// space. The extra mapped pages will not be written until actually used, so physical
// committed memory should not be affected in the default implementation. Will be
// aligned to a multiple of spans that match memory page size in case of huge pages.
size_t span_map_count;
//! Enable use of large/huge pages. If this flag is set to non-zero and page size is
// zero, the allocator will try to enable huge pages and auto detect the configuration.
// If this is set to non-zero and page_size is also non-zero, the allocator will
// assume huge pages have been configured and enabled prior to initializing the
// allocator.
// For Windows, see https://docs.microsoft.com/en-us/windows/desktop/memory/large-page-support
// For Linux, see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
int enable_huge_pages;
} rpmalloc_config_t;
//! Initialize allocator with default configuration
RPMALLOC_EXPORT int
rpmalloc_initialize(void);
//! Initialize allocator with given configuration
RPMALLOC_EXPORT int
rpmalloc_initialize_config(const rpmalloc_config_t* config);
//! Get allocator configuration
RPMALLOC_EXPORT const rpmalloc_config_t*
rpmalloc_config(void);
//! Finalize allocator
RPMALLOC_EXPORT void
rpmalloc_finalize(void);
//! Initialize allocator for calling thread
RPMALLOC_EXPORT void
rpmalloc_thread_initialize(void);
//! Finalize allocator for calling thread
RPMALLOC_EXPORT void
rpmalloc_thread_finalize(void);
//! Perform deferred deallocations pending for the calling thread heap
RPMALLOC_EXPORT void
rpmalloc_thread_collect(void);
//! Query if allocator is initialized for calling thread
RPMALLOC_EXPORT int
rpmalloc_is_thread_initialized(void);
//! Get per-thread statistics
RPMALLOC_EXPORT void
rpmalloc_thread_statistics(rpmalloc_thread_statistics_t* stats);
//! Get global statistics
RPMALLOC_EXPORT void
rpmalloc_global_statistics(rpmalloc_global_statistics_t* stats);
//! Dump all statistics in human readable format to file (should be a FILE*)
RPMALLOC_EXPORT void
rpmalloc_dump_statistics(void* file);
//! Allocate a memory block of at least the given size
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void*
rpmalloc(size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1);
//! Free the given memory block
RPMALLOC_EXPORT void
rpfree(void* ptr);
//! Allocate a memory block of at least the given size and zero initialize it
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void*
rpcalloc(size_t num, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE2(1, 2);
//! Reallocate the given block to at least the given size
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void*
rprealloc(void* ptr, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2);
//! Reallocate the given block to at least the given size and alignment,
// with optional control flags (see RPMALLOC_NO_PRESERVE).
// Alignment must be a power of two and a multiple of sizeof(void*),
// and should ideally be less than memory page size. A caveat of rpmalloc
// internals is that this must also be strictly less than the span size (default 64KiB)
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void*
rpaligned_realloc(void* ptr, size_t alignment, size_t size, size_t oldsize, unsigned int flags) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(3);
//! Allocate a memory block of at least the given size and alignment.
// Alignment must be a power of two and a multiple of sizeof(void*),
// and should ideally be less than memory page size. A caveat of rpmalloc
// internals is that this must also be strictly less than the span size (default 64KiB)
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void*
rpaligned_alloc(size_t alignment, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2);
//! Allocate a memory block of at least the given size and alignment.
// Alignment must be a power of two and a multiple of sizeof(void*),
// and should ideally be less than memory page size. A caveat of rpmalloc
// internals is that this must also be strictly less than the span size (default 64KiB)
RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void*
rpmemalign(size_t alignment, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2);
//! Allocate a memory block of at least the given size and alignment.
// Alignment must be a power of two and a multiple of sizeof(void*),
// and should ideally be less than memory page size. A caveat of rpmalloc
// internals is that this must also be strictly less than the span size (default 64KiB)
RPMALLOC_EXPORT int
rpposix_memalign(void **memptr, size_t alignment, size_t size);
//! Query the usable size of the given memory block (from given pointer to the end of block)
RPMALLOC_EXPORT size_t
rpmalloc_usable_size(void* ptr);
#ifdef __cplusplus
}
#endif
......@@ -2,7 +2,7 @@
* Authors:
* Anatolii Kurotych <akurotych@gmail.com>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved.
......