-
-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Zig Version
0.14.1
Steps to Reproduce and Observed Behavior
Any call to CPython API PySequence_Fast_GET_SIZE
will result in this error:
...\.zig-cache\o\6bacacdc44df520a1df153414437fc32\cimport.zig:8950:76: error: expected type 'bool', found 'c_int'
pub inline fn PySequence_Fast_GET_SIZE(o: anytype) @TypeOf(if (PyList_Check(o)) PyList_GET_SIZE(o) else PyTuple_GET_SIZE(o)) {
~~~~~~~~~~~~^~~
pack_py.zig:62:44: note: called from here
const len = py.PySequence_Fast_GET_SIZE(fastseq);
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
py
is defined as the following:
pub const py = @cImport({
@cDefine("PY_SSIZE_T_CLEAN", {});
@cInclude("Python.h");
});
Expected Behavior
Checking the translated code, I found that the translate-c module convert this C definition:
#define PySequence_Fast_GET_SIZE(o) \
(PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
to
pub inline fn PySequence_Fast_GET_SIZE(o: anytype) @TypeOf(if (PyList_Check(o)) PyList_GET_SIZE(o) else PyTuple_GET_SIZE(o)) {
_ = &o;
return if (PyList_Check(o)) PyList_GET_SIZE(o) else PyTuple_GET_SIZE(o);
}
However, the return type of PyList_Check
is int rather than bool, which caused this problem.
Maybe when translating this, the ternary condition should be wrapped with an helper function converting int to bool.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working