[GDnative] ptrcall on OS.get_static_memory_usage cause segfault due to godot_int != uint64_t
Created by: touilleMan
OS.get_static_memory_usage
&friends are supposed to return uint64_t
:
https://github.com/godotengine/godot/blob/435cced7d8fbc80e6842d7c171a87d4db1e64fe4/core/os/os.h#L398-L401
However they are defined with a int
as return value in api.json:
"name": "get_static_memory_usage",
"return_type": "int",
"is_editor": false,
"is_noscript": false,
"is_const": true,
"is_reverse": false,
"is_virtual": false,
"has_varargs": false,
"is_from_script": false,
"arguments": [
]
This is bad because the int
type in api.json should correspond to godot_int
type defined in godot native headers as typedef int godot_int
.
This means we end up with memory corruption and segfault when using this function according to the api.json
definition :'(
I guess the reason why this function is marked as int
is because it represent the integer type of the Variant (which has uint64_t constructor and cast operator).
I see two solution to solve this:
- mark this function as ptrcall incompatible so use must use Variant call (typically by adding a new field
is_ptrcall_compatible
in theapi.json
). However I'm a bit worried what happened in caseOS.get_static_memory_usage
returns au value bigger thansizeof(godot_int)
... - introduce a uint64_t compatible type in api.json type field
It would be interesting to dig a big in the codebase to see how many functions have a similar issues (and if they are performance critical ones). Any idea how we could do that ?