Commit 15acc85c authored by Marius Wachtler's avatar Marius Wachtler

Merge commit '9b30997a' into refcounting

Conflicts:
	src/runtime/builtin_modules/builtins.cpp
	src/runtime/builtin_modules/sys.cpp
parents 273c6644 9b30997a
...@@ -1359,7 +1359,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ ...@@ -1359,7 +1359,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
*/ */
#define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL) #define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)
PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, const char *key) PYSTON_NOEXCEPT;
/* /*
Return element of o corresponding to the object, key, or NULL Return element of o corresponding to the object, key, or NULL
...@@ -1367,7 +1367,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ ...@@ -1367,7 +1367,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
o[key]. o[key].
*/ */
PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, char *key, PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key,
PyObject *value) PYSTON_NOEXCEPT; PyObject *value) PYSTON_NOEXCEPT;
/* /*
......
...@@ -1806,7 +1806,7 @@ extern "C" int PyMapping_HasKey(PyObject* o, PyObject* key) noexcept { ...@@ -1806,7 +1806,7 @@ extern "C" int PyMapping_HasKey(PyObject* o, PyObject* key) noexcept {
return 0; return 0;
} }
extern "C" PyObject* PyMapping_GetItemString(PyObject* o, char* key) noexcept { extern "C" PyObject* PyMapping_GetItemString(PyObject* o, const char* key) noexcept {
PyObject* okey, *r; PyObject* okey, *r;
if (key == NULL) if (key == NULL)
...@@ -1820,7 +1820,7 @@ extern "C" PyObject* PyMapping_GetItemString(PyObject* o, char* key) noexcept { ...@@ -1820,7 +1820,7 @@ extern "C" PyObject* PyMapping_GetItemString(PyObject* o, char* key) noexcept {
return r; return r;
} }
extern "C" int PyMapping_SetItemString(PyObject* o, char* key, PyObject* value) noexcept { extern "C" int PyMapping_SetItemString(PyObject* o, const char* key, PyObject* value) noexcept {
PyObject* okey; PyObject* okey;
int r; int r;
......
...@@ -43,7 +43,10 @@ public: ...@@ -43,7 +43,10 @@ public:
static BoxedString* __repr__(BoxedCApiFunction* self) { static BoxedString* __repr__(BoxedCApiFunction* self) {
assert(self->cls == capifunc_cls); assert(self->cls == capifunc_cls);
return boxString(self->method_def->ml_name); if (self->passthrough == NULL)
return (BoxedString*)PyString_FromFormat("<built-in function %s>", self->method_def->ml_name);
return (BoxedString*)PyString_FromFormat("<built-in method %s of %s object at %p>", self->method_def->ml_name,
self->passthrough->cls->tp_name, self->passthrough);
} }
static Box* __call__(BoxedCApiFunction* self, BoxedTuple* varargs, BoxedDict* kwargs); static Box* __call__(BoxedCApiFunction* self, BoxedTuple* varargs, BoxedDict* kwargs);
......
...@@ -343,11 +343,34 @@ void registerMainThread() { ...@@ -343,11 +343,34 @@ void registerMainThread() {
current_threads[pthread_self()] = current_internal_thread_state; current_threads[pthread_self()] = current_internal_thread_state;
} }
/* Wait until threading._shutdown completes, provided
the threading module was imported in the first place.
The shutdown routine will wait until all non-daemon
"threading" threads have completed. */
static void wait_for_thread_shutdown(void) noexcept {
#ifdef WITH_THREAD
PyObject* result;
PyThreadState* tstate = PyThreadState_GET();
PyObject* threading = PyMapping_GetItemString(getSysModulesDict(), "threading");
if (threading == NULL) {
/* threading not imported */
PyErr_Clear();
return;
}
result = PyObject_CallMethod(threading, "_shutdown", "");
if (result == NULL)
PyErr_WriteUnraisable(threading);
else
Py_DECREF(result);
Py_DECREF(threading);
#endif
}
void finishMainThread() { void finishMainThread() {
assert(current_internal_thread_state); assert(current_internal_thread_state);
current_internal_thread_state->assertNoGenerators(); current_internal_thread_state->assertNoGenerators();
// TODO maybe this is the place to wait for non-daemon threads? wait_for_thread_shutdown();
} }
bool isMainThread() { bool isMainThread() {
...@@ -422,6 +445,22 @@ extern "C" void PyEval_ReInitThreads() noexcept { ...@@ -422,6 +445,22 @@ extern "C" void PyEval_ReInitThreads() noexcept {
threads_waiting_on_gil = 0; threads_waiting_on_gil = 0;
PerThreadSetBase::runAllForkHandlers(); PerThreadSetBase::runAllForkHandlers();
/* Update the threading module with the new state.
*/
Box* threading = PyMapping_GetItemString(getSysModulesDict(), "threading");
if (threading == NULL) {
/* threading not imported */
PyErr_Clear();
return;
}
Box* result = PyObject_CallMethod(threading, "_after_fork", NULL);
if (result == NULL)
PyErr_WriteUnraisable(threading);
else
Py_DECREF(result);
Py_DECREF(threading);
} }
void acquireGLWrite() { void acquireGLWrite() {
......
...@@ -2591,7 +2591,7 @@ void setupBuiltins() { ...@@ -2591,7 +2591,7 @@ void setupBuiltins() {
}; };
for (auto& md : builtin_methods) { for (auto& md : builtin_methods) {
builtins_module->giveAttr(md.ml_name, builtins_module->giveAttr(md.ml_name,
new BoxedCApiFunction(&md, builtins_module, autoDecref(boxString("__builtin__")))); new BoxedCApiFunction(&md, NULL, autoDecref(boxString("__builtin__"))));
} }
} }
} }
...@@ -73,9 +73,6 @@ Box* sysExcClear() { ...@@ -73,9 +73,6 @@ Box* sysExcClear() {
static Box* sysExit(Box* arg) { static Box* sysExit(Box* arg) {
assert(arg); assert(arg);
Box* exc = runtimeCall(SystemExit, ArgPassSpec(1), arg, NULL, NULL, NULL, NULL); Box* exc = runtimeCall(SystemExit, ArgPassSpec(1), arg, NULL, NULL, NULL, NULL);
// TODO this should be handled by the SystemExit constructor
exc->giveAttrBorrowed("code", arg);
raiseExc(exc); raiseExc(exc);
} }
...@@ -773,7 +770,7 @@ void setupSys() { ...@@ -773,7 +770,7 @@ void setupSys() {
auto sys_str = getStaticString("sys"); auto sys_str = getStaticString("sys");
for (auto& md : sys_methods) { for (auto& md : sys_methods) {
sys_module->giveAttr(md.ml_name, new BoxedCApiFunction(&md, sys_module, sys_str)); sys_module->giveAttr(md.ml_name, new BoxedCApiFunction(&md, NULL, sys_str));
} }
sys_module->giveAttrBorrowed("__displayhook__", sys_module->getattr(autoDecref(internStringMortal("displayhook")))); sys_module->giveAttrBorrowed("__displayhook__", sys_module->getattr(autoDecref(internStringMortal("displayhook"))));
......
...@@ -90,7 +90,7 @@ static void* thread_start(Box* target, Box* varargs, Box* kwargs) { ...@@ -90,7 +90,7 @@ static void* thread_start(Box* target, Box* varargs, Box* kwargs) {
// TODO this should take kwargs, which defaults to empty // TODO this should take kwargs, which defaults to empty
Box* startNewThread(Box* target, Box* args, Box* kw) { Box* startNewThread(Box* target, Box* args, Box* kw) {
intptr_t thread_id = start_thread(&thread_start, target, args, kw); intptr_t thread_id = start_thread(&thread_start, target, args, kw);
return boxInt(thread_id ^ 0x12345678901L); return boxInt(thread_id);
} }
#define CHECK_STATUS(name) \ #define CHECK_STATUS(name) \
......
print compile
c = compile("a", "test.py", "eval") c = compile("a", "test.py", "eval")
print type(c), c.co_filename, c.co_name print type(c), c.co_filename, c.co_name
......
import sys import sys
import os.path import os.path
print sys.excepthook, sys.displayhook
print sys.version[:3] print sys.version[:3]
print os.path.exists(sys.executable) print os.path.exists(sys.executable)
print sys.copyright[-200:] print sys.copyright[-200:]
......
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