Commit 393ee878 authored by Kevin Modzelewski's avatar Kevin Modzelewski

capi fix: we were setting PyCFunction_Type to the wrong class

parent 73140839
...@@ -14,8 +14,8 @@ extern "C" { ...@@ -14,8 +14,8 @@ extern "C" {
// Pyston change: this is no longer a static object // Pyston change: this is no longer a static object
//PyAPI_DATA(PyTypeObject) PyCFunction_Type; //PyAPI_DATA(PyTypeObject) PyCFunction_Type;
PyAPI_DATA(PyTypeObject*) builtin_function_or_method_cls; PyAPI_DATA(PyTypeObject*) capifunc_cls;
#define PyCFunction_Type (*builtin_function_or_method_cls) #define PyCFunction_Type (*capifunc_cls)
#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type) #define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
...@@ -28,6 +28,8 @@ PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *) PYSTON_NOEXCEPT; ...@@ -28,6 +28,8 @@ PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *) PYSTON_NOEXCEPT;
// Pyston change: changed to function calls
#if 0
/* Macros for direct access to these values. Type checks are *not* /* Macros for direct access to these values. Type checks are *not*
done, so use with care. */ done, so use with care. */
#define PyCFunction_GET_FUNCTION(func) \ #define PyCFunction_GET_FUNCTION(func) \
...@@ -36,6 +38,13 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *) PYSTON_NOEXCEPT; ...@@ -36,6 +38,13 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *) PYSTON_NOEXCEPT;
(((PyCFunctionObject *)func) -> m_self) (((PyCFunctionObject *)func) -> m_self)
#define PyCFunction_GET_FLAGS(func) \ #define PyCFunction_GET_FLAGS(func) \
(((PyCFunctionObject *)func) -> m_ml -> ml_flags) (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
#endif
#define PyCFunction_GET_FUNCTION(func) \
PyCFunction_GetFunction((PyObject*)(func))
#define PyCFunction_GET_SELF(func) \
PyCFunction_GetSelf((PyObject*)(func))
#define PyCFunction_GET_FLAGS(func) \
PyCFunction_GetFlags((PyObject*)(func))
PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *) PYSTON_NOEXCEPT;
struct PyMethodDef { struct PyMethodDef {
...@@ -82,12 +91,15 @@ typedef struct PyMethodChain { ...@@ -82,12 +91,15 @@ typedef struct PyMethodChain {
PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *, PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
const char *) PYSTON_NOEXCEPT; const char *) PYSTON_NOEXCEPT;
// Pyston change: not our format
#if 0
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
PyMethodDef *m_ml; /* Description of the C function to call */ PyMethodDef *m_ml; /* Description of the C function to call */
PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
PyObject *m_module; /* The __module__ attribute, can be anything */ PyObject *m_module; /* The __module__ attribute, can be anything */
} PyCFunctionObject; } PyCFunctionObject;
#endif
PyAPI_FUNC(int) PyCFunction_ClearFreeList(void) PYSTON_NOEXCEPT; PyAPI_FUNC(int) PyCFunction_ClearFreeList(void) PYSTON_NOEXCEPT;
......
...@@ -244,14 +244,14 @@ ...@@ -244,14 +244,14 @@
#define HAVE_SYS_WAIT_H 1 #define HAVE_SYS_WAIT_H 1
#define HAVE_TCGETPGRP 1 #define HAVE_TCGETPGRP 1
#define HAVE_TCSETPGRP 1 #define HAVE_TCSETPGRP 1
#define HAVE_TEMPNAM 1 //#define HAVE_TEMPNAM 1 // pyston change: we have them but I dislike the compiler warnings they generate
#define HAVE_TERM_H 1 #define HAVE_TERM_H 1
#define HAVE_TERMIOS_H 1 #define HAVE_TERMIOS_H 1
#define HAVE_TGAMMA 1 #define HAVE_TGAMMA 1
#define HAVE_TIMEGM 1 #define HAVE_TIMEGM 1
#define HAVE_TIMES 1 #define HAVE_TIMES 1
#define HAVE_TMPFILE 1 #define HAVE_TMPFILE 1
#define HAVE_TMPNAM 1 //#define HAVE_TMPNAM 1 // pyston change: we have them but I dislike the compiler warnings they generate
#define HAVE_TMPNAM_R 1 #define HAVE_TMPNAM_R 1
#define HAVE_TM_ZONE 1 #define HAVE_TM_ZONE 1
#define HAVE_TRUNCATE 1 #define HAVE_TRUNCATE 1
......
...@@ -27,6 +27,8 @@ static const std::string _getattr_str("__getattr__"); ...@@ -27,6 +27,8 @@ static const std::string _getattr_str("__getattr__");
static const std::string _getattribute_str("__getattribute__"); static const std::string _getattribute_str("__getattribute__");
typedef int (*update_callback)(PyTypeObject*, void*); typedef int (*update_callback)(PyTypeObject*, void*);
static PyObject* tp_new_wrapper(PyTypeObject* self, BoxedTuple* args, Box* kwds) noexcept;
extern "C" void conservativeGCHandler(GCVisitor* v, Box* b) noexcept { extern "C" void conservativeGCHandler(GCVisitor* v, Box* b) noexcept {
v->visitPotentialRange((void* const*)b, (void* const*)((char*)b + b->cls->tp_basicsize)); v->visitPotentialRange((void* const*)b, (void* const*)((char*)b + b->cls->tp_basicsize));
} }
...@@ -1591,8 +1593,6 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce ...@@ -1591,8 +1593,6 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce
else else
use_generic = 1; use_generic = 1;
} }
// TODO Pyston doesn't support PyCFunction_Type yet I think?
#if 0
} else if (Py_TYPE(descr) == &PyCFunction_Type && PyCFunction_GET_FUNCTION(descr) == (PyCFunction)tp_new_wrapper } else if (Py_TYPE(descr) == &PyCFunction_Type && PyCFunction_GET_FUNCTION(descr) == (PyCFunction)tp_new_wrapper
&& ptr == (void**)&type->tp_new) { && ptr == (void**)&type->tp_new) {
/* The __new__ wrapper is not a wrapper descriptor, /* The __new__ wrapper is not a wrapper descriptor,
...@@ -1611,7 +1611,6 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce ...@@ -1611,7 +1611,6 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce
in this reasoning that requires additional in this reasoning that requires additional
sanity checks. I'll buy the first person to sanity checks. I'll buy the first person to
point out a bug in this reasoning a beer. */ point out a bug in this reasoning a beer. */
#endif
} else if (offset == offsetof(BoxedClass, tp_descr_get) && descr->cls == function_cls } else if (offset == offsetof(BoxedClass, tp_descr_get) && descr->cls == function_cls
&& static_cast<BoxedFunction*>(descr)->f->always_use_version) { && static_cast<BoxedFunction*>(descr)->f->always_use_version) {
type->tpp_descr_get = (descrgetfunc) static_cast<BoxedFunction*>(descr)->f->always_use_version->code; type->tpp_descr_get = (descrgetfunc) static_cast<BoxedFunction*>(descr)->f->always_use_version->code;
......
...@@ -52,6 +52,8 @@ public: ...@@ -52,6 +52,8 @@ public:
DEFAULT_CLASS(capifunc_cls); DEFAULT_CLASS(capifunc_cls);
PyCFunction getFunction() { return func; }
static BoxedString* __repr__(BoxedCApiFunction* self) { static BoxedString* __repr__(BoxedCApiFunction* self) {
assert(self->cls == capifunc_cls); assert(self->cls == capifunc_cls);
return boxStrConstant(self->name); return boxStrConstant(self->name);
......
...@@ -1273,7 +1273,7 @@ extern "C" PyCFunction PyCFunction_GetFunction(PyObject* op) noexcept { ...@@ -1273,7 +1273,7 @@ extern "C" PyCFunction PyCFunction_GetFunction(PyObject* op) noexcept {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return NULL; return NULL;
} }
return ((PyCFunctionObject*)op)->m_ml->ml_meth; return static_cast<BoxedCApiFunction*>(op)->getFunction();
} }
extern "C" int _PyEval_SliceIndex(PyObject* v, Py_ssize_t* pi) noexcept { extern "C" int _PyEval_SliceIndex(PyObject* v, Py_ssize_t* pi) noexcept {
......
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