Merge branch 'chlandsi-master'
* chlandsi-master: Testcase for testing __new__ override Python 3.6 fix fix for creating new shadow class in python 3.6
This commit is contained in:
commit
d9ecff1fca
4 changed files with 48 additions and 5 deletions
|
|
@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.0.0 (in progress)
|
||||
===========================
|
||||
|
||||
2018-12-20: chlandsi
|
||||
[Python] #1357. Fix overriding __new__ in Python 3.6.
|
||||
|
||||
Fixes SystemError: Objects/tupleobject.c:81: bad argument to internal function"
|
||||
|
||||
2018-12-16: wsfulton
|
||||
[Python] #848 #1343 The module import logic has changed to stop obfuscating real ImportError
|
||||
problems. Only one import of the low-level C/C++ module from the pure Python module is
|
||||
|
|
|
|||
|
|
@ -3,3 +3,7 @@ import python_pythoncode
|
|||
# No need to actually do anything, this is a regression test for a bug which
|
||||
# caused an invalid python_pythoncode.py to be generated, so if we can import
|
||||
# it the bug is still fixed.
|
||||
|
||||
# A later test enhancement checking __new__ requires some code...
|
||||
f = python_pythoncode.get_foo()
|
||||
f = python_pythoncode.Foo()
|
||||
|
|
|
|||
|
|
@ -29,3 +29,33 @@ struct TYPE2 {
|
|||
struct TYPE { };
|
||||
struct TYPE2 { };
|
||||
%}
|
||||
|
||||
|
||||
// Overriding __new__ test: https://github.com/swig/swig/pull/1357
|
||||
%inline %{
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
Foo() {}
|
||||
};
|
||||
|
||||
Foo* get_foo() {return new Foo();}
|
||||
%}
|
||||
|
||||
%pythoncode %{
|
||||
print_debug = True
|
||||
%}
|
||||
|
||||
%extend Foo {
|
||||
// Note that %pythoncode is not available with -builtin
|
||||
%pythoncode %{
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if print_debug:
|
||||
print('in Foo.__new__()')
|
||||
return super(Foo, cls).__new__(cls)
|
||||
|
||||
def __init__(self):
|
||||
if print_debug:
|
||||
print('in Foo.__init__()')
|
||||
%}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1191,12 +1191,16 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
|
|||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyObject *empty_args = PyTuple_New(0);
|
||||
if (empty_args) {
|
||||
inst = ((PyTypeObject *)data->newargs)->tp_new((PyTypeObject *)data->newargs, empty_args, Py_None);
|
||||
Py_DECREF(empty_args);
|
||||
if (inst) {
|
||||
PyObject_SetAttr(inst, SWIG_This(), swig_this);
|
||||
Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
|
||||
PyObject *empty_kwargs = PyDict_New();
|
||||
if (empty_kwargs) {
|
||||
inst = ((PyTypeObject *)data->newargs)->tp_new((PyTypeObject *)data->newargs, empty_args, empty_kwargs);
|
||||
Py_DECREF(empty_kwargs);
|
||||
if (inst) {
|
||||
PyObject_SetAttr(inst, SWIG_This(), swig_this);
|
||||
Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
|
||||
}
|
||||
}
|
||||
Py_DECREF(empty_args);
|
||||
}
|
||||
#else
|
||||
PyObject *dict = PyDict_New();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue