Commit 57c801a8 authored by asaka's avatar asaka

use abstract.c from cpython instead of abstract.cpp

parent cd29133e
...@@ -81,6 +81,7 @@ file(GLOB_RECURSE STDMODULE_SRCS Modules ...@@ -81,6 +81,7 @@ file(GLOB_RECURSE STDMODULE_SRCS Modules
# compile specified files in from_cpython/Objects # compile specified files in from_cpython/Objects
file(GLOB_RECURSE STDOBJECT_SRCS Objects file(GLOB_RECURSE STDOBJECT_SRCS Objects
abstract.c
bufferobject.c bufferobject.c
bytearrayobject.c bytearrayobject.c
bytes_methods.c bytes_methods.c
...@@ -97,6 +98,7 @@ file(GLOB_RECURSE STDOBJECT_SRCS Objects ...@@ -97,6 +98,7 @@ file(GLOB_RECURSE STDOBJECT_SRCS Objects
iterobject.c iterobject.c
memoryobject.c memoryobject.c
obmalloc.c obmalloc.c
sliceobject.c
stringobject.c stringobject.c
structseq.c structseq.c
traceback.c traceback.c
......
...@@ -64,9 +64,13 @@ PyAPI_FUNC(BORROWED(PyObject *)) PyClass_Name(PyObject *) PYSTON_NOEXCEPT; ...@@ -64,9 +64,13 @@ PyAPI_FUNC(BORROWED(PyObject *)) PyClass_Name(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *, PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
PyObject *) PYSTON_NOEXCEPT; PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, 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_Function(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *) PYSTON_NOEXCEPT;
...@@ -107,4 +111,3 @@ PyAPI_FUNC(int) PyMethod_ClearFreeList(void) PYSTON_NOEXCEPT; ...@@ -107,4 +111,3 @@ PyAPI_FUNC(int) PyMethod_ClearFreeList(void) PYSTON_NOEXCEPT;
} }
#endif #endif
#endif /* !Py_CLASSOBJECT_H */ #endif /* !Py_CLASSOBJECT_H */
// This file is originally from CPython 2.7, with modifications for Pyston
/* Abstract Object Interface (many thanks to Jim Fulton) */ /* Abstract Object Interface (many thanks to Jim Fulton) */
#include "Python.h" #include "Python.h"
#include <ctype.h> #include <ctype.h>
#include "structmember.h" /* we need the offsetof() macro from there */ #include "structmember.h" /* we need the offsetof() macro from there */
// pyston change: comment this out
#if 0
#include "longintrepr.h" #include "longintrepr.h"
#endif
#define NEW_STYLE_NUMBER(o) PyType_HasFeature((o)->ob_type, \ #define NEW_STYLE_NUMBER(o) PyType_HasFeature((o)->ob_type, \
Py_TPFLAGS_CHECKTYPES) Py_TPFLAGS_CHECKTYPES)
...@@ -18,7 +24,8 @@ type_error(const char *msg, PyObject *obj) ...@@ -18,7 +24,8 @@ type_error(const char *msg, PyObject *obj)
return NULL; return NULL;
} }
static PyObject * // pyston change: removed the static keyword, this function is also used in src/capi/abstract.cpp
PyObject *
null_error(void) null_error(void)
{ {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
...@@ -57,6 +64,8 @@ PyObject_Type(PyObject *o) ...@@ -57,6 +64,8 @@ PyObject_Type(PyObject *o)
return v; return v;
} }
// pyston change: comment this out
#if 0
Py_ssize_t Py_ssize_t
PyObject_Size(PyObject *o) PyObject_Size(PyObject *o)
{ {
...@@ -73,6 +82,7 @@ PyObject_Size(PyObject *o) ...@@ -73,6 +82,7 @@ PyObject_Size(PyObject *o)
return PyMapping_Size(o); return PyMapping_Size(o);
} }
#endif
#undef PyObject_Length #undef PyObject_Length
Py_ssize_t Py_ssize_t
...@@ -131,6 +141,8 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) ...@@ -131,6 +141,8 @@ _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
return rv; return rv;
} }
// pyston change: comment this out
#if 0
PyObject * PyObject *
PyObject_GetItem(PyObject *o, PyObject *key) PyObject_GetItem(PyObject *o, PyObject *key)
{ {
...@@ -222,6 +234,7 @@ PyObject_DelItem(PyObject *o, PyObject *key) ...@@ -222,6 +234,7 @@ PyObject_DelItem(PyObject *o, PyObject *key)
type_error("'%.200s' object does not support item deletion", o); type_error("'%.200s' object does not support item deletion", o);
return -1; return -1;
} }
#endif
int int
PyObject_DelItemString(PyObject *o, char *key) PyObject_DelItemString(PyObject *o, char *key)
...@@ -356,6 +369,8 @@ int PyObject_AsWriteBuffer(PyObject *obj, ...@@ -356,6 +369,8 @@ int PyObject_AsWriteBuffer(PyObject *obj,
/* Buffer C-API for Python 3.0 */ /* Buffer C-API for Python 3.0 */
// pyston change: comment this out
#if 0
int int
PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
{ {
...@@ -367,6 +382,7 @@ PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) ...@@ -367,6 +382,7 @@ PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
} }
return (*(obj->ob_type->tp_as_buffer->bf_getbuffer))(obj, view, flags); return (*(obj->ob_type->tp_as_buffer->bf_getbuffer))(obj, view, flags);
} }
#endif
static int static int
_IsFortranContiguous(Py_buffer *view) _IsFortranContiguous(Py_buffer *view)
...@@ -720,6 +736,8 @@ PyBuffer_Release(Py_buffer *view) ...@@ -720,6 +736,8 @@ PyBuffer_Release(Py_buffer *view)
view->obj = NULL; view->obj = NULL;
} }
// pyston change: comment this out
#if 0
PyObject * PyObject *
PyObject_Format(PyObject* obj, PyObject *format_spec) PyObject_Format(PyObject* obj, PyObject *format_spec)
{ {
...@@ -876,6 +894,7 @@ done: ...@@ -876,6 +894,7 @@ done:
Py_XDECREF(empty); Py_XDECREF(empty);
return result; return result;
} }
#endif
/* Operations on numbers */ /* Operations on numbers */
...@@ -1572,6 +1591,8 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format) ...@@ -1572,6 +1591,8 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
int_name = PyString_InternFromString("__int__"); int_name = PyString_InternFromString("__int__");
if (int_name == NULL) if (int_name == NULL)
return NULL; return NULL;
// Pyston change:
PyGC_RegisterStaticConstant(int_name);
} }
if (integral && (!PyInt_Check(integral) && if (integral && (!PyInt_Check(integral) &&
...@@ -1595,8 +1616,11 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format) ...@@ -1595,8 +1616,11 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
non_integral_error: non_integral_error:
if (PyInstance_Check(integral)) { if (PyInstance_Check(integral)) {
type_name = PyString_AS_STRING(((PyInstanceObject *)integral) // Pyston change:
->in_class->cl_name); // type_name = PyString_AS_STRING(((PyInstanceObject *)integral)
// ->in_class->cl_name);
// type_name = static_cast<BoxedInstance*>(integral)->inst_cls->name->data();
type_name = PyString_AS_STRING(PyClass_Name(PyInstance_Class(integral)));
} }
else { else {
type_name = integral->ob_type->tp_name; type_name = integral->ob_type->tp_name;
...@@ -1606,7 +1630,6 @@ non_integral_error: ...@@ -1606,7 +1630,6 @@ non_integral_error:
return NULL; return NULL;
} }
PyObject * PyObject *
PyNumber_Int(PyObject *o) PyNumber_Int(PyObject *o)
{ {
...@@ -1620,6 +1643,8 @@ PyNumber_Int(PyObject *o) ...@@ -1620,6 +1643,8 @@ PyNumber_Int(PyObject *o)
trunc_name = PyString_InternFromString("__trunc__"); trunc_name = PyString_InternFromString("__trunc__");
if (trunc_name == NULL) if (trunc_name == NULL)
return NULL; return NULL;
// Pyston change:
PyGC_RegisterStaticConstant(trunc_name);
} }
if (o == NULL) if (o == NULL)
...@@ -1705,6 +1730,8 @@ PyNumber_Long(PyObject *o) ...@@ -1705,6 +1730,8 @@ PyNumber_Long(PyObject *o)
trunc_name = PyString_InternFromString("__trunc__"); trunc_name = PyString_InternFromString("__trunc__");
if (trunc_name == NULL) if (trunc_name == NULL)
return NULL; return NULL;
// Pyston change:
PyGC_RegisterStaticConstant(trunc_name);
} }
if (o == NULL) if (o == NULL)
...@@ -2445,7 +2472,7 @@ PyMapping_Length(PyObject *o) ...@@ -2445,7 +2472,7 @@ PyMapping_Length(PyObject *o)
#define PyMapping_Length PyMapping_Size #define PyMapping_Length PyMapping_Size
PyObject * PyObject *
PyMapping_GetItemString(PyObject *o, char *key) PyMapping_GetItemString(PyObject *o, const char *key)
{ {
PyObject *okey, *r; PyObject *okey, *r;
...@@ -2461,7 +2488,7 @@ PyMapping_GetItemString(PyObject *o, char *key) ...@@ -2461,7 +2488,7 @@ PyMapping_GetItemString(PyObject *o, char *key)
} }
int int
PyMapping_SetItemString(PyObject *o, char *key, PyObject *value) PyMapping_SetItemString(PyObject *o, const char *key, PyObject *value)
{ {
PyObject *okey; PyObject *okey;
int r; int r;
...@@ -2517,6 +2544,8 @@ PyObject_CallObject(PyObject *o, PyObject *a) ...@@ -2517,6 +2544,8 @@ PyObject_CallObject(PyObject *o, PyObject *a)
return PyEval_CallObjectWithKeywords(o, a, NULL); return PyEval_CallObjectWithKeywords(o, a, NULL);
} }
// pyston change: comment this out
#if 0
PyObject * PyObject *
PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw)
{ {
...@@ -2538,6 +2567,7 @@ PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) ...@@ -2538,6 +2567,7 @@ PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw)
func->ob_type->tp_name); func->ob_type->tp_name);
return NULL; return NULL;
} }
#endif
static PyObject* static PyObject*
call_function_tail(PyObject *callable, PyObject *args) call_function_tail(PyObject *callable, PyObject *args)
...@@ -2566,7 +2596,7 @@ call_function_tail(PyObject *callable, PyObject *args) ...@@ -2566,7 +2596,7 @@ call_function_tail(PyObject *callable, PyObject *args)
} }
PyObject * PyObject *
PyObject_CallFunction(PyObject *callable, char *format, ...) PyObject_CallFunction(PyObject *callable, const char *format, ...)
{ {
va_list va; va_list va;
PyObject *args; PyObject *args;
...@@ -2586,7 +2616,7 @@ PyObject_CallFunction(PyObject *callable, char *format, ...) ...@@ -2586,7 +2616,7 @@ PyObject_CallFunction(PyObject *callable, char *format, ...)
} }
PyObject * PyObject *
_PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...) _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
{ {
va_list va; va_list va;
PyObject *args; PyObject *args;
...@@ -2605,8 +2635,10 @@ _PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...) ...@@ -2605,8 +2635,10 @@ _PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...)
return call_function_tail(callable, args); return call_function_tail(callable, args);
} }
// pyston change: comment this out
#if 0
PyObject * PyObject *
PyObject_CallMethod(PyObject *o, char *name, char *format, ...) PyObject_CallMethod(PyObject *o, const char *name, const char *format, ...)
{ {
va_list va; va_list va;
PyObject *args; PyObject *args;
...@@ -2645,7 +2677,7 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...) ...@@ -2645,7 +2677,7 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
} }
PyObject * PyObject *
_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...) _PyObject_CallMethod_SizeT(PyObject *o, const char *name, const char *format, ...)
{ {
va_list va; va_list va;
PyObject *args; PyObject *args;
...@@ -2682,9 +2714,11 @@ _PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...) ...@@ -2682,9 +2714,11 @@ _PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...)
return retval; return retval;
} }
#endif
static PyObject * // pyston change: removed the static keyword, this function is also used in src/capi/abstract.cpp
PyObject *
objargs_mktuple(va_list va) objargs_mktuple(va_list va)
{ {
int i, n = 0; int i, n = 0;
...@@ -2714,6 +2748,8 @@ objargs_mktuple(va_list va) ...@@ -2714,6 +2748,8 @@ objargs_mktuple(va_list va)
return result; return result;
} }
// pyston change: comment this out
#if 0
PyObject * PyObject *
PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...) PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...)
{ {
...@@ -2741,6 +2777,7 @@ PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...) ...@@ -2741,6 +2777,7 @@ PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...)
return tmp; return tmp;
} }
#endif
PyObject * PyObject *
PyObject_CallFunctionObjArgs(PyObject *callable, ...) PyObject_CallFunctionObjArgs(PyObject *callable, ...)
...@@ -2792,7 +2829,9 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...) ...@@ -2792,7 +2829,9 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...)
* When there's no exception to propagate, it's customary for the caller to * When there's no exception to propagate, it's customary for the caller to
* set a TypeError. * set a TypeError.
*/ */
static PyObject *
// pyston change: removed the static keyword, this function is also used in src/capi/abstract.cpp
PyObject *
abstract_get_bases(PyObject *cls) abstract_get_bases(PyObject *cls)
{ {
static PyObject *__bases__ = NULL; static PyObject *__bases__ = NULL;
...@@ -2802,6 +2841,8 @@ abstract_get_bases(PyObject *cls) ...@@ -2802,6 +2841,8 @@ abstract_get_bases(PyObject *cls)
__bases__ = PyString_InternFromString("__bases__"); __bases__ = PyString_InternFromString("__bases__");
if (__bases__ == NULL) if (__bases__ == NULL)
return NULL; return NULL;
// Pyston change:
PyGC_RegisterStaticConstant(__bases__);
} }
bases = PyObject_GetAttr(cls, __bases__); bases = PyObject_GetAttr(cls, __bases__);
if (bases == NULL) { if (bases == NULL) {
...@@ -2854,7 +2895,8 @@ abstract_issubclass(PyObject *derived, PyObject *cls) ...@@ -2854,7 +2895,8 @@ abstract_issubclass(PyObject *derived, PyObject *cls)
} }
} }
static int // pyston change: removed the static keyword, this function is also used in src/capi/abstract.cpp
int
check_class(PyObject *cls, const char *error) check_class(PyObject *cls, const char *error)
{ {
PyObject *bases = abstract_get_bases(cls); PyObject *bases = abstract_get_bases(cls);
...@@ -2879,11 +2921,15 @@ recursive_isinstance(PyObject *inst, PyObject *cls) ...@@ -2879,11 +2921,15 @@ recursive_isinstance(PyObject *inst, PyObject *cls)
__class__ = PyString_InternFromString("__class__"); __class__ = PyString_InternFromString("__class__");
if (__class__ == NULL) if (__class__ == NULL)
return -1; return -1;
// Pyston change:
PyGC_RegisterStaticConstant(__class__);
} }
if (PyClass_Check(cls) && PyInstance_Check(inst)) { if (PyClass_Check(cls) && PyInstance_Check(inst)) {
PyObject *inclass = // Pyston change:
(PyObject*)((PyInstanceObject*)inst)->in_class; // PyObject *inclass =
// (PyObject*)((PyInstanceObject*)inst)->in_class;
PyObject *inclass = PyInstance_Class(inst);
retval = PyClass_IsSubclass(inclass, cls); retval = PyClass_IsSubclass(inclass, cls);
} }
else if (PyType_Check(cls)) { else if (PyType_Check(cls)) {
...@@ -2922,6 +2968,8 @@ recursive_isinstance(PyObject *inst, PyObject *cls) ...@@ -2922,6 +2968,8 @@ recursive_isinstance(PyObject *inst, PyObject *cls)
return retval; return retval;
} }
// pyston change: comment this out
#if 0
int int
PyObject_IsInstance(PyObject *inst, PyObject *cls) PyObject_IsInstance(PyObject *inst, PyObject *cls)
{ {
...@@ -2974,8 +3022,10 @@ PyObject_IsInstance(PyObject *inst, PyObject *cls) ...@@ -2974,8 +3022,10 @@ PyObject_IsInstance(PyObject *inst, PyObject *cls)
} }
return recursive_isinstance(inst, cls); return recursive_isinstance(inst, cls);
} }
#endif
static int // pyston change: removed the static keyword, this function is also used in src/capi/abstract.cpp
int
recursive_issubclass(PyObject *derived, PyObject *cls) recursive_issubclass(PyObject *derived, PyObject *cls)
{ {
int retval; int retval;
...@@ -3005,6 +3055,8 @@ recursive_issubclass(PyObject *derived, PyObject *cls) ...@@ -3005,6 +3055,8 @@ recursive_issubclass(PyObject *derived, PyObject *cls)
return retval; return retval;
} }
// pyston change: comment this out
#if 0
int int
PyObject_IsSubclass(PyObject *derived, PyObject *cls) PyObject_IsSubclass(PyObject *derived, PyObject *cls)
{ {
...@@ -3059,6 +3111,7 @@ _PyObject_RealIsInstance(PyObject *inst, PyObject *cls) ...@@ -3059,6 +3111,7 @@ _PyObject_RealIsInstance(PyObject *inst, PyObject *cls)
{ {
return recursive_isinstance(inst, cls); return recursive_isinstance(inst, cls);
} }
#endif
int int
_PyObject_RealIsSubclass(PyObject *derived, PyObject *cls) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls)
...@@ -3066,7 +3119,8 @@ _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls) ...@@ -3066,7 +3119,8 @@ _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls)
return recursive_issubclass(derived, cls); return recursive_issubclass(derived, cls);
} }
// pyston change: comment this out
#if 0
PyObject * PyObject *
PyObject_GetIter(PyObject *o) PyObject_GetIter(PyObject *o)
{ {
...@@ -3111,3 +3165,4 @@ PyIter_Next(PyObject *iter) ...@@ -3111,3 +3165,4 @@ PyIter_Next(PyObject *iter)
PyErr_Clear(); PyErr_Clear();
return result; return result;
} }
#endif
// This file is originally from CPython 2.7, with modifications for Pyston
/* /*
Written by Jim Hugunin and Chris Chase. Written by Jim Hugunin and Chris Chase.
...@@ -14,6 +16,9 @@ this type and there is exactly one in existence. ...@@ -14,6 +16,9 @@ this type and there is exactly one in existence.
*/ */
#include "Python.h" #include "Python.h"
// pyston change: comment this out
#if 0
#include "structmember.h" #include "structmember.h"
static PyObject * static PyObject *
...@@ -78,6 +83,7 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step) ...@@ -78,6 +83,7 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
return (PyObject *) obj; return (PyObject *) obj;
} }
#endif
PyObject * PyObject *
_PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop) _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop)
...@@ -98,6 +104,8 @@ _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop) ...@@ -98,6 +104,8 @@ _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop)
return slice; return slice;
} }
// pyston change: comment this out
#if 0
int int
PySlice_GetIndices(PySliceObject *r, Py_ssize_t length, PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
...@@ -360,3 +368,4 @@ PyTypeObject PySlice_Type = { ...@@ -360,3 +368,4 @@ PyTypeObject PySlice_Type = {
0, /* tp_alloc */ 0, /* tp_alloc */
slice_new, /* tp_new */ slice_new, /* tp_new */
}; };
#endif
This diff is collapsed.
...@@ -1906,6 +1906,38 @@ extern "C" int PyCFunction_ClearFreeList() noexcept { ...@@ -1906,6 +1906,38 @@ extern "C" int PyCFunction_ClearFreeList() noexcept {
return 0; // number of entries cleared 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() { void setupCAPI() {
capifunc_cls->giveAttr( capifunc_cls->giveAttr(
"__repr__", new BoxedFunction(FunctionMetadata::create((void*)BoxedCApiFunction::__repr__<CXX>, UNKNOWN, 1))); "__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 ...@@ -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) { static Box* classobjGetattribute(Box* _cls, Box* _attr) {
RELEASE_ASSERT(_cls->cls == classobj_cls, ""); RELEASE_ASSERT(_cls->cls == classobj_cls, "");
BoxedClassobj* cls = static_cast<BoxedClassobj*>(_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