swoole / phpy

Connecting the Python and PHP ecosystems together
Apache License 2.0
539 stars 44 forks source link

修正只有kwargs没有args时报错 #28

Closed he426100 closed 10 months ago

he426100 commented 10 months ago

复现代码

$namedtuple = PyCore::import('collections')->namedtuple;

$Person = $namedtuple('Person', ["name", "age", "gender"]);
$p1 = $Person(name: "阮奇桢", age: 40, gender: "男");
PyCore::print($p1->name);

运行会 [1] 11886 segmentation fault php test.php gdb调试发现在 value = PyObject_Call(fn, args, kwargs);处 出错,根据文档 调用对象的 API PyObject_Call的第二个参数 args 是可以为空的,此时应该传 空元组。

如果不改 bride/core.cc的话 第一个参数必须是 args,所以php中要改成 $p1 = $Person("阮奇桢", age: 40, gender: "男");,但这样显得很奇怪,与python不一致了