Everywhere: Use slon_mem_task for memory allocation
This commit is contained in:
parent
5333b64917
commit
64f31de070
24 changed files with 146 additions and 139 deletions
|
@ -18,7 +18,7 @@ U8* @base64_decode(U8* input, I64* output_length)
|
|||
}
|
||||
|
||||
// Allocate memory for the decoded data
|
||||
U8* decoded_data = CAlloc(*output_length, adam_task);
|
||||
U8* decoded_data = CAlloc(*output_length, slon_mem_task);
|
||||
if (decoded_data == NULL) {
|
||||
return NULL; // Memory allocation failed
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ U8* @base64_encode(U8* input, I64 input_length)
|
|||
I64 i;
|
||||
U8 buf[3];
|
||||
I64 c = 0;
|
||||
U8* output = CAlloc(input_length * 2, adam_task);
|
||||
U8* output = CAlloc(input_length * 2, slon_mem_task);
|
||||
|
||||
for (i = 0; i < input_length; i += 3) {
|
||||
buf[0] = input[i];
|
||||
|
|
|
@ -78,7 +78,7 @@ U8* @http_string_from_fifo(CFifoU8* f)
|
|||
{
|
||||
U8 ch;
|
||||
I64 i = 0;
|
||||
U8* str = CAlloc(FifoU8Cnt(f) + 1, adam_task);
|
||||
U8* str = CAlloc(FifoU8Cnt(f) + 1, slon_mem_task);
|
||||
while (FifoU8Cnt(f)) {
|
||||
FifoU8Rem(f, &ch);
|
||||
str[i] = ch;
|
||||
|
@ -121,22 +121,22 @@ U0 @http_free_response(@http_response* resp)
|
|||
U8 hex[3];
|
||||
I64 i = 0;
|
||||
I64 state = HTTP_PARSE_SCHEME;
|
||||
CFifoU8* consume_fifo = FifoU8New(HTTP_PARSE_URL_FIFO_SIZE, adam_task);
|
||||
@http_url* url = CAlloc(sizeof(@http_url), adam_task);
|
||||
CFifoU8* consume_fifo = FifoU8New(HTTP_PARSE_URL_FIFO_SIZE, slon_mem_task);
|
||||
@http_url* url = CAlloc(sizeof(@http_url), slon_mem_task);
|
||||
while (1) {
|
||||
switch (str[i]) {
|
||||
case 0:
|
||||
switch (state) {
|
||||
case HTTP_PARSE_HOST:
|
||||
url->host = @http_string_from_fifo(consume_fifo);
|
||||
url->path = StrNew("/", adam_task);
|
||||
url->path = StrNew("/", slon_mem_task);
|
||||
goto done_parsing_url;
|
||||
break;
|
||||
case HTTP_PARSE_PORT:
|
||||
buf = @http_string_from_fifo(consume_fifo);
|
||||
url->port = Str2I64(buf);
|
||||
Free(buf);
|
||||
url->path = StrNew("/", adam_task);
|
||||
url->path = StrNew("/", slon_mem_task);
|
||||
goto done_parsing_url;
|
||||
break;
|
||||
case HTTP_PARSE_PATH:
|
||||
|
@ -297,9 +297,9 @@ U0 @http_parse_response_headers(@http_response* resp, U8* buffer, I64 length)
|
|||
(*StrFind(" ", resp_protocol)) = NULL;
|
||||
(*StrFind(" ", resp_status_code)) = NULL;
|
||||
|
||||
resp->status.protocol = StrNew(resp_protocol, adam_task);
|
||||
resp->status.protocol = StrNew(resp_protocol, slon_mem_task);
|
||||
resp->status.code = Str2I64(resp_status_code);
|
||||
resp->status.text = StrNew(resp_text, adam_task);
|
||||
resp->status.text = StrNew(resp_text, slon_mem_task);
|
||||
|
||||
for (i = 1; i < lines_count; i++) {
|
||||
for (j = 0; j < StrLen(lines[i]); j++) {
|
||||
|
@ -308,7 +308,7 @@ U0 @http_parse_response_headers(@http_response* resp, U8* buffer, I64 length)
|
|||
key_ptr = lines[i];
|
||||
value_ptr = lines[i] + j + 2;
|
||||
(*StrFind("\r", value_ptr)) = NULL;
|
||||
Json.Set(headers, key_ptr, StrNew(value_ptr, adam_task), JSON_STRING);
|
||||
Json.Set(headers, key_ptr, StrNew(value_ptr, slon_mem_task), JSON_STRING);
|
||||
goto @http_next_header_line;
|
||||
}
|
||||
}
|
||||
|
@ -350,9 +350,9 @@ I64 @http_req(@http_request* req)
|
|||
I64 cnt = 1;
|
||||
I64 len = NULL;
|
||||
|
||||
buf = CAlloc(HTTP_MIN_REQUEST_BUFFER_SIZE, adam_task);
|
||||
buf = CAlloc(HTTP_MIN_REQUEST_BUFFER_SIZE, slon_mem_task);
|
||||
if (req->headers) {
|
||||
headers_buf = CAlloc(HTTP_MIN_REQUEST_BUFFER_SIZE, adam_task);
|
||||
headers_buf = CAlloc(HTTP_MIN_REQUEST_BUFFER_SIZE, slon_mem_task);
|
||||
JsonKey* key = req->headers->keys;
|
||||
while (key) {
|
||||
StrPrint(headers_buf + StrLen(headers_buf), "%s: %s\r\n", key->name, key->value);
|
||||
|
@ -467,8 +467,8 @@ Bool @http_scheme_is_https(@http_url* url)
|
|||
|
||||
@http_response* @http_get(@http_url* url, U8* buf, U64 return_req = NULL, JsonObject* headers = NULL)
|
||||
{
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), adam_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), adam_task);
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), slon_mem_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), slon_mem_task);
|
||||
if (return_req)
|
||||
MemCpy(return_req, &req, sizeof(U64));
|
||||
req->url = url;
|
||||
|
@ -482,8 +482,8 @@ Bool @http_scheme_is_https(@http_url* url)
|
|||
|
||||
@http_response* @http_head(@http_url* url, U8* buf, JsonObject* headers = NULL)
|
||||
{
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), adam_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), adam_task);
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), slon_mem_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), slon_mem_task);
|
||||
req->url = url;
|
||||
req->buf = buf;
|
||||
req->type = HTTP_REQ_HEAD;
|
||||
|
@ -495,8 +495,8 @@ Bool @http_scheme_is_https(@http_url* url)
|
|||
|
||||
@http_response* @http_post(@http_url* url, U8* buf, U8* data, JsonObject* headers = NULL)
|
||||
{
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), adam_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), adam_task);
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), slon_mem_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), slon_mem_task);
|
||||
req->url = url;
|
||||
req->buf = buf;
|
||||
req->type = HTTP_REQ_POST;
|
||||
|
@ -509,8 +509,8 @@ Bool @http_scheme_is_https(@http_url* url)
|
|||
|
||||
@http_response* @http_put(@http_url* url, U8* buf, U8* data, JsonObject* headers = NULL)
|
||||
{
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), adam_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), adam_task);
|
||||
@http_response* resp = CAlloc(sizeof(@http_response), slon_mem_task);
|
||||
@http_request* req = CAlloc(sizeof(@http_request), slon_mem_task);
|
||||
req->url = url;
|
||||
req->buf = buf;
|
||||
req->type = HTTP_REQ_PUT;
|
||||
|
@ -558,7 +558,7 @@ U0 @http_cache_resource(U8* src, U8* data, I64 size, U8* cache_directory = HTTP_
|
|||
|
||||
U8* @http_get_cached_resource_filename(U8* src, U8* cache_directory = HTTP_CACHE_DIRECTORY)
|
||||
{
|
||||
U8* buf = CAlloc(512, adam_task);
|
||||
U8* buf = CAlloc(512, slon_mem_task);
|
||||
U8* src_md5 = md5_string(src, StrLen(src));
|
||||
StrCpy(buf, cache_directory);
|
||||
StrPrint(buf + StrLen(buf), "/%s", src_md5);
|
||||
|
@ -591,7 +591,7 @@ I64 curl(U8* url_string)
|
|||
{
|
||||
if (!url_string)
|
||||
return 0;
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
@http_response* resp = fetch(url_string, fetch_buffer);
|
||||
if (!resp)
|
||||
return 0;
|
||||
|
@ -614,7 +614,7 @@ I64 download(U8* path, U8* url_string)
|
|||
{
|
||||
if (!path || !url_string)
|
||||
return 0;
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
@http_response* resp = fetch(url_string, fetch_buffer);
|
||||
if (!resp)
|
||||
return 0;
|
||||
|
|
|
@ -181,7 +181,7 @@ U8* @json_string_from_fifo(CFifoU8* f)
|
|||
{
|
||||
U8 ch;
|
||||
I64 i = 0;
|
||||
U8* str = CAlloc(FifoU8Cnt(f) + 1, adam_task);
|
||||
U8* str = CAlloc(FifoU8Cnt(f) + 1, slon_mem_task);
|
||||
while (FifoU8Cnt(f)) {
|
||||
FifoU8Rem(f, &ch);
|
||||
str[i] = ch;
|
||||
|
@ -413,7 +413,7 @@ U0 @json_parse_object(@json_parser* parser, @json_object* obj)
|
|||
parser->state = JSON_STATE_OBJECT_SEPARATOR;
|
||||
break;
|
||||
case JSON_STATE_OBJECT:
|
||||
key = CAlloc(sizeof(@json_key), adam_task);
|
||||
key = CAlloc(sizeof(@json_key), slon_mem_task);
|
||||
key->sig = JSON_SIG;
|
||||
parser->state = JSON_STATE_OBJECT_KEY;
|
||||
break;
|
||||
|
@ -498,7 +498,7 @@ U0 @json_parse_array(@json_parser* parser, @json_array* arr)
|
|||
return;
|
||||
break;
|
||||
}
|
||||
item = CAlloc(sizeof(@json_item), adam_task);
|
||||
item = CAlloc(sizeof(@json_item), slon_mem_task);
|
||||
item->sig = JSON_SIG;
|
||||
parser->state = JSON_STATE_ARRAY_TYPE;
|
||||
}
|
||||
|
@ -707,7 +707,7 @@ extern @json_callable_object* @json_create_callable_object(@json_object* obj);
|
|||
|
||||
@json_element* @json_parse_object_or_array(@json_parser* parser)
|
||||
{
|
||||
@json_element* el = CAlloc(sizeof(@json_element) * 2, adam_task);
|
||||
@json_element* el = CAlloc(sizeof(@json_element) * 2, slon_mem_task);
|
||||
el->sig = JSON_SIG;
|
||||
while (1) {
|
||||
switch (parser->stream[parser->pos]) {
|
||||
|
@ -747,8 +747,8 @@ extern @json_callable_object* @json_create_callable_object(@json_object* obj);
|
|||
|
||||
@json_element* @json_parse(U8* str)
|
||||
{
|
||||
@json_parser* parser = CAlloc(sizeof(@json_parser), adam_task);
|
||||
parser->consumed = FifoU8New(JSON_PARSER_FIFO_SIZE, adam_task);
|
||||
@json_parser* parser = CAlloc(sizeof(@json_parser), slon_mem_task);
|
||||
parser->consumed = FifoU8New(JSON_PARSER_FIFO_SIZE, slon_mem_task);
|
||||
// parser->debug = TRUE;
|
||||
parser->stream = str;
|
||||
@json_element* root = @json_parse_object_or_array(parser);
|
||||
|
@ -1006,9 +1006,9 @@ U0 @json_stringify_object_or_array(@json_stringify_string* str, @json_element* e
|
|||
|
||||
U8* @json_stringify(@json_element* el, I64 buf_size = JSON_STRINGIFY_BUF_SIZE)
|
||||
{
|
||||
// U8* str = CAlloc(buf_size, adam_task);
|
||||
@json_stringify_string* str = CAlloc(sizeof(@json_stringify_string), adam_task);
|
||||
U8* value = CAlloc(buf_size, adam_task);
|
||||
// U8* str = CAlloc(buf_size, slon_mem_task);
|
||||
@json_stringify_string* str = CAlloc(sizeof(@json_stringify_string), slon_mem_task);
|
||||
U8* value = CAlloc(buf_size, slon_mem_task);
|
||||
str->value = value;
|
||||
@json_stringify_object_or_array(str, el);
|
||||
Free(str);
|
||||
|
@ -1049,12 +1049,12 @@ U0 @json_set(@json_object* obj, U8* key, U64 value, I64 type = JSON_SAME)
|
|||
}
|
||||
iter_key = iter_key->next;
|
||||
}
|
||||
@json_key* new_key = CAlloc(sizeof(@json_key), adam_task);
|
||||
@json_key* new_key = CAlloc(sizeof(@json_key), slon_mem_task);
|
||||
new_key->sig = JSON_SIG;
|
||||
new_key->name = StrNew(key, adam_task);
|
||||
new_key->name = StrNew(key, slon_mem_task);
|
||||
new_key->type = type;
|
||||
if (new_key->type == JSON_STRING)
|
||||
new_key->value = StrNew(value, adam_task);
|
||||
new_key->value = StrNew(value, slon_mem_task);
|
||||
else
|
||||
new_key->value = value;
|
||||
@json_insert_key(obj, new_key);
|
||||
|
@ -1102,14 +1102,14 @@ U0 @json_callable_object_unset_wrapper_function(U8* key)
|
|||
@json_callable_object* @json_create_callable_object(@json_object* obj)
|
||||
{
|
||||
// Alloc callable object and copy instance
|
||||
@json_callable_object* cobj = CAlloc(sizeof(@json_callable_object), adam_task);
|
||||
@json_callable_object* cobj = CAlloc(sizeof(@json_callable_object), slon_mem_task);
|
||||
cobj->sig = JSON_SIG;
|
||||
MemCpy(cobj, obj, sizeof(@json_object));
|
||||
|
||||
// Create a copy of function and patch Get
|
||||
U64 a;
|
||||
I64 code_size = MSize(&@json_callable_object_get_wrapper_function);
|
||||
cobj->@ = CAlloc(code_size, adam_task->code_heap);
|
||||
cobj->@ = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(cobj->@, &@json_callable_object_get_wrapper_function, code_size);
|
||||
|
||||
a = cobj->@;
|
||||
|
@ -1122,7 +1122,7 @@ U0 @json_callable_object_unset_wrapper_function(U8* key)
|
|||
|
||||
// Create a copy of function and patch Set
|
||||
code_size = MSize(&@json_callable_object_set_wrapper_function);
|
||||
cobj->set = CAlloc(code_size, adam_task->code_heap);
|
||||
cobj->set = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(cobj->set, &@json_callable_object_set_wrapper_function, code_size);
|
||||
|
||||
a = cobj->set;
|
||||
|
@ -1135,7 +1135,7 @@ U0 @json_callable_object_unset_wrapper_function(U8* key)
|
|||
|
||||
// Create a copy of function and patch Unset
|
||||
code_size = MSize(&@json_callable_object_unset_wrapper_function);
|
||||
cobj->unset = CAlloc(code_size, adam_task->code_heap);
|
||||
cobj->unset = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(cobj->unset, &@json_callable_object_unset_wrapper_function, code_size);
|
||||
|
||||
a = cobj->unset;
|
||||
|
@ -1154,7 +1154,7 @@ U0 @json_callable_object_unset_wrapper_function(U8* key)
|
|||
|
||||
@json_callable_object* @json_create_object()
|
||||
{
|
||||
@json_object* obj = CAlloc(sizeof(@json_object), adam_task);
|
||||
@json_object* obj = CAlloc(sizeof(@json_object), slon_mem_task);
|
||||
obj->sig = JSON_SIG;
|
||||
obj->type = JSON_OBJECT;
|
||||
return @json_create_callable_object(obj);
|
||||
|
@ -1162,11 +1162,11 @@ U0 @json_callable_object_unset_wrapper_function(U8* key)
|
|||
|
||||
@json_item* @json_create_item(U64 value, I64 type)
|
||||
{
|
||||
@json_item* item = CAlloc(sizeof(@json_item), adam_task);
|
||||
@json_item* item = CAlloc(sizeof(@json_item), slon_mem_task);
|
||||
item->sig = JSON_SIG;
|
||||
item->type = type;
|
||||
if (item->type == JSON_STRING)
|
||||
item->value = StrNew(value, adam_task);
|
||||
item->value = StrNew(value, slon_mem_task);
|
||||
else
|
||||
item->value = value;
|
||||
return item;
|
||||
|
@ -1259,14 +1259,14 @@ U0 @json_callable_array_remove_wrapper_function(I64 index)
|
|||
@json_callable_array* @json_create_callable_array(@json_array* arr)
|
||||
{
|
||||
// Alloc callable object and copy instance
|
||||
@json_callable_array* carr = CAlloc(sizeof(@json_callable_array), adam_task);
|
||||
@json_callable_array* carr = CAlloc(sizeof(@json_callable_array), slon_mem_task);
|
||||
carr->sig = JSON_SIG;
|
||||
MemCpy(carr, arr, sizeof(@json_array));
|
||||
|
||||
// Create a copy of function and patch Index
|
||||
U64 a;
|
||||
I64 code_size = MSize(&@json_callable_array_index_wrapper_function);
|
||||
carr->@ = CAlloc(code_size, adam_task->code_heap);
|
||||
carr->@ = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(carr->@, &@json_callable_array_index_wrapper_function, code_size);
|
||||
|
||||
a = carr->@;
|
||||
|
@ -1282,7 +1282,7 @@ U0 @json_callable_array_remove_wrapper_function(I64 index)
|
|||
|
||||
// Create a copy of function and patch Append
|
||||
code_size = MSize(&@json_callable_array_append_wrapper_function);
|
||||
carr->append = CAlloc(code_size, adam_task->code_heap);
|
||||
carr->append = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(carr->append, &@json_callable_array_append_wrapper_function, code_size);
|
||||
|
||||
a = carr->append;
|
||||
|
@ -1295,7 +1295,7 @@ U0 @json_callable_array_remove_wrapper_function(I64 index)
|
|||
|
||||
// Create a copy of function and patch Prepend
|
||||
code_size = MSize(&@json_callable_array_prepend_wrapper_function);
|
||||
carr->prepend = CAlloc(code_size, adam_task->code_heap);
|
||||
carr->prepend = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(carr->prepend, &@json_callable_array_prepend_wrapper_function, code_size);
|
||||
|
||||
a = carr->prepend;
|
||||
|
@ -1308,7 +1308,7 @@ U0 @json_callable_array_remove_wrapper_function(I64 index)
|
|||
|
||||
// Create a copy of function and patch Insert
|
||||
code_size = MSize(&@json_callable_array_insert_wrapper_function);
|
||||
carr->insert = CAlloc(code_size, adam_task->code_heap);
|
||||
carr->insert = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(carr->insert, &@json_callable_array_insert_wrapper_function, code_size);
|
||||
|
||||
a = carr->insert;
|
||||
|
@ -1321,7 +1321,7 @@ U0 @json_callable_array_remove_wrapper_function(I64 index)
|
|||
|
||||
// Create a copy of function and patch Remove
|
||||
code_size = MSize(&@json_callable_array_remove_wrapper_function);
|
||||
carr->remove = CAlloc(code_size, adam_task->code_heap);
|
||||
carr->remove = CAlloc(code_size, slon_mem_task->code_heap);
|
||||
MemCpy(carr->remove, &@json_callable_array_remove_wrapper_function, code_size);
|
||||
|
||||
a = carr->remove;
|
||||
|
@ -1337,7 +1337,7 @@ U0 @json_callable_array_remove_wrapper_function(I64 index)
|
|||
|
||||
@json_array* @json_create_array()
|
||||
{
|
||||
@json_array* arr = CAlloc(sizeof(@json_array), adam_task);
|
||||
@json_array* arr = CAlloc(sizeof(@json_array), slon_mem_task);
|
||||
arr->sig = JSON_SIG;
|
||||
arr->type = JSON_ARRAY;
|
||||
return @json_create_callable_array(arr);
|
||||
|
|
|
@ -8,7 +8,7 @@ U0 @string_append(U8* dst, U8* fmt, ...)
|
|||
if (argc) {
|
||||
buf = StrPrintJoin(NULL, fmt, argc, argv);
|
||||
} else {
|
||||
buf = StrNew(fmt, adam_task);
|
||||
buf = StrNew(fmt, slon_mem_task);
|
||||
}
|
||||
U8* src = buf;
|
||||
StrCpy(dst + StrLen(dst), src);
|
||||
|
@ -53,7 +53,7 @@ Bool @string_ends_with(U8* fragment, U8* str)
|
|||
U8* @string_replace(U8* s, U8* oldW, U8* newW)
|
||||
{
|
||||
if (!StrFind(oldW, s)) {
|
||||
return StrNew(s, adam_task);
|
||||
return StrNew(s, slon_mem_task);
|
||||
}
|
||||
U8* result;
|
||||
I64 i, cnt = 0;
|
||||
|
@ -66,7 +66,7 @@ U8* @string_replace(U8* s, U8* oldW, U8* newW)
|
|||
i += oldWlen - 1;
|
||||
}
|
||||
}
|
||||
result = MAlloc(i + cnt * (newWlen - oldWlen) + 1, adam_task);
|
||||
result = MAlloc(i + cnt * (newWlen - oldWlen) + 1, slon_mem_task);
|
||||
i = 0;
|
||||
while (*s) {
|
||||
if (StrFind(oldW, s) == s) {
|
||||
|
@ -85,7 +85,7 @@ U8** @string_split(U8* s, U8 ch = '\n', I64* cnt)
|
|||
U8 check_buf[4];
|
||||
StrPrint(check_buf, "%c", ch);
|
||||
if (!StrFind(check_buf, s)) {
|
||||
U8** same_arr = CAlloc(sizeof(U8*) * 1, adam_task);
|
||||
U8** same_arr = CAlloc(sizeof(U8*) * 1, slon_mem_task);
|
||||
same_arr[0] = s;
|
||||
*cnt = 1;
|
||||
return same_arr;
|
||||
|
@ -101,7 +101,7 @@ U8** @string_split(U8* s, U8 ch = '\n', I64* cnt)
|
|||
return NULL;
|
||||
cnt[0]++;
|
||||
I64 i = -1;
|
||||
U8** arr = CAlloc(sizeof(U8*) * cnt[0], adam_task);
|
||||
U8** arr = CAlloc(sizeof(U8*) * cnt[0], slon_mem_task);
|
||||
p = s;
|
||||
while (*p) {
|
||||
if (*p == ch || i < 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue