fix regression in FeaturePythonPyT
This commit is contained in:
parent
b1b5e59364
commit
7f96119321
|
@ -115,22 +115,22 @@ int FeaturePythonPyT<FeaturePyT>::_setattr(char *attr, PyObject *value)
|
||||||
{
|
{
|
||||||
int returnValue = FeaturePyT::_setattr(attr, value);
|
int returnValue = FeaturePyT::_setattr(attr, value);
|
||||||
if (returnValue == -1) {
|
if (returnValue == -1) {
|
||||||
PyObject *s;
|
|
||||||
s = PyString_InternFromString(attr);
|
|
||||||
if (s == NULL)
|
|
||||||
return -1;
|
|
||||||
PyObject* dict_item = value;
|
PyObject* dict_item = value;
|
||||||
if (value && PyFunction_Check(value)) {
|
if (value) {
|
||||||
dict_item = PyMethod_New(value, this, 0);
|
if (PyFunction_Check(value)) {
|
||||||
returnValue = _PyObject_GenericSetAttrWithDict(this, s, dict_item, dict_methods);
|
PyErr_Clear();
|
||||||
Py_XDECREF(dict_item);
|
dict_item = PyMethod_New(value, this, 0);
|
||||||
|
returnValue = PyDict_SetItemString(dict_methods, attr, dict_item);
|
||||||
|
Py_XDECREF(dict_item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
returnValue = _PyObject_GenericSetAttrWithDict(this, s, dict_item, dict_methods);
|
// delete
|
||||||
|
PyErr_Clear();
|
||||||
|
returnValue = PyDict_DelItemString(dict_methods, attr);
|
||||||
|
if (returnValue < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
|
||||||
|
PyErr_SetString(PyExc_AttributeError, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_XDECREF(s);
|
|
||||||
PyErr_Clear();
|
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,7 @@ PyObject *FeaturePythonPyT<FeaturePyT>::_getattr(char *attr)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get only attributes of this type
|
||||||
if (Base::streq(attr, "__dict__")) {
|
if (Base::streq(attr, "__dict__")) {
|
||||||
// Return the default dict
|
// Return the default dict
|
||||||
PyTypeObject *tp = this->ob_type;
|
PyTypeObject *tp = this->ob_type;
|
||||||
|
@ -158,26 +159,20 @@ PyObject *FeaturePythonPyT<FeaturePyT>::_getattr(char *attr)
|
||||||
PyObject* dict_old = dict;
|
PyObject* dict_old = dict;
|
||||||
dict = PyDict_Copy(dict_old);
|
dict = PyDict_Copy(dict_old);
|
||||||
Py_DECREF(dict_old); // delete old dict
|
Py_DECREF(dict_old); // delete old dict
|
||||||
|
|
||||||
PyDict_Merge(dict, dict_methods, 0);
|
PyDict_Merge(dict, dict_methods, 0);
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
Py_DECREF(dict);
|
|
||||||
dict = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *s;
|
// find the attribute in the dict
|
||||||
s = PyString_InternFromString(attr);
|
|
||||||
if (s == NULL)
|
|
||||||
return NULL;
|
|
||||||
PyObject *dict_item = NULL;
|
PyObject *dict_item = NULL;
|
||||||
dict_item = _PyObject_GenericGetAttrWithDict(this, s, dict_methods);
|
dict_item = PyDict_GetItemString(dict_methods, attr);
|
||||||
Py_XDECREF(s);
|
if (dict_item) {
|
||||||
if (dict_item)
|
Py_INCREF(dict_item);
|
||||||
return dict_item;
|
return dict_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
// search for the attribute in the base class
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
return FeaturePyT::_getattr(attr);
|
return FeaturePyT::_getattr(attr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user