Everywhere: Use slon_mem_task for memory allocation

This commit is contained in:
Alec Murphy 2025-03-06 09:54:26 -05:00
parent 5333b64917
commit 64f31de070
24 changed files with 146 additions and 139 deletions

View file

@ -13,7 +13,7 @@ U32 @dns_query(U8* host)
if (!host)
return U32_MAX;
DnsRequest* request = CAlloc(sizeof(DnsRequest), Fs->code_heap);
request->host = StrNew(host, adam_task);
request->host = StrNew(host, slon_mem_task);
request->pointer_to_u32 = &res;
U64* request_ptr = DNS_REQUEST_PTR;
while (*request_ptr)

View file

@ -60,8 +60,8 @@ U0 md5(U8* initial_msg, U32 initial_len, U32* md5_h)
;
new_len /= 8;
msg = CAlloc(new_len + 64, adam_task); // also appends "0" bits
// (we alloc also 64 extra bytes...)
msg = CAlloc(new_len + 64, slon_mem_task); // also appends "0" bits
// (we alloc also 64 extra bytes...)
MemCpy(msg, initial_msg, initial_len);
msg[initial_len] = 128; // write the "1" bit
@ -131,7 +131,7 @@ U8* md5_string(U8* buf, I64 size)
{
U32 md5_h[4];
md5(buf, size, &md5_h[0]);
U8* str = CAlloc(33, adam_task);
U8* str = CAlloc(33, slon_mem_task);
StrPrint(str + StrLen(str), "%02x%02x%02x%02x", md5_h[0].u8[0],
md5_h[0].u8[1], md5_h[0].u8[2], md5_h[0].u8[3]);
StrPrint(str + StrLen(str), "%02x%02x%02x%02x", md5_h[1].u8[0],

View file

@ -112,13 +112,13 @@ U0 @tcp_socket_close(TcpSocket* s)
TcpSocket* @tcp_socket_create(U8* host, U64 port)
{
U64 addr = @dns_query(host);
TcpSocket* s = CAlloc(sizeof(TcpSocket), adam_task->code_heap);
TcpSocket* s = CAlloc(sizeof(TcpSocket), slon_mem_task->code_heap);
s->remote_addr = addr;
s->remote_port = port;
U64 a;
s->close = MAlloc(16, adam_task->code_heap);
s->close = MAlloc(16, slon_mem_task->code_heap);
MemCpy(s->close, @tcp_close_wrapper_function, 16);
a = s->close;
a += 0x05;
@ -127,7 +127,7 @@ TcpSocket* @tcp_socket_create(U8* host, U64 port)
a += 0x09;
@patch_call_rel32(a, &@tcp_socket_close);
s->receive = MAlloc(25, adam_task->code_heap);
s->receive = MAlloc(25, slon_mem_task->code_heap);
MemCpy(s->receive, @tcp_receive_wrapper_function, 32);
a = s->receive;
a += 0x11;
@ -136,7 +136,7 @@ TcpSocket* @tcp_socket_create(U8* host, U64 port)
a += 0x15;
@patch_call_rel32(a, &@tcp_socket_receive);
s->send = MAlloc(32, adam_task->code_heap);
s->send = MAlloc(32, slon_mem_task->code_heap);
MemCpy(s->send, @tcp_send_wrapper_function, 32);
a = s->send;
a += 0x11;
@ -157,7 +157,7 @@ U64 @tcp_socket_bind(U64 port, U64 function)
if (!port || !function)
return NULL;
TcpBind* b = CAlloc(sizeof(TcpBind), adam_task->code_heap);
TcpBind* b = CAlloc(sizeof(TcpBind), slon_mem_task->code_heap);
b->port = port;
b->function = function; // U0 my_spawn_wrapper_function(TcpSocket* s)
@ -179,7 +179,7 @@ TcpSocket* @tcp_socket_accept(TcpSocket* s)
U64 a;
s->close = MAlloc(16, adam_task->code_heap);
s->close = MAlloc(16, slon_mem_task->code_heap);
MemCpy(s->close, @tcp_close_wrapper_function, 16);
a = s->close;
a += 0x05;
@ -188,7 +188,7 @@ TcpSocket* @tcp_socket_accept(TcpSocket* s)
a += 0x09;
@patch_call_rel32(a, &@tcp_socket_close);
s->receive = MAlloc(25, adam_task->code_heap);
s->receive = MAlloc(25, slon_mem_task->code_heap);
MemCpy(s->receive, @tcp_receive_wrapper_function, 32);
a = s->receive;
a += 0x11;
@ -197,7 +197,7 @@ TcpSocket* @tcp_socket_accept(TcpSocket* s)
a += 0x15;
@patch_call_rel32(a, &@tcp_socket_receive);
s->send = MAlloc(32, adam_task->code_heap);
s->send = MAlloc(32, slon_mem_task->code_heap);
MemCpy(s->send, @tcp_send_wrapper_function, 32);
a = s->send;
a += 0x11;

View file

@ -50,13 +50,13 @@ U0 @tls12_connect(TlsSocket* s)
TlsSocket* @tls_socket_create(U8* server_name, U64 port = 443)
{
U64 addr = @dns_query(server_name);
TlsSocket* s = CAlloc(sizeof(TlsSocket), adam_task->code_heap);
TlsSocket* s = CAlloc(sizeof(TlsSocket), slon_mem_task->code_heap);
s->remote_addr = addr;
s->remote_port = port;
U64 a;
s->close = MAlloc(16, adam_task->code_heap);
s->close = MAlloc(16, slon_mem_task->code_heap);
MemCpy(s->close, @tcp_close_wrapper_function, 16);
a = s->close;
a += 0x05;
@ -65,7 +65,7 @@ TlsSocket* @tls_socket_create(U8* server_name, U64 port = 443)
a += 0x09;
@patch_call_rel32(a, &@tcp_socket_close);
s->receive = MAlloc(25, adam_task->code_heap);
s->receive = MAlloc(25, slon_mem_task->code_heap);
MemCpy(s->receive, @tcp_receive_wrapper_function, 32);
a = s->receive;
a += 0x11;
@ -74,7 +74,7 @@ TlsSocket* @tls_socket_create(U8* server_name, U64 port = 443)
a += 0x15;
@patch_call_rel32(a, &@tls_socket_receive);
s->send = MAlloc(32, adam_task->code_heap);
s->send = MAlloc(32, slon_mem_task->code_heap);
MemCpy(s->send, @tcp_send_wrapper_function, 32);
a = s->send;
a += 0x11;
@ -92,7 +92,7 @@ TlsSocket* @tls_socket_create(U8* server_name, U64 port = 443)
Sleep(1);
s->ctx = @tls_create_context(0, TLS_V12);
@tls_sni_set(s->ctx, StrNew(server_name, adam_task->code_heap));
@tls_sni_set(s->ctx, StrNew(server_name, slon_mem_task->code_heap));
Spawn(&@tls12_connect, s, , , , TLS_CONNECT_TASK_STACK_SIZE);
return s;

View file

@ -138,7 +138,7 @@ I64 VirtioBlkInit()
// Set up virt queue
OutU16(virtio_blk.port + VIRTIO_PCI_QUEUE_SEL, 0);
virtio_blk.vq_size = InU16(virtio_blk.port + VIRTIO_PCI_QUEUE_SIZE); // 256
virtio_blk.vq = CAllocAligned(sizeof(@virtio_queue), 4096, adam_task->code_heap);
virtio_blk.vq = CAllocAligned(sizeof(@virtio_queue), 4096, slon_mem_task->code_heap);
OutU32(virtio_blk.port + VIRTIO_PCI_QUEUE_PFN, virtio_blk.vq / 4096);
// Init OK
@ -152,7 +152,7 @@ U0 VIOFlush()
{
I64 j;
I64 vq_idx;
@virtio_blk_request* brq = CAlloc(sizeof(@virtio_blk_request), adam_task);
@virtio_blk_request* brq = CAlloc(sizeof(@virtio_blk_request), slon_mem_task);
brq->type = VIRTIO_BLK_T_FLUSH;
brq->sector = NULL;
vq_idx = virtio_blk.vq->available.index % 256;
@ -181,7 +181,7 @@ Bool VIORBlks(CDrv* dv, U8* buf, I64 blk, I64 cnt)
I64 i, j;
I64 vq_idx;
U64 addr;
@virtio_blk_request* brq = CAlloc(sizeof(@virtio_blk_request), adam_task);
@virtio_blk_request* brq = CAlloc(sizeof(@virtio_blk_request), slon_mem_task);
for (i = 0; i < cnt; i++) {
brq->type = VIRTIO_BLK_T_IN;
brq->sector = blk + i;
@ -218,7 +218,7 @@ Bool VIOWBlks(CDrv* dv, U8* buf, I64 blk, I64 cnt)
I64 i, j;
I64 vq_idx;
U64 addr;
@virtio_blk_request* brq = CAlloc(sizeof(@virtio_blk_request), adam_task);
@virtio_blk_request* brq = CAlloc(sizeof(@virtio_blk_request), slon_mem_task);
for (i = 0; i < cnt; i++) {
brq->type = VIRTIO_BLK_T_OUT;
brq->sector = blk + i;
@ -277,7 +277,7 @@ U8 MountVirtioBlk()
{ // Mount Virtio-blk device
CDrv* dv = DrvMakeFreeSlot(DrvNextFreeLet('A'));
CBlkDev* bd = BlkDevNextFreeSlot(dv->drv_let, BDT_RAM);
CRedSeaBoot* bs = CAlloc(BLK_SIZE, adam_task);
CRedSeaBoot* bs = CAlloc(BLK_SIZE, slon_mem_task);
bd->max_blk = 512;
BlkDevAdd(bd, , TRUE, TRUE);
bd->type = BDT_VIRTIO_BLK;

View file

@ -244,7 +244,7 @@ U0 process_elf_rela_plt_entries(Elf* elf)
for (i = 0; i < elf->rela_plt_size; i++) {
symbol_exists = FALSE;
entry_name = elf->dynstr + elf->dynsym[(rela_plt->r_info >> 32)].st_name;
handler = MAlloc(sizeof(unimplemented_symbol), adam_task->code_heap);
handler = MAlloc(sizeof(unimplemented_symbol), slon_mem_task->code_heap);
MemCpy(handler, &unimplemented_symbol, sizeof(unimplemented_symbol));
patch = handler + 0x0A;
*patch = entry_name;

View file

@ -14,7 +14,7 @@ U0 calloc()
{
PUSH_SYSV_REGS
GET_SYSV_ARGS
CAlloc(p0 * p1, adam_task->code_heap);
CAlloc(p0 * p1, slon_mem_task->code_heap);
POP_SYSV_REGS
}
@ -46,7 +46,7 @@ I64 @fwrite(U8* ptr, I64 size, I64 nmemb, U64 stream)
switch (stream) {
case stdout:
case stderr:
tmp = CAlloc((size * nmemb) + 1, adam_task->code_heap);
tmp = CAlloc((size * nmemb) + 1, slon_mem_task->code_heap);
MemCpy(tmp, ptr, (size * nmemb));
#ifdef QEMU_RUN_TESTS
QemuDebugMsg(tmp);
@ -122,7 +122,7 @@ U0 malloc()
{
PUSH_SYSV_REGS
GET_SYSV_ARGS
MAlloc(p0, adam_task->code_heap);
MAlloc(p0, slon_mem_task->code_heap);
POP_SYSV_REGS
}
@ -207,9 +207,9 @@ U8* @realloc(U8* ptr, I64 size)
{
U8* new;
if (!ptr) {
new = MAlloc(size, adam_task->code_heap);
new = MAlloc(size, slon_mem_task->code_heap);
} else {
new = MAlloc(size, adam_task->code_heap);
new = MAlloc(size, slon_mem_task->code_heap);
MemCpy(new, ptr, size);
Free(ptr);
}

View file

@ -21,7 +21,7 @@ U0 _Znwm()
// operator new(unsigned long)
PUSH_SYSV_REGS
GET_SYSV_ARGS
MAlloc(p0, adam_task);
MAlloc(p0, slon_mem_task);
POP_SYSV_REGS
}
@ -30,6 +30,6 @@ U0 _ZnwmRKSt9nothrow_t()
// operator new(unsigned long, std::nothrow_t const&)
PUSH_SYSV_REGS
GET_SYSV_ARGS
MAlloc(p0, adam_task);
MAlloc(p0, slon_mem_task);
POP_SYSV_REGS
}

View file

@ -39,7 +39,7 @@ U0 _Z16os_device_callocj()
// os_device_calloc(unsigned int)
PUSH_SYSV_REGS
GET_SYSV_ARGS
CAllocAligned(p0, 4096, adam_task->code_heap);
CAllocAligned(p0, 4096, slon_mem_task->code_heap);
POP_SYSV_REGS
}
@ -54,7 +54,7 @@ U0 _Z7os_exitv()
U8* @os_file_picker(U8* path, U8* glob)
{
U8* full_path = CAlloc(StrLen(path) + StrLen(glob) + 4, adam_task);
U8* full_path = CAlloc(StrLen(path) + StrLen(glob) + 4, slon_mem_task);
CatPrint(full_path, "%s/%s", path, glob);
CDirEntry* de = FilesFind(full_path);
@ -72,7 +72,7 @@ U8* @os_file_picker(U8* path, U8* glob)
tmpde = tmpde->next;
}
file_list = CAlloc(list_size, adam_task);
file_list = CAlloc(list_size, slon_mem_task);
tmpde = de;
while (tmpde) {
@ -87,13 +87,13 @@ U8* @os_file_picker(U8* path, U8* glob)
if (list_index < 0) {
DirTreeDel(de);
return StrNew("", adam_task);
return StrNew("", slon_mem_task);
}
tmpde = de;
while (tmpde) {
if (list_index == list_pos) {
selected_file = CAlloc(StrLen(path) + StrLen(tmpde->name) + 4, adam_task);
selected_file = CAlloc(StrLen(path) + StrLen(tmpde->name) + 4, slon_mem_task);
CatPrint(selected_file, "%s/%s", path, tmpde->name);
break;
}
@ -117,7 +117,7 @@ U0 _Z14os_file_pickerPKcS0_()
U8* @os_files_list(U8* path)
{
U8* full_path = CAlloc(StrLen(path) + 4, adam_task);
U8* full_path = CAlloc(StrLen(path) + 4, slon_mem_task);
CatPrint(full_path, "%s", path);
CDirEntry* de = FilesFind(full_path);
@ -138,7 +138,7 @@ U8* @os_files_list(U8* path)
if (!list_size)
return NULL;
file_list = CAlloc(list_size, adam_task);
file_list = CAlloc(list_size, slon_mem_task);
tmpde = de;
I64 counter = 0;
@ -243,7 +243,7 @@ U0 _Z19os_read_entire_filePKcPl()
U0 @os_screenshot()
{
CDC* dc = DCScrnCapture(, adam_task);
CDC* dc = DCScrnCapture(, slon_mem_task);
Image.Write("B:/screenshot.png", dc);
DCDel(dc);
}
@ -263,7 +263,7 @@ U8* @os_to_uppercase(U8* instr)
return NULL;
if (!StrLen(instr))
return NULL;
U8* outstr = CAlloc(StrLen(instr) + 1, adam_task);
U8* outstr = CAlloc(StrLen(instr) + 1, slon_mem_task);
I64 i;
for (i = 0; i < StrLen(instr); i++)
outstr[i] = ToUpper(instr[i]);

View file

@ -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];

View file

@ -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;

View file

@ -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);

View file

@ -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) {

View file

@ -1,5 +1,12 @@
/* clang-format off */
U0 @slon_mem_task_loop()
{
while(1){Sleep(1);};
}
CTask* slon_mem_task = Spawn(&@slon_mem_task_loop,, "SlonMemTask");
DocMax(adam_task);
WinMax(adam_task);
WinToTop(adam_task);

View file

@ -288,7 +288,7 @@ U32* @image_get_rgba_buffer_from_dc_body(CDC* dc)
{
if (!dc)
return NULL;
U32* pixels = CAlloc((dc->width * dc->height) * 4, adam_task);
U32* pixels = CAlloc((dc->width * dc->height) * 4, slon_mem_task);
I64 x;
I64 y;
I64 p = 0;
@ -368,12 +368,12 @@ CDC* @image_from_buffer(U8* buffer, I64 len)
PopUpOk(@stbi_failure_reason);
if (!z)
return NULL; // no frames?
@image_collection* collection = CAlloc(sizeof(@image_collection), adam_task);
@image_collection* collection = CAlloc(sizeof(@image_collection), slon_mem_task);
@image_frame* frame;
collection->frames = CAlloc(sizeof(@image_frame*) * z, adam_task);
collection->frames = CAlloc(sizeof(@image_frame*) * z, slon_mem_task);
collection->count = z;
for (i = 0; i < z; i++) {
frame = CAlloc(sizeof(@image_frame), adam_task);
frame = CAlloc(sizeof(@image_frame), slon_mem_task);
frame->dc = @image_generate_dc_from_pixels(pixels, x, y);
frame->sprite = DC2Sprite(frame->dc);
frame->delay = delays[i];