Squashed 'external/toxcore/c-toxcore/' changes from 640e6cace..e58eb27a8

e58eb27a8 fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.
206ea3530 refactor: Explicitly pass dependencies to constructors.
7cefa93cf fix(toxencryptsave): Wipe salt and passkey after usage.
7c3be2342 refactor: Add file/line to tox-bootstrapd logging.
f84e8cdce refactor: Move loglogdata out of network.c.
390f7db06 refactor: Move random and memory OS-specifics to `os_*` files.
REVERT: 640e6cace fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: e58eb27a84f9fa0cd996868e079f39e90a5c04b6
This commit is contained in:
Green Sky
2025-11-04 21:18:05 +01:00
parent 54c0a3c874
commit 596ea37298
117 changed files with 1409 additions and 697 deletions

View File

@@ -5,59 +5,29 @@
#include "mem.h"
#include <stdlib.h>
#include <string.h>
#include "attributes.h"
#include "ccompat.h"
static void *sys_malloc(void *_Nullable obj, uint32_t size)
{
return malloc(size);
}
static void *sys_calloc(void *_Nullable obj, uint32_t nmemb, uint32_t size)
{
return calloc(nmemb, size);
}
static void *sys_realloc(void *_Nullable obj, void *_Nullable ptr, uint32_t size)
{
return realloc(ptr, size);
}
static void sys_free(void *_Nullable obj, void *_Nullable ptr)
{
free(ptr);
}
static const Memory_Funcs os_memory_funcs = {
sys_malloc,
sys_calloc,
sys_realloc,
sys_free,
};
static const Memory os_memory_obj = {&os_memory_funcs};
const Memory *os_memory(void)
{
return &os_memory_obj;
}
#include "tox_memory.h"
void *mem_balloc(const Memory *mem, uint32_t size)
{
void *const ptr = mem->funcs->malloc(mem->obj, size);
void *const ptr = tox_memory_malloc(mem, size);
return ptr;
}
void *mem_brealloc(const Memory *mem, void *ptr, uint32_t size)
{
void *const new_ptr = mem->funcs->realloc(mem->obj, ptr, size);
void *const new_ptr = tox_memory_realloc(mem, ptr, size);
return new_ptr;
}
void *mem_alloc(const Memory *mem, uint32_t size)
{
void *const ptr = mem->funcs->calloc(mem->obj, 1, size);
void *const ptr = tox_memory_malloc(mem, size);
if (ptr != nullptr) {
memset(ptr, 0, size);
}
return ptr;
}
@@ -69,7 +39,10 @@ void *mem_valloc(const Memory *mem, uint32_t nmemb, uint32_t size)
return nullptr;
}
void *const ptr = mem->funcs->calloc(mem->obj, nmemb, size);
void *const ptr = tox_memory_malloc(mem, bytes);
if (ptr != nullptr) {
memset(ptr, 0, bytes);
}
return ptr;
}
@@ -81,11 +54,11 @@ void *mem_vrealloc(const Memory *mem, void *ptr, uint32_t nmemb, uint32_t size)
return nullptr;
}
void *const new_ptr = mem->funcs->realloc(mem->obj, ptr, bytes);
void *const new_ptr = tox_memory_realloc(mem, ptr, bytes);
return new_ptr;
}
void mem_delete(const Memory *mem, void *ptr)
{
mem->funcs->free(mem->obj, ptr);
tox_memory_dealloc(mem, ptr);
}