forked from Green-Sky/tomato
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:
60
toxcore/tox_memory.c
Normal file
60
toxcore/tox_memory.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
#include "tox_memory.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "ccompat.h"
|
||||
#include "tox_memory_impl.h" // IWYU pragma: keep
|
||||
|
||||
Tox_Memory *tox_memory_new(const Tox_Memory_Funcs *funcs, void *user_data)
|
||||
{
|
||||
const Tox_Memory bootstrap = {funcs, user_data};
|
||||
|
||||
Tox_Memory *mem = (Tox_Memory *)tox_memory_alloc(&bootstrap, sizeof(Tox_Memory));
|
||||
|
||||
if (mem == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
*mem = bootstrap;
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
void tox_memory_free(Tox_Memory *mem)
|
||||
{
|
||||
if (mem == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
tox_memory_dealloc(mem, mem);
|
||||
}
|
||||
|
||||
void *tox_memory_malloc(const Tox_Memory *mem, uint32_t size)
|
||||
{
|
||||
void *const ptr = mem->funcs->malloc_callback(mem->user_data, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *tox_memory_alloc(const Tox_Memory *mem, uint32_t size)
|
||||
{
|
||||
void *const ptr = tox_memory_malloc(mem, size);
|
||||
if (ptr != nullptr) {
|
||||
memset(ptr, 0, size);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *tox_memory_realloc(const Tox_Memory *mem, void *ptr, uint32_t size)
|
||||
{
|
||||
void *const new_ptr = mem->funcs->realloc_callback(mem->user_data, ptr, size);
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
void tox_memory_dealloc(const Tox_Memory *mem, void *ptr)
|
||||
{
|
||||
mem->funcs->dealloc_callback(mem->user_data, ptr);
|
||||
}
|
||||
Reference in New Issue
Block a user