Commit 6876768d authored by Kevin Modzelewski's avatar Kevin Modzelewski

import _socket

"import socket" does not quite work yet
parent 6dab00bb
...@@ -291,7 +291,7 @@ STDLIB_OBJS := stdlib.bc.o stdlib.stripped.bc.o ...@@ -291,7 +291,7 @@ STDLIB_OBJS := stdlib.bc.o stdlib.stripped.bc.o
STDLIB_RELEASE_OBJS := stdlib.release.bc.o STDLIB_RELEASE_OBJS := stdlib.release.bc.o
ASM_SRCS := $(wildcard src/runtime/*.S) 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) 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) 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)) 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) ...@@ -15,7 +15,7 @@ endforeach(STDLIB_FILE)
add_custom_target(copy_stdlib ALL DEPENDS ${STDLIB_TARGETS}) add_custom_target(copy_stdlib ALL DEPENDS ${STDLIB_TARGETS})
# compile specified files in from_cpython/Modules # 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 # compile specified files in from_cpython/Objects
file(GLOB_RECURSE STDOBJECT_SRCS Objects structseq.c capsule.c stringobject.c) file(GLOB_RECURSE STDOBJECT_SRCS Objects structseq.c capsule.c stringobject.c)
......
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
#define HAVE_SELECT 1 #define HAVE_SELECT 1
#define HAVE_ALARM 1 #define HAVE_ALARM 1
#define HAVE_SYMLINK 1 #define HAVE_SYMLINK 1
#define HAVE_ADDRINFO 1
#define HAVE_SOCKADDR_STORAGE 1
#define HAVE_SOCKETPAIR 1
#define PY_FORMAT_LONG_LONG "ll" #define PY_FORMAT_LONG_LONG "ll"
#define PY_FORMAT_SIZE_T "z" #define PY_FORMAT_SIZE_T "z"
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#define PYSTON_NOEXCEPT #define PYSTON_NOEXCEPT
#endif #endif
#define Py_PROTO(x) x
// Pyston change: these are just hard-coded for now: // Pyston change: these are just hard-coded for now:
typedef ssize_t Py_ssize_t; typedef ssize_t Py_ssize_t;
#define Py_FORMAT_PARSETUPLE(func,p1,p2) #define Py_FORMAT_PARSETUPLE(func,p1,p2)
......
...@@ -4578,6 +4578,9 @@ init_socket(void) ...@@ -4578,6 +4578,9 @@ init_socket(void)
if (!os_init()) if (!os_init())
return; return;
// Pyston change: we require calling PyType_Ready for now:
PyType_Ready(&sock_type);
Py_TYPE(&sock_type) = &PyType_Type; Py_TYPE(&sock_type) = &PyType_Type;
m = Py_InitModule3(PySocket_MODULE_NAME, m = Py_InitModule3(PySocket_MODULE_NAME,
socket_methods, socket_methods,
......
...@@ -439,12 +439,13 @@ public: ...@@ -439,12 +439,13 @@ public:
void setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite_args); void setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite_args);
void giveAttr(const std::string& attr, Box* val) { void giveAttr(const std::string& attr, Box* val) {
assert(this->getattr(attr) == NULL); assert(!this->hasattr(attr));
this->setattr(attr, val, NULL); this->setattr(attr, val, NULL);
} }
Box* getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args); Box* getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args);
Box* getattr(const std::string& attr) { return getattr(attr, NULL); } 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); void delattr(const std::string& attr, DelattrRewriteArgs* rewrite_args);
Box* reprIC(); Box* reprIC();
......
...@@ -674,8 +674,10 @@ static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int ...@@ -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 { extern "C" PyObject* PyErr_NewException(char* name, PyObject* _base, PyObject* dict) noexcept {
RELEASE_ASSERT(_base == NULL, "unimplemented"); if (_base == NULL)
RELEASE_ASSERT(dict == NULL, "unimplemented"); _base = Exception;
if (dict == NULL)
dict = new BoxedDict();
try { try {
char* dot_pos = strchr(name, '.'); char* dot_pos = strchr(name, '.');
...@@ -683,13 +685,16 @@ extern "C" PyObject* PyErr_NewException(char* name, PyObject* _base, PyObject* d ...@@ -683,13 +685,16 @@ extern "C" PyObject* PyErr_NewException(char* name, PyObject* _base, PyObject* d
int n = strlen(name); int n = strlen(name);
BoxedString* boxedName = boxStrConstantSize(dot_pos + 1, n - (dot_pos - name) - 1); BoxedString* boxedName = boxStrConstantSize(dot_pos + 1, n - (dot_pos - name) - 1);
BoxedClass* base = Exception; // It can also be a tuple of bases
BoxedClass* cls RELEASE_ASSERT(isSubclass(_base->cls, type_cls), "");
= new BoxedHeapClass(base, NULL, offsetof(BoxedException, attrs), sizeof(BoxedException), true, boxedName); BoxedClass* base = static_cast<BoxedClass*>(_base);
cls->giveAttr("__module__", boxStrConstantSize(name, dot_pos - name)); if (PyDict_GetItemString(dict, "__module__") == NULL) {
// TODO Not sure if this should be called here PyDict_SetItemString(dict, "__module__", boxStrConstantSize(name, dot_pos - name));
fixup_slot_dispatchers(cls); }
checkAndThrowCAPIException();
Box* cls = runtimeCall(type_cls, ArgPassSpec(3), boxedName, new BoxedTuple({ base }), dict, NULL, NULL);
return cls; return cls;
} catch (ExcInfo e) { } catch (ExcInfo e) {
abort(); abort();
......
...@@ -3543,14 +3543,17 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) { ...@@ -3543,14 +3543,17 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
} }
made->tp_dictoffset = base->tp_dictoffset; made->tp_dictoffset = base->tp_dictoffset;
made->giveAttr("__module__", boxString(getCurrentModule()->name()));
made->giveAttr("__doc__", None);
for (const auto& p : attr_dict->d) { for (const auto& p : attr_dict->d) {
assert(p.first->cls == str_cls); assert(p.first->cls == str_cls);
made->setattr(static_cast<BoxedString*>(p.first)->s, p.second, NULL); 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; made->tp_new = base->tp_new;
PystonType_Ready(made); PystonType_Ready(made);
......
...@@ -63,6 +63,7 @@ extern "C" void inittime(); ...@@ -63,6 +63,7 @@ extern "C" void inittime();
extern "C" void initarray(); extern "C" void initarray();
extern "C" void initzlib(); extern "C" void initzlib();
extern "C" void init_codecs(); extern "C" void init_codecs();
extern "C" void init_socket();
namespace pyston { namespace pyston {
...@@ -1371,6 +1372,7 @@ void setupRuntime() { ...@@ -1371,6 +1372,7 @@ void setupRuntime() {
initarray(); initarray();
initzlib(); initzlib();
init_codecs(); init_codecs();
init_socket();
setupSysEnd(); setupSysEnd();
......
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