Commit 44d78d5c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #539 from undingen/pyicu

Add PyWrapperDescr_Type, allow cls->tp_descr_get, allow overwriting attributes inside PyType_Ready
parents 244c7b90 86258dd3
......@@ -82,6 +82,8 @@ PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
#endif
// (Pyston TODO: add #defines to our names)
PyAPI_DATA(PyTypeObject*) wrapperdescr_cls;
#define PyWrapperDescr_Type (*wrapperdescr_cls)
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *) PYSTON_NOEXCEPT;
......
......@@ -2706,7 +2706,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
RELEASE_ASSERT(cls->tp_flags & Py_TPFLAGS_CHECKTYPES, "Pyston doesn't yet support non-checktypes behavior");
}
RELEASE_ASSERT(cls->tp_descr_get == NULL, "");
RELEASE_ASSERT(cls->tp_descr_set == NULL, "");
RELEASE_ASSERT(cls->tp_free == NULL || cls->tp_free == PyObject_Del || cls->tp_free == PyObject_GC_Del, "");
RELEASE_ASSERT(cls->tp_is_gc == NULL, "");
......@@ -2750,7 +2749,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
}
for (PyMethodDef* method = cls->tp_methods; method && method->ml_name; ++method) {
cls->giveAttr(method->ml_name, new BoxedMethodDescriptor(method, cls));
cls->setattr(method->ml_name, new BoxedMethodDescriptor(method, cls), NULL);
}
for (PyMemberDef* member = cls->tp_members; member && member->name; ++member) {
......
......@@ -34,7 +34,7 @@ struct wrapper_def {
// exists in CPython: PyObject *name_strobj
};
extern BoxedClass* capifunc_cls, *wrapperdescr_cls, *wrapperobject_cls;
extern "C" BoxedClass* capifunc_cls, *wrapperdescr_cls, *wrapperobject_cls;
class BoxedCApiFunction : public Box {
private:
......
......@@ -50,11 +50,10 @@ extern "C" bool _PyObject_CheckBuffer(PyObject* obj) noexcept {
extern "C" {
int Py_Py3kWarningFlag;
}
BoxedClass* capifunc_cls;
BoxedClass* wrapperdescr_cls, *wrapperobject_cls;
}
Box* BoxedWrapperDescriptor::__get__(BoxedWrapperDescriptor* self, Box* inst, Box* owner) {
RELEASE_ASSERT(self->cls == wrapperdescr_cls, "");
......
Subproject commit 1b5100b9900c3bfc4ab75082870f5215d6a0695f
Subproject commit e715c2e4beec912248bcaa258b4dfd7c015a9273
......@@ -573,6 +573,55 @@ static PyTypeObject slots_tester_nullreturngetattr = {
0, /* tp_free */
};
static PyObject* descr_get_func(PyObject* obj, PyObject* inst, PyObject* owner) {
printf("Inside descr_get_func:\n");
return PyInt_FromLong(42);
}
static PyTypeObject slots_tester_descrget = {
PyVarObject_HEAD_INIT(NULL, 0)
"slots_test.slots_tester_descr_get", /* tp_name */
sizeof(PyObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
descr_get_func, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
0, /* tp_free */
};
// Tests the correctness of the CAPI slots when the attributes get set in Python code:
static PyObject *
call_funcs(PyObject* _module, PyObject* args) {
......@@ -787,6 +836,10 @@ initslots_test(void)
res = PyType_Ready(&slots_tester_nullreturngetattr);
if (res < 0)
return;
res = PyType_Ready(&slots_tester_descrget);
if (res < 0)
return;
// Not sure if the result of PyInt_FromLong needs to be decref'd
PyDict_SetItemString(slots_tester_seq.tp_dict, "set_through_tpdict", PyInt_FromLong(123));
......@@ -797,4 +850,5 @@ initslots_test(void)
PyModule_AddObject(m, "SlotsTesterSub", (PyObject *)&slots_tester_sub);
PyModule_AddObject(m, "SlotsTesterNonsubclassable", (PyObject *)&slots_tester_nonsubclassable);
PyModule_AddObject(m, "SlotsTesterNullReturnGetAttr", (PyObject *)&slots_tester_nullreturngetattr);
PyModule_AddObject(m, "SlotsTesterDescrGet", (PyObject *)&slots_tester_descrget);
}
......@@ -217,3 +217,8 @@ C.__get__ = lambda *args: None
slots_test.call_funcs(C())
del C.__get__
slots_test.call_funcs(C())
# test if __get__'s called
class C(object):
val = slots_test.SlotsTesterDescrGet()
print C().val
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment