Commit 0c693471 authored by Marius Wachtler's avatar Marius Wachtler

add PyObject_AsWriteBuffer, _PyInstance_Lookup, PyInstance_NewRaw, PyInstance_New

parent 4b324243
...@@ -605,6 +605,32 @@ extern "C" int PyObject_AsReadBuffer(PyObject* obj, const void** buffer, Py_ssiz ...@@ -605,6 +605,32 @@ extern "C" int PyObject_AsReadBuffer(PyObject* obj, const void** buffer, Py_ssiz
return 0; return 0;
} }
extern "C" int PyObject_AsWriteBuffer(PyObject* obj, void** buffer, Py_ssize_t* buffer_len) noexcept {
PyBufferProcs* pb;
void* pp;
Py_ssize_t len;
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
null_error();
return -1;
}
pb = obj->cls->tp_as_buffer;
if (pb == NULL || pb->bf_getwritebuffer == NULL || pb->bf_getsegcount == NULL) {
PyErr_SetString(PyExc_TypeError, "expected a writeable buffer object");
return -1;
}
if ((*pb->bf_getsegcount)(obj, NULL) != 1) {
PyErr_SetString(PyExc_TypeError, "expected a single-segment buffer object");
return -1;
}
len = (*pb->bf_getwritebuffer)(obj, 0, &pp);
if (len < 0)
return -1;
*buffer = pp;
*buffer_len = len;
return 0;
}
static PyObject* call_function_tail(PyObject* callable, PyObject* args) { static PyObject* call_function_tail(PyObject* callable, PyObject* args) {
PyObject* retval; PyObject* retval;
......
...@@ -564,10 +564,6 @@ extern "C" int PyObject_HasAttrString(PyObject* v, const char* name) noexcept { ...@@ -564,10 +564,6 @@ extern "C" int PyObject_HasAttrString(PyObject* v, const char* name) noexcept {
return 0; return 0;
} }
extern "C" int PyObject_AsWriteBuffer(PyObject* obj, void** buffer, Py_ssize_t* buffer_len) noexcept {
Py_FatalError("unimplemented");
}
// I'm not sure how we can support this one: // I'm not sure how we can support this one:
extern "C" PyObject** _PyObject_GetDictPtr(PyObject* obj) noexcept { extern "C" PyObject** _PyObject_GetDictPtr(PyObject* obj) noexcept {
fatalOrError(PyExc_NotImplementedError, "unimplemented"); fatalOrError(PyExc_NotImplementedError, "unimplemented");
......
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
BoxedCApiFunction* o = static_cast<BoxedCApiFunction*>(_o); BoxedCApiFunction* o = static_cast<BoxedCApiFunction*>(_o);
Box::gcHandler(v, o); Box::gcHandler(v, o);
v->visitPotential(o->method_def);
v->visit(&o->passthrough); v->visit(&o->passthrough);
v->visit(&o->module); v->visit(&o->module);
} }
......
...@@ -54,6 +54,34 @@ static Box* classLookup(BoxedClassobj* cls, BoxedString* attr, GetattrRewriteArg ...@@ -54,6 +54,34 @@ static Box* classLookup(BoxedClassobj* cls, BoxedString* attr, GetattrRewriteArg
return NULL; return NULL;
} }
extern "C" PyObject* _PyInstance_Lookup(PyObject* pinst, PyObject* pname) noexcept {
RELEASE_ASSERT(PyInstance_Check(pinst), "");
BoxedInstance* inst = (BoxedInstance*)pinst;
RELEASE_ASSERT(PyString_Check(pname), "");
BoxedString* name = (BoxedString*)pname;
try {
internStringMortalInplace(name);
Box* v = inst->getattr(name, NULL);
if (v == NULL)
v = classLookup(inst->inst_cls, name);
return v;
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
}
}
extern "C" PyObject* PyInstance_NewRaw(PyObject* klass, PyObject* dict) noexcept {
RELEASE_ASSERT(!dict, "not implemented");
if (!PyClass_Check(klass)) {
PyErr_BadInternalCall();
return NULL;
}
return new BoxedInstance((BoxedClassobj*)klass);
}
extern "C" int PyClass_IsSubclass(PyObject* klass, PyObject* base) noexcept { extern "C" int PyClass_IsSubclass(PyObject* klass, PyObject* base) noexcept {
Py_ssize_t i, n; Py_ssize_t i, n;
if (klass == base) if (klass == base)
...@@ -155,6 +183,15 @@ Box* classobjCall(Box* _cls, Box* _args, Box* _kwargs) { ...@@ -155,6 +183,15 @@ Box* classobjCall(Box* _cls, Box* _args, Box* _kwargs) {
return made; return made;
} }
extern "C" PyObject* PyInstance_New(PyObject* klass, PyObject* arg, PyObject* kw) noexcept {
try {
return classobjCall(klass, arg, kw);
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
}
}
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