Update primitives
This commit is contained in:
parent
09e96f8112
commit
12e8515b27
@ -54,10 +54,6 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
common_includes: List[CInclude] = [
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", out_dir)).replace("\\", "/"),
|
||||
local=True,
|
||||
),
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "mem_allocator" / "mem_allocator.h", out_dir)).replace("\\", "/"),
|
||||
local=True,
|
||||
@ -108,11 +104,11 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
|
||||
decl_types=[*common_decl_types],
|
||||
includes=[
|
||||
CInclude(header, local=True, same_dir=True),
|
||||
CInclude(header="stddef.h"),
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "assert" / "assert.h", out_dir)).replace("\\", "/"),
|
||||
local=True
|
||||
),
|
||||
CInclude(header="stddef.h"),
|
||||
],
|
||||
internal_funcs=[],
|
||||
funcs=header.funcs
|
||||
|
@ -56,13 +56,6 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
out_dir = WAPP_SRC_ROOT / "primitives" / "dbl_list"
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
common_includes: List[CInclude] = [
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", out_dir)).replace("\\", "/"),
|
||||
local=True,
|
||||
)
|
||||
]
|
||||
|
||||
common_decl_types: List[CStruct] = []
|
||||
|
||||
datatypes: dict[CDataType, DblListData] = {
|
||||
@ -111,16 +104,11 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
local=True
|
||||
),
|
||||
CInclude(header="stddef.h"),
|
||||
CInclude(header="assert.h"),
|
||||
],
|
||||
internal_funcs=[],
|
||||
funcs=header.funcs
|
||||
)
|
||||
|
||||
if len(common_includes) > 0:
|
||||
header.includes.extend(common_includes)
|
||||
source.includes.extend(common_includes)
|
||||
|
||||
for _type, dbl_list_data in datatypes.items():
|
||||
type_string = get_datatype_string(_type)
|
||||
clean_type_string = type_string.replace(" ", "").replace("*", "_ptr")
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "./array.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../mem_allocator/mem_allocator.h"
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
@ -5,7 +5,6 @@
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../mem_allocator/mem_allocator.h"
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
@ -5,10 +5,8 @@
|
||||
#include "./dbl_list.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
|
||||
internal Str8List str8_node_to_list(Str8Node *node);
|
||||
internal VoidPList void_ptr_node_to_list(VoidPNode *node);
|
||||
|
@ -5,7 +5,6 @@
|
||||
#ifndef DBL_LIST_H
|
||||
#define DBL_LIST_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
|
||||
|
@ -163,7 +163,7 @@ Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src)
|
||||
u64 remaining = dst->capacity - dst->size;
|
||||
if (src->size <= remaining) {
|
||||
output = dst;
|
||||
goto COPY_STRING_STR8_CONCAT;
|
||||
goto SOURCE_STRING_STR8_CONCAT;
|
||||
}
|
||||
|
||||
u64 capacity = dst->capacity + src->size;
|
||||
@ -175,13 +175,60 @@ Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src)
|
||||
|
||||
wapp_str8_concat_capped(output, dst);
|
||||
|
||||
COPY_STRING_STR8_CONCAT:
|
||||
SOURCE_STRING_STR8_CONCAT:
|
||||
wapp_str8_concat_capped(output, src);
|
||||
|
||||
RETURN_STR8_CONCAT:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_copy_cstr(const Allocator *allocator, Str8 *dst, const char *src) {
|
||||
wapp_debug_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
|
||||
Str8 *output = NULL;
|
||||
u64 size = strlen(src);
|
||||
if (size <= dst->capacity) {
|
||||
output = dst;
|
||||
goto SOURCE_CSTRING_STR8_COPY;
|
||||
}
|
||||
|
||||
u64 capacity = dst->capacity + size;
|
||||
|
||||
output = wapp_str8_alloc_buf(allocator, capacity);
|
||||
if (!output) {
|
||||
goto RETURN_CSTRING_STR8_COPY;
|
||||
}
|
||||
|
||||
SOURCE_CSTRING_STR8_COPY:
|
||||
wapp_str8_copy_cstr_capped(output, src);
|
||||
|
||||
RETURN_CSTRING_STR8_COPY:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_copy_str8(const Allocator *allocator, Str8 *dst, Str8RO *src) {
|
||||
wapp_debug_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
|
||||
Str8 *output = NULL;
|
||||
if (src->size <= dst->capacity) {
|
||||
output = dst;
|
||||
goto SOURCE_STRING_STR8_COPY;
|
||||
}
|
||||
|
||||
u64 capacity = dst->capacity + src->size;
|
||||
|
||||
output = wapp_str8_alloc_buf(allocator, capacity);
|
||||
if (!output) {
|
||||
goto RETURN_STRING_STR8_COPY;
|
||||
}
|
||||
|
||||
SOURCE_STRING_STR8_COPY:
|
||||
wapp_str8_copy_str8_capped(output, src);
|
||||
|
||||
RETURN_STRING_STR8_COPY:
|
||||
return output;
|
||||
}
|
||||
|
||||
void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
|
||||
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
|
||||
|
@ -79,6 +79,8 @@ Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str);
|
||||
Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str);
|
||||
Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end);
|
||||
Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src);
|
||||
Str8 *wapp_str8_alloc_copy_cstr(const Allocator *allocator, Str8 *dst, const char *src);
|
||||
Str8 *wapp_str8_alloc_copy_str8(const Allocator *allocator, Str8 *dst, Str8RO *src);
|
||||
// Only needed for allocators like malloc where each allocation has to be freed on its own.
|
||||
// No need to use it for allocators like Arena.
|
||||
void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str);
|
||||
|
Loading…
x
Reference in New Issue
Block a user