diff options
| author | Andre Weissflog <floooh@gmail.com> | 2022-07-02 13:15:34 +0200 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2022-07-02 13:15:34 +0200 |
| commit | 49ab1f46c16ecaffb8e075707a47f67cbd191b0a (patch) | |
| tree | 9436226244b33de677ababa7c90910c90a4fec50 /bindgen/gen_nim.py | |
| parent | c07c12b1eac7fe56ca28c81bf88fb039dbdb7375 (diff) | |
Nim bindings: remove to_Range and clean up type mappings
- to_Range() converter removed, to easy to f*ck up and end
up with corrupted memory
- size_t mapping changed from Nim's uint to int (because Nim's
sizeof returns int
- change Range.pointer to Range.addr (looks better since it is
usually used with Nim's unsafeAddr)
Diffstat (limited to 'bindgen/gen_nim.py')
| -rw-r--r-- | bindgen/gen_nim.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/bindgen/gen_nim.py b/bindgen/gen_nim.py index e88bd5cd..a01c057d 100644 --- a/bindgen/gen_nim.py +++ b/bindgen/gen_nim.py @@ -42,7 +42,7 @@ overrides = { 'SG_BUFFERTYPE_VERTEXBUFFER': 'SG_BUFFERTYPE_VERTEX_BUFFER', 'SG_BUFFERTYPE_INDEXBUFFER': 'SG_BUFFERTYPE_INDEX_BUFFER', 'SG_ACTION_DONTCARE': 'SG_ACTION_DONT_CARE', - 'ptr': 'pointer', # range ptr + 'ptr': 'addr', # range ptr } enumPrefixOverrides = { @@ -90,7 +90,7 @@ prim_types = { 'double': 'float64', 'uintptr_t': 'uint', 'intptr_t': 'int', - 'size_t': 'uint', + 'size_t': 'int', # not a bug, Nim's sizeof() returns int } prim_defaults = { @@ -565,11 +565,6 @@ def gen_extra(inp): l('else:') l(' error("unsupported platform")') l('') - if inp['prefix'] in ['sg_', 'sdtx_', 'sshape_']: - l('# helper function to convert "anything" into a Range') - l('converter to_Range*[T](source: T): Range =') - l(' Range(pointer: source.unsafeAddr, size: source.sizeof.uint)') - l('') if inp['prefix'] in ['sg_']: l('## Convert a 4-element tuple of numbers to a gfx.Color') l('converter toColor*[R:SomeNumber,G:SomeNumber,B:SomeNumber,A:SomeNumber](rgba: tuple [r:R,g:G,b:B,a:A]):Color =') @@ -579,6 +574,15 @@ def gen_extra(inp): l('converter toColor*[R:SomeNumber,G:SomeNumber,B:SomeNumber](rgba: tuple [r:R,g:G,b:B]):Color =') l(' Color(r:rgba.r.float32, g:rgba.g.float32, b:rgba.b.float32, a:1.float32)') l('') + # NOTE: this simplistic to_Range() converter has various issues, some of them dangerous: + # - doesn't work as expected for slice types + # - it's very easy to create a range that points to invalid memory + # (so far observed for stack-allocated structs <= 16 bytes) + #if inp['prefix'] in ['sg_', 'sdtx_', 'sshape_']: + # l('# helper function to convert "anything" into a Range') + # l('converter to_Range*[T](source: T): Range =') + # l(' Range(addr: source.unsafeAddr, size: source.sizeof.uint)') + # l('') c_source_path = '/'.join(c_source_paths[inp['prefix']].split('/')[3:]) l('{.passc:"-DSOKOL_NIM_IMPL".}') l(f'{{.compile:"{c_source_path}".}}') |