Commit 9cd8624a authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge branch 'socket'

parents 6dab00bb 96637e72
......@@ -291,7 +291,7 @@ STDLIB_OBJS := stdlib.bc.o stdlib.stripped.bc.o
STDLIB_RELEASE_OBJS := stdlib.release.bc.o
ASM_SRCS := $(wildcard src/runtime/*.S)
STDMODULE_SRCS := errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c $(EXTRA_STDMODULE_SRCS)
STDMODULE_SRCS := errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c socketmodule.c $(EXTRA_STDMODULE_SRCS)
STDOBJECT_SRCS := structseq.c capsule.c stringobject.c $(EXTRA_STDOBJECT_SRCS)
STDPYTHON_SRCS := pyctype.c getargs.c formatter_string.c pystrtod.c dtoa.c $(EXTRA_STDPYTHON_SRCS)
FROM_CPYTHON_SRCS := $(addprefix from_cpython/Modules/,$(STDMODULE_SRCS)) $(addprefix from_cpython/Objects/,$(STDOBJECT_SRCS)) $(addprefix from_cpython/Python/,$(STDPYTHON_SRCS))
......
......@@ -15,7 +15,7 @@ endforeach(STDLIB_FILE)
add_custom_target(copy_stdlib ALL DEPENDS ${STDLIB_TARGETS})
# compile specified files in from_cpython/Modules
file(GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c)
file(GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c socketmodule.c)
# compile specified files in from_cpython/Objects
file(GLOB_RECURSE STDOBJECT_SRCS Objects structseq.c capsule.c stringobject.c)
......
......@@ -49,6 +49,10 @@
#define HAVE_SELECT 1
#define HAVE_ALARM 1
#define HAVE_SYMLINK 1
#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"
......
......@@ -12,6 +12,8 @@
#define PYSTON_NOEXCEPT
#endif
#define Py_PROTO(x) x
// Pyston change: these are just hard-coded for now:
typedef ssize_t Py_ssize_t;
#define Py_FORMAT_PARSETUPLE(func,p1,p2)
......
......@@ -4578,6 +4578,9 @@ init_socket(void)
if (!os_init())
return;
// Pyston change: we require calling PyType_Ready for now:
PyType_Ready(&sock_type);
Py_TYPE(&sock_type) = &PyType_Type;
m = Py_InitModule3(PySocket_MODULE_NAME,
socket_methods,
......
......@@ -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;
......
......@@ -439,12 +439,13 @@ public:
void setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite_args);
void giveAttr(const std::string& attr, Box* val) {
assert(this->getattr(attr) == NULL);
assert(!this->hasattr(attr));
this->setattr(attr, val, NULL);
}
Box* getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args);
Box* getattr(const std::string& attr) { return getattr(attr, NULL); }
bool hasattr(const std::string& attr) { return getattr(attr) != NULL; }
void delattr(const std::string& attr, DelattrRewriteArgs* rewrite_args);
Box* reprIC();
......
......@@ -674,8 +674,10 @@ static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int
}
extern "C" PyObject* PyErr_NewException(char* name, PyObject* _base, PyObject* dict) noexcept {
RELEASE_ASSERT(_base == NULL, "unimplemented");
RELEASE_ASSERT(dict == NULL, "unimplemented");
if (_base == NULL)
_base = Exception;
if (dict == NULL)
dict = new BoxedDict();
try {
char* dot_pos = strchr(name, '.');
......@@ -683,13 +685,16 @@ extern "C" PyObject* PyErr_NewException(char* name, PyObject* _base, PyObject* d
int n = strlen(name);
BoxedString* boxedName = boxStrConstantSize(dot_pos + 1, n - (dot_pos - name) - 1);
BoxedClass* base = Exception;
BoxedClass* cls
= new BoxedHeapClass(base, NULL, offsetof(BoxedException, attrs), sizeof(BoxedException), true, boxedName);
// It can also be a tuple of bases
RELEASE_ASSERT(isSubclass(_base->cls, type_cls), "");
BoxedClass* base = static_cast<BoxedClass*>(_base);
cls->giveAttr("__module__", boxStrConstantSize(name, dot_pos - name));
// TODO Not sure if this should be called here
fixup_slot_dispatchers(cls);
if (PyDict_GetItemString(dict, "__module__") == NULL) {
PyDict_SetItemString(dict, "__module__", boxStrConstantSize(name, dot_pos - name));
}
checkAndThrowCAPIException();
Box* cls = runtimeCall(type_cls, ArgPassSpec(3), boxedName, new BoxedTuple({ base }), dict, NULL, NULL);
return cls;
} catch (ExcInfo e) {
abort();
......
......@@ -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)));
......
......@@ -3543,14 +3543,17 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
}
made->tp_dictoffset = base->tp_dictoffset;
made->giveAttr("__module__", boxString(getCurrentModule()->name()));
made->giveAttr("__doc__", None);
for (const auto& p : attr_dict->d) {
assert(p.first->cls == str_cls);
made->setattr(static_cast<BoxedString*>(p.first)->s, p.second, NULL);
}
if (!made->hasattr("__module__"))
made->giveAttr("__module__", boxString(getCurrentModule()->name()));
if (!made->hasattr("__doc__"))
made->giveAttr("__doc__", None);
made->tp_new = base->tp_new;
PystonType_Ready(made);
......
......@@ -63,6 +63,7 @@ extern "C" void inittime();
extern "C" void initarray();
extern "C" void initzlib();
extern "C" void init_codecs();
extern "C" void init_socket();
namespace pyston {
......@@ -739,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>");
......@@ -1300,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(
......@@ -1371,6 +1391,7 @@ void setupRuntime() {
initarray();
initzlib();
init_codecs();
init_socket();
setupSysEnd();
......
# 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