Skip to content

Commit db31a73

Browse files
committed
Fix builtins __bool__ implementation
1 parent 768399b commit db31a73

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/godot/builtins.pyx.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{%- from 'builtins_pyx/conversion.pyx.j2' import render_all_conversions with context -%}
33
cimport cython
44
from libc.math cimport INFINITY as inf # Needed by some constants
5+
from libc.string cimport memset # Needed to create zeroized builtins used in `__bool__`
56

67
# Forward declarations
78
{% for builtin in api.builtins %}

src/godot/builtins_pyx/operator.pyx.j2

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@ def __eq__(self, object other):
4646
{# Note `__bool__` is not needed if `__len__` is defined #}
4747
def __len__(self):
4848
return self.size()
49+
{% elif builtin.is_transparent_builtin %}
50+
def __bool__(self):
51+
return (
52+
{% for member in builtin.all_nested_scalar_members %}
53+
{% if not loop.first %}or {% endif %}self.{{ member }} != 0
54+
{% endfor %}
55+
)
4956
{% else %}
5057
def __bool__(self):
51-
return gdptrs.gdptr_variant_booleanize(&self._gd_data)
58+
cdef {{ builtin.c_type }} zero
59+
memset(&zero, 0, cython.sizeof({{ builtin.c_type }}))
60+
return not gdapi.gd_{{ builtin.snake_name }}_op_equal_{{ builtin.snake_name }}(&self._gd_data, &zero)
5261
{% endif %}
5362

5463
{% if builtin.original_name == "Array" or builtin.is_packed_array %}

0 commit comments

Comments
 (0)