Ver Fonte

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
Andre Weissflog há 3 anos atrás
pai
commit
2bd14a3890
12 ficheiros alterados com 32 adições e 72 exclusões
  1. 2 12
      bindgen/gen_nim.py
  2. 10 10
      bindgen/gen_zig.py
  3. 2 5
      sokol_app.h
  4. 2 5
      sokol_args.h
  5. 2 5
      sokol_audio.h
  6. 2 5
      sokol_fetch.h
  7. 2 5
      sokol_gfx.h
  8. 2 5
      util/sokol_debugtext.h
  9. 2 5
      util/sokol_fontstash.h
  10. 2 5
      util/sokol_gfx_imgui.h
  11. 2 5
      util/sokol_gl.h
  12. 2 5
      util/sokol_imgui.h

+ 2 - 12
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(',')

+ 10 - 10
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):

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;
 

+ 2 - 5
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;