mirror of https://github.com/swig/swig
Add python builtin testcase for handling NULL in a couple of closures
From and for testing issue #2771.
This commit is contained in:
parent
b97972c706
commit
bfff61bd99
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.2.1 (in progress)
|
||||
===========================
|
||||
|
||||
2024-01-31: jim-easterbrook
|
||||
#2771 [Python] builtin fixes to handle NULL values passed to slots using
|
||||
functype: ssizeobjargproc and ternaryfunc.
|
||||
|
||||
2024-01-31: olly
|
||||
[java] #2766 Fix segfault trying to wrap a constant whose type is unknown
|
||||
to SWIG with "%javaconst(1);" enabled.
|
||||
|
|
|
@ -111,3 +111,26 @@ z = ANumber(9)
|
|||
z = pow(x, y, z)
|
||||
if z.Value() != 7:
|
||||
raise RuntimeError("pow(x, y, z) wrong")
|
||||
|
||||
# Test 8 https://github.com/swig/swig/pull/2771 __setitem__ for deleting item, uses C NULL
|
||||
def check_gsi(gsi, idx, value, args_count, kw_count):
|
||||
if gsi.idx != idx:
|
||||
raise RuntimeError("idx wrong {}".format(idx))
|
||||
if gsi.value != value:
|
||||
raise RuntimeError("value wrong {}".format(value))
|
||||
if gsi.args_count != args_count:
|
||||
raise RuntimeError("args_count wrong {}".format(args_count))
|
||||
if gsi.kw_count != kw_count:
|
||||
raise RuntimeError("kw_count wrong {}".format(kw_count))
|
||||
gsi.reset()
|
||||
|
||||
if is_python_builtin():
|
||||
gsi = GetSetItem()
|
||||
gsi[0] = 111
|
||||
check_gsi(gsi, 0, 111, -100, -100)
|
||||
del gsi[0]
|
||||
check_gsi(gsi, 0, -11, -100, -100)
|
||||
gsi(222, fred = 333, jack = 444)
|
||||
check_gsi(gsi, -100, -100, 1, 2)
|
||||
gsi(333)
|
||||
check_gsi(gsi, -100, -100, 1, -11)
|
||||
|
|
|
@ -244,3 +244,35 @@ public:
|
|||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// Test 8 https://github.com/swig/swig/pull/2771 __setitem__ for deleting item, uses C NULL
|
||||
%feature("python:slot", "sq_item", functype="ssizeargfunc") GetSetItem::__getitem__;
|
||||
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") GetSetItem::__setitem__;
|
||||
%feature("python:slot", "tp_call", functype="ternaryfunc") GetSetItem::__call__;
|
||||
%typemap(default) PyObject* value {$1 = NULL;}
|
||||
|
||||
%inline %{
|
||||
class GetSetItem {
|
||||
public:
|
||||
int idx, value, args_count, kw_count;
|
||||
GetSetItem() : idx(), value(), args_count(), kw_count() { reset(); }
|
||||
int __getitem__(int idx) {
|
||||
this->idx = idx;
|
||||
return 123;
|
||||
}
|
||||
void __setitem__(int idx, PyObject* value) {
|
||||
this->idx = idx;
|
||||
this->value = value ? (int)PyInt_AsLong(value) : -11;
|
||||
}
|
||||
void __call__(PyObject* args, PyObject* kw) {
|
||||
this->args_count = args ? (int)PyTuple_Size(args) : -11;
|
||||
this->kw_count = kw ? (int)PyDict_Size(kw) : -11;
|
||||
}
|
||||
void reset() {
|
||||
idx = -100;
|
||||
value = -100;
|
||||
args_count = -100;
|
||||
kw_count = -100;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
|
Loading…
Reference in New Issue