Commit 27410967 authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1249 from aisk/cpython-abstract

use cpython's abstract.c instead of src/capi/abstract.cpp
parents 82c402a6 57c801a8
......@@ -81,6 +81,7 @@ file(GLOB_RECURSE STDMODULE_SRCS Modules
# compile specified files in from_cpython/Objects
file(GLOB_RECURSE STDOBJECT_SRCS Objects
abstract.c
bufferobject.c
bytearrayobject.c
bytes_methods.c
......@@ -97,6 +98,7 @@ file(GLOB_RECURSE STDOBJECT_SRCS Objects
iterobject.c
memoryobject.c
obmalloc.c
sliceobject.c
stringobject.c
structseq.c
traceback.c
......
......@@ -64,9 +64,13 @@ PyAPI_FUNC(BORROWED(PyObject *)) PyClass_Name(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *) PYSTON_NOEXCEPT;
// Pyston change: pyston addition returns PyInstanceObject->in_class
PyAPI_FUNC(BORROWED(PyObject*)) PyInstance_Class(PyObject* _inst) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *) PYSTON_NOEXCEPT;
......@@ -107,4 +111,3 @@ PyAPI_FUNC(int) PyMethod_ClearFreeList(void) PYSTON_NOEXCEPT;
}
#endif
#endif /* !Py_CLASSOBJECT_H */
This diff is collapsed.
This diff is collapsed.
......@@ -38,7 +38,7 @@ add_library(PYSTON_OBJECTS OBJECT ${OPTIONAL_SRCS}
codegen/baseline_jit.cpp
codegen/codegen.cpp
codegen/compvars.cpp
codegen/cpython_ast.cpp
codegen/cpython_ast.cpp
codegen/entry.cpp
codegen/gcbuilder.cpp
codegen/irgen.cpp
......
This diff is collapsed.
......@@ -1906,6 +1906,38 @@ extern "C" int PyCFunction_ClearFreeList() noexcept {
return 0; // number of entries cleared
}
extern "C" int PyNumber_Coerce(PyObject** pv, PyObject** pw) noexcept {
int err = PyNumber_CoerceEx(pv, pw);
if (err <= 0)
return err;
PyErr_SetString(PyExc_TypeError, "number coercion failed");
return -1;
}
extern "C" int PyNumber_CoerceEx(PyObject** pv, PyObject** pw) noexcept {
PyObject* v = *pv;
PyObject* w = *pw;
int res;
/* Shortcut only for old-style types */
if (v->cls == w->cls && !PyType_HasFeature(v->cls, Py_TPFLAGS_CHECKTYPES)) {
Py_INCREF(v);
Py_INCREF(w);
return 0;
}
if (v->cls->tp_as_number && v->cls->tp_as_number->nb_coerce) {
res = (*v->cls->tp_as_number->nb_coerce)(pv, pw);
if (res <= 0)
return res;
}
if (w->cls->tp_as_number && w->cls->tp_as_number->nb_coerce) {
res = (*w->cls->tp_as_number->nb_coerce)(pw, pv);
if (res <= 0)
return res;
}
return 1;
}
void setupCAPI() {
capifunc_cls->giveAttr(
"__repr__", new BoxedFunction(FunctionMetadata::create((void*)BoxedCApiFunction::__repr__<CXX>, UNKNOWN, 1)));
......
......@@ -215,6 +215,12 @@ extern "C" PyObject* PyInstance_New(PyObject* klass, PyObject* arg, PyObject* kw
}
}
extern "C" BORROWED(PyObject*) PyInstance_Class(PyObject* _inst) noexcept {
RELEASE_ASSERT(PyInstance_Check(_inst), "");
BoxedInstance* inst = (BoxedInstance*)_inst;
return inst->inst_cls;
}
static Box* classobjGetattribute(Box* _cls, Box* _attr) {
RELEASE_ASSERT(_cls->cls == classobj_cls, "");
BoxedClassobj* cls = static_cast<BoxedClassobj*>(_cls);
......
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