From d90c11db585d06037c19ba9c7977ef5a2daf1e1d Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Tue, 12 Sep 2023 15:03:20 +0200 Subject: [PATCH] Save return pointer before calling native function in binding stubs --- scripts/bindgen.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/bindgen.py b/scripts/bindgen.py index 0c92693..53036ad 100755 --- a/scripts/bindgen.py +++ b/scripts/bindgen.py @@ -123,6 +123,11 @@ def bindgen(apiName, spec, **kwargs): if retTag != 'v': firstArgIndex = 1 + if retTag == 'S': + retTypeName = decl['ret']['name'] + retTypeCName = decl['ret'].get('cname', retTypeName) + s += retTypeCName + '* __retPtr = (' + retTypeCName + '*)((char*)_mem + *(i32*)&_sp[0]);\n' + for argIndex, arg in enumerate(decl['args']): argName = arg['name'] @@ -202,9 +207,7 @@ def bindgen(apiName, spec, **kwargs): elif retTag == 'F': s += '*((f64*)&_sp[0]) = (f64)' elif retTag == 'S': - retTypeName = decl['ret']['name'] - retTypeCName = decl['ret'].get('cname', retTypeName) - s += '*(' + retTypeCName + '*)((char*)_mem + *(i32*)&_sp[0]) = ' + s += '*__retPtr = ' elif retTag == 'p': print("Warning: " + name + ": pointer return type not supported yet")