Commit 96637e72 authored by Kevin Modzelewski's avatar Kevin Modzelewski

A number of features to get Lib/socket.py working

- Apparently you can manually create instancemethod objects
- set __doc__ on more things
parent 6876768d
......@@ -52,6 +52,7 @@
#define HAVE_ADDRINFO 1
#define HAVE_SOCKADDR_STORAGE 1
#define HAVE_SOCKETPAIR 1
#define HAVE_GETPEERNAME 1
#define PY_FORMAT_LONG_LONG "ll"
#define PY_FORMAT_SIZE_T "z"
......
......@@ -1862,6 +1862,14 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
PystonType_Ready(cls);
if (!cls->hasattr("__doc__")) {
if (cls->tp_doc) {
cls->giveAttr("__doc__", boxStrConstant(cls->tp_doc));
} else {
cls->giveAttr("__doc__", None);
}
}
if (cls->tp_alloc == &PystonType_GenericAlloc)
cls->tp_alloc = &PyType_GenericAlloc;
......
......@@ -1535,6 +1535,14 @@ Box* BoxedCApiFunction::callInternal(BoxedFunctionBase* func, CallRewriteArgs* r
return r;
}
static Box* method_get_doc(Box* b, void*) {
assert(b->cls == method_cls);
const char* s = static_cast<BoxedMethodDescriptor*>(b)->method->ml_doc;
if (s)
return boxStrConstant(s);
return None;
}
void setupCAPI() {
capifunc_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedCApiFunction), false, "capifunc");
......@@ -1552,6 +1560,7 @@ void setupCAPI() {
new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::__get__, UNKNOWN, 3)));
method_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::__call__, UNKNOWN, 2,
0, true, true)));
method_cls->giveAttr("__doc__", new BoxedGetsetDescriptor(method_get_doc, NULL, NULL));
method_cls->freeze();
wrapperdescr_cls
......
......@@ -171,9 +171,10 @@ void setupDescr() {
member_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)memberGet, UNKNOWN, 3)));
member_cls->freeze();
property_cls->giveAttr(
"__init__",
new BoxedFunction(boxRTFunction((void*)propertyInit, UNKNOWN, 5, 4, false, false), { NULL, NULL, NULL, NULL }));
property_cls->giveAttr("__init__",
new BoxedFunction(boxRTFunction((void*)propertyInit, UNKNOWN, 5, 4, false, false,
ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")),
{ NULL, NULL, NULL, NULL }));
property_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)propertyGet, UNKNOWN, 3)));
property_cls->giveAttr("__set__", new BoxedFunction(boxRTFunction((void*)propertySet, UNKNOWN, 3)));
property_cls->giveAttr("__delete__", new BoxedFunction(boxRTFunction((void*)propertyDel, UNKNOWN, 2)));
......
......@@ -740,6 +740,23 @@ Box* instancemethodGet(BoxedInstanceMethod* self, Box* obj, Box* type) {
return new BoxedInstanceMethod(obj, self->func);
}
Box* instancemethodNew(BoxedClass* cls, Box* func, Box* self, Box** args) {
Box* classObj = args[0];
if (!PyCallable_Check(func)) {
PyErr_SetString(PyExc_TypeError, "first argument must be callable");
return NULL;
}
if (self == Py_None)
self = NULL;
if (self == NULL && classObj == NULL) {
PyErr_SetString(PyExc_TypeError, "unbound methods must have non-NULL im_class");
return NULL;
}
return new BoxedInstanceMethod(self, func);
}
Box* instancemethodRepr(BoxedInstanceMethod* self) {
if (self->obj)
return boxStrConstant("<bound instancemethod object>");
......@@ -1301,6 +1318,8 @@ void setupRuntime() {
new BoxedGetsetDescriptor(builtin_function_or_method_name, NULL, NULL));
builtin_function_or_method_cls->freeze();
instancemethod_cls->giveAttr(
"__new__", new BoxedFunction(boxRTFunction((void*)instancemethodNew, UNKNOWN, 4, 1, false, false), { NULL }));
instancemethod_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)instancemethodRepr, STR, 1)));
instancemethod_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)instancemethodEq, UNKNOWN, 2)));
instancemethod_cls->giveAttr(
......
# allow-warning: converting unicode literal to str
import socket
s = socket.socket()
s.close()
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