aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2022-05-30 15:35:21 +0200
committerGitHub <noreply@github.com>2022-05-30 15:35:21 +0200
commit2bd14a389008b87d24706801fb5e40141d928087 (patch)
tree5fddaf955ca90f163e5c1aeb33101f236258c9b2
parente79c1e55ace947a41fa55fcc1aa79570c05b069e (diff)
Language bindings: fix new allocator callbacks (#671)
* remove typedef indirection for allocator callback functions * language bindings: fix allocator bindings * language bindings: replace FIXMEs and ??? with actual errors
-rw-r--r--bindgen/gen_nim.py14
-rw-r--r--bindgen/gen_zig.py20
-rw-r--r--sokol_app.h7
-rw-r--r--sokol_args.h7
-rw-r--r--sokol_audio.h7
-rw-r--r--sokol_fetch.h7
-rw-r--r--sokol_gfx.h7
-rw-r--r--util/sokol_debugtext.h7
-rw-r--r--util/sokol_fontstash.h7
-rw-r--r--util/sokol_gfx_imgui.h7
-rw-r--r--util/sokol_gl.h7
-rw-r--r--util/sokol_imgui.h7
12 files changed, 32 insertions, 72 deletions
diff --git a/bindgen/gen_nim.py b/bindgen/gen_nim.py
index 1261c87d..e40d58f3 100644
--- a/bindgen/gen_nim.py
+++ b/bindgen/gen_nim.py
@@ -6,7 +6,7 @@
# - reference: https://nim-lang.org/docs/nep1.html
#-------------------------------------------------------------------------------
import gen_ir
-import json, re, os, shutil
+import json, re, os, shutil, sys
module_names = {
'sg_': 'gfx',
@@ -48,16 +48,6 @@ const_bitfield_overrides = {
struct_field_type_overrides = {
'sapp_event.modifiers': 'sapp_event_modifier', # type declared above
- 'sapp_allocator.alloc': 'void * (*)(size_t, void *)',
- 'sapp_allocator.free': 'void (*)(void *, void *)',
- 'sg_allocator.alloc': 'void * (*)(size_t, void *)',
- 'sg_allocator.free': 'void (*)(void *, void *)',
- 'sgl_allocator_t.alloc': 'void * (*)(size_t, void *)',
- 'sgl_allocator_t.free': 'void (*)(void *, void *)',
- 'sdtx_allocator_t.alloc': 'void * (*)(size_t, void *)',
- 'sdtx_allocator_t.free': 'void (*)(void *, void *)',
- 'saudio_allocator.alloc': 'void * (*)(size_t, void *)',
- 'saudio_allocator.free': 'void (*)(void *, void *)',
}
prim_types = {
@@ -326,7 +316,7 @@ def as_nim_type(ctype, prefix):
array_nums = extract_array_nums(ctype)
return f"array[{array_nums}, {as_nim_type(array_ctype, prefix)}]"
else:
- l(f"// FIXME: {ctype};")
+ sys.exit(f"ERROR as_nim_type: {ctype}")
def funcptr_args(field_type, prefix):
tokens = field_type[field_type.index('(*)')+4:-1].split(',')
diff --git a/bindgen/gen_zig.py b/bindgen/gen_zig.py
index 5a0fceb7..e18dacc0 100644
--- a/bindgen/gen_zig.py
+++ b/bindgen/gen_zig.py
@@ -7,7 +7,7 @@
# - otherwise snake_case
#-------------------------------------------------------------------------------
import gen_ir
-import json, re, os, shutil
+import json, re, os, shutil, sys
module_names = {
'sg_': 'gfx',
@@ -263,7 +263,7 @@ def as_extern_c_arg_type(arg_type, prefix):
elif is_const_prim_ptr(arg_type):
return f"[*c]const {as_zig_prim_type(extract_ptr_type(arg_type))}"
else:
- return '??? (as_extern_c_arg_type)'
+ sys.exit(f"Error as_extern_c_arg_type(): {arg_type}")
def as_zig_arg_type(arg_prefix, arg_type, prefix):
# NOTE: if arg_prefix is None, the result is used as return value
@@ -293,7 +293,7 @@ def as_zig_arg_type(arg_prefix, arg_type, prefix):
elif is_const_prim_ptr(arg_type):
return pre + f"*const {as_zig_prim_type(extract_ptr_type(arg_type))}"
else:
- return arg_prefix + "??? (as_zig_arg_type)"
+ sys.exit(f"ERROR as_zig_arg_type(): {arg_type}")
# get C-style arguments of a function pointer as string
def funcptr_args_c(field_type, prefix):
@@ -317,8 +317,10 @@ def funcptr_res_c(field_type):
return 'void'
elif is_const_void_ptr(res_type):
return '?*const anyopaque'
+ elif is_void_ptr(res_type):
+ return '?*anyopaque'
else:
- return '???'
+ sys.exit(f"ERROR funcptr_res_c(): {field_type}")
def funcdecl_args_c(decl, prefix):
s = ""
@@ -398,8 +400,7 @@ def gen_struct(decl, prefix, callconvc_funcptrs = True, use_raw_name=False, use_
zig_type = as_zig_enum_type(array_type, prefix)
def_val = '.{}'
else:
- zig_type = '??? (array type)'
- def_val = '???'
+ sys.exit(f"ERROR gen_struct is_1d_array_type: {array_type}")
t0 = f"[{array_nums[0]}]{zig_type}"
t0_slice = f"[]const {zig_type}"
t1 = f"[_]{zig_type}"
@@ -407,7 +408,7 @@ def gen_struct(decl, prefix, callconvc_funcptrs = True, use_raw_name=False, use_
elif is_const_void_ptr(array_type):
l(f" {field_name}: [{array_nums[0]}]?*const anyopaque = [_]?*const anyopaque {{ null }} ** {array_nums[0]},")
else:
- l(f"// FIXME: ??? array {field_name}: {field_type} => {array_type} [{array_nums[0]}]")
+ sys.exit(f"ERROR gen_struct: array {field_name}: {field_type} => {array_type} [{array_nums[0]}]")
elif is_2d_array_type(field_type):
array_type = extract_array_type(field_type)
array_nums = extract_array_nums(field_type)
@@ -418,12 +419,11 @@ def gen_struct(decl, prefix, callconvc_funcptrs = True, use_raw_name=False, use_
zig_type = as_zig_struct_type(array_type, prefix)
def_val = ".{ }"
else:
- zig_type = "???"
- def_val = "???"
+ sys.exit(f"ERROR gen_struct is_2d_array_type: {array_type}")
t0 = f"[{array_nums[0]}][{array_nums[1]}]{zig_type}"
l(f" {field_name}: {t0} = [_][{array_nums[1]}]{zig_type}{{[_]{zig_type}{{ {def_val} }}**{array_nums[1]}}}**{array_nums[0]},")
else:
- l(f"// FIXME: {field_name}: {field_type};")
+ sys.exit(f"ERROR gen_struct: {field_name}: {field_type};")
l("};")
def gen_consts(decl, prefix):
diff --git a/sokol_app.h b/sokol_app.h
index 0e930258..5138a479 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -1391,12 +1391,9 @@ typedef struct sapp_icon_desc {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*sapp_malloc)(size_t size, void* user_data);
-typedef void(*sapp_free)(void* ptr, void* user_data);
-
typedef struct sapp_allocator {
- sapp_malloc alloc;
- sapp_free free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sapp_allocator;
diff --git a/sokol_args.h b/sokol_args.h
index 56b00eaa..e2cd85f3 100644
--- a/sokol_args.h
+++ b/sokol_args.h
@@ -307,12 +307,9 @@ extern "C" {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*sargs_malloc)(size_t size, void* user_data);
-typedef void(*sargs_free)(void* ptr, void* user_data);
-
typedef struct sargs_allocator {
- sargs_malloc alloc;
- sargs_free free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sargs_allocator;
diff --git a/sokol_audio.h b/sokol_audio.h
index 8c3585ff..7e60ba0f 100644
--- a/sokol_audio.h
+++ b/sokol_audio.h
@@ -453,12 +453,9 @@ extern "C" {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*saudio_malloc)(size_t size, void* user_data);
-typedef void(*saudio_free)(void* ptr, void* user_data);
-
typedef struct saudio_allocator {
- saudio_malloc alloc;
- saudio_free free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} saudio_allocator;
diff --git a/sokol_fetch.h b/sokol_fetch.h
index e8b1f0c7..8c2dc03f 100644
--- a/sokol_fetch.h
+++ b/sokol_fetch.h
@@ -897,12 +897,9 @@ extern "C" {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*sfetch_malloc_t)(size_t size, void* user_data);
-typedef void(*sfetch_free_t)(void* ptr, void* user_data);
-
typedef struct sfetch_allocator_t {
- sfetch_malloc_t alloc;
- sfetch_free_t free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sfetch_allocator_t;
diff --git a/sokol_gfx.h b/sokol_gfx.h
index a39a880b..d8f9c0fe 100644
--- a/sokol_gfx.h
+++ b/sokol_gfx.h
@@ -2441,12 +2441,9 @@ typedef struct sg_context_desc {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*sg_malloc)(size_t size, void* user_data);
-typedef void(*sg_free)(void* ptr, void* user_data);
-
typedef struct sg_allocator {
- sg_malloc alloc;
- sg_free free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sg_allocator;
diff --git a/util/sokol_debugtext.h b/util/sokol_debugtext.h
index 99524cc5..0219bbc3 100644
--- a/util/sokol_debugtext.h
+++ b/util/sokol_debugtext.h
@@ -537,12 +537,9 @@ typedef struct sdtx_context_desc_t {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*sdtx_malloc_t)(size_t size, void* user_data);
-typedef void(*sdtx_free_t)(void* ptr, void* user_data);
-
typedef struct sdtx_allocator_t {
- sdtx_malloc_t alloc;
- sdtx_free_t free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sdtx_allocator_t;
diff --git a/util/sokol_fontstash.h b/util/sokol_fontstash.h
index 39d601a7..30d4cde1 100644
--- a/util/sokol_fontstash.h
+++ b/util/sokol_fontstash.h
@@ -221,12 +221,9 @@ extern "C" {
NOTE that this does not affect memory allocation calls inside
fontstash.h
*/
-typedef void*(*sfons_malloc_t)(size_t size, void* user_data);
-typedef void(*sfons_free_t)(void* ptr, void* user_data);
-
typedef struct sfons_allocator_t {
- sfons_malloc_t alloc;
- sfons_free_t free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sfons_allocator_t;
diff --git a/util/sokol_gfx_imgui.h b/util/sokol_gfx_imgui.h
index e6d0d08d..8e980701 100644
--- a/util/sokol_gfx_imgui.h
+++ b/util/sokol_gfx_imgui.h
@@ -665,12 +665,9 @@ typedef struct sg_imgui_caps_t {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*sg_imgui_malloc_t)(size_t size, void* user_data);
-typedef void(*sg_imgui_free_t)(void* ptr, void* user_data);
-
typedef struct sg_imgui_allocator_t {
- sg_imgui_malloc_t alloc;
- sg_imgui_free_t free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sg_imgui_allocator_t;
diff --git a/util/sokol_gl.h b/util/sokol_gl.h
index 6c35eac1..5f8e565c 100644
--- a/util/sokol_gl.h
+++ b/util/sokol_gl.h
@@ -669,12 +669,9 @@ typedef struct sgl_context_desc_t {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*sgl_malloc_t)(size_t size, void* user_data);
-typedef void(*sgl_free_t)(void* ptr, void* user_data);
-
typedef struct sgl_allocator_t {
- sgl_malloc_t alloc;
- sgl_free_t free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} sgl_allocator_t;
diff --git a/util/sokol_imgui.h b/util/sokol_imgui.h
index 5fc06c1a..4548548b 100644
--- a/util/sokol_imgui.h
+++ b/util/sokol_imgui.h
@@ -285,12 +285,9 @@ extern "C" {
alloc and free function must be provided (e.g. it's not valid to
override one function but not the other).
*/
-typedef void*(*simgui_malloc_t)(size_t size, void* user_data);
-typedef void(*simgui_free_t)(void* ptr, void* user_data);
-
typedef struct simgui_allocator_t {
- simgui_malloc_t alloc;
- simgui_free_t free;
+ void* (*alloc)(size_t size, void* user_data);
+ void (*free)(void* ptr, void* user_data);
void* user_data;
} simgui_allocator_t;