Commit 00e024af authored by Marius Wachtler's avatar Marius Wachtler

fix abstractmethods check

parent b0959d9e
...@@ -441,10 +441,10 @@ Box* notimplementedRepr(Box* self) { ...@@ -441,10 +441,10 @@ Box* notimplementedRepr(Box* self) {
} }
Box* sorted(Box* obj, Box* cmp, Box* key, Box** args) { Box* sorted(Box* obj, Box* cmp, Box* key, Box** args) {
assert(0 && "check refcounting");
Box* reverse = args[0]; Box* reverse = args[0];
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
KEEP_ALIVE(rtn);
for (Box* e : obj->pyElements()) { for (Box* e : obj->pyElements()) {
listAppendInternalStolen(rtn, e); listAppendInternalStolen(rtn, e);
} }
......
...@@ -901,6 +901,7 @@ public: ...@@ -901,6 +901,7 @@ public:
}; };
void listSort(BoxedList* self, Box* cmp, Box* key, Box* reverse) { void listSort(BoxedList* self, Box* cmp, Box* key, Box* reverse) {
assert(0 && "check refcounting");
assert(PyList_Check(self)); assert(PyList_Check(self));
if (cmp == None) if (cmp == None)
......
...@@ -2883,20 +2883,28 @@ static void typeSetAbstractMethods(Box* _type, PyObject* value, void* context) { ...@@ -2883,20 +2883,28 @@ static void typeSetAbstractMethods(Box* _type, PyObject* value, void* context) {
throwCAPIException(); throwCAPIException();
} }
static Box* typeAbstractMethods(Box* _type, void*) { static PyObject* type_abstractmethods(PyTypeObject *type, void *context) noexcept
RELEASE_ASSERT(PyType_Check(_type), ""); {
PyTypeObject* type = static_cast<PyTypeObject*>(_type); PyObject *mod = NULL;
PyObject* mod = NULL;
/* type itself has an __abstractmethods__ descriptor (this). Don't return /* type itself has an __abstractmethods__ descriptor (this). Don't return
that. */ that. */
if (type != &PyType_Type) if (type != &PyType_Type)
mod = PyDict_GetItemString(type->tp_dict, "__abstractmethods__"); mod = PyDict_GetItemString(type->tp_dict, "__abstractmethods__");
// mod = type->getattr(internStringMortal("__abstractmethods__"));
if (!mod) { if (!mod) {
raiseExcHelper(AttributeError, "__abstractmethods__"); PyErr_SetString(PyExc_AttributeError, "__abstractmethods__");
return NULL;
} }
return incref(mod); Py_XINCREF(mod);
return mod;
}
static Box* typeAbstractMethods(Box* _type, void* c) {
RELEASE_ASSERT(PyType_Check(_type), "");
PyTypeObject* type = static_cast<PyTypeObject*>(_type);
Box* rtn = type_abstractmethods(type, c);
if (!rtn)
throwCAPIException();
return rtn;
} }
static PyObject* object_new(PyTypeObject* type, PyObject* args, PyObject* kwds) noexcept { static PyObject* object_new(PyTypeObject* type, PyObject* args, PyObject* kwds) noexcept {
...@@ -2923,20 +2931,24 @@ static PyObject* object_new(PyTypeObject* type, PyObject* args, PyObject* kwds) ...@@ -2923,20 +2931,24 @@ static PyObject* object_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
/* Compute ", ".join(sorted(type.__abstractmethods__)) /* Compute ", ".join(sorted(type.__abstractmethods__))
into joined. */ into joined. */
abstract_methods = typeAbstractMethods(type, NULL); abstract_methods = type_abstractmethods(type, NULL);
if (abstract_methods == NULL) if (abstract_methods == NULL)
goto error; goto error;
builtins = PyEval_GetBuiltins(); builtins = PyEval_GetBuiltins();
if (builtins == NULL) if (builtins == NULL)
goto error; goto error;
sorted = builtins->getattr(internStringMortal("sorted")); // Pyston change: builtins is a module not a dict
// sorted = PyDict_GetItemString(builtins, "sorted");
sorted = builtins->getattr(autoDecref(internStringMortal("sorted")));
if (sorted == NULL) if (sorted == NULL)
goto error; goto error;
sorted_methods = PyObject_CallFunctionObjArgs(sorted, abstract_methods, NULL); sorted_methods = PyObject_CallFunctionObjArgs(sorted, abstract_methods, NULL);
if (sorted_methods == NULL) if (sorted_methods == NULL)
goto error; goto error;
if (comma == NULL) { if (comma == NULL) {
comma = PyString_InternFromString(", "); // Pyston change:
// comma = PyGC_ PyString_InternFromString(", ");
comma = getStaticString(", ");
if (comma == NULL) if (comma == NULL)
goto error; goto error;
} }
...@@ -2951,6 +2963,9 @@ static PyObject* object_new(PyTypeObject* type, PyObject* args, PyObject* kwds) ...@@ -2951,6 +2963,9 @@ static PyObject* object_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
"with abstract methods %s", "with abstract methods %s",
type->tp_name, joined_str); type->tp_name, joined_str);
error: error:
Py_XDECREF(joined);
Py_XDECREF(sorted_methods);
Py_XDECREF(abstract_methods);
return NULL; return NULL;
} }
return type->tp_alloc(type, 0); return type->tp_alloc(type, 0);
......
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