Commit 21d52eb8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Runtime setup is complete

parent fa84f801
...@@ -388,12 +388,6 @@ static int main(int argc, char** argv) noexcept { ...@@ -388,12 +388,6 @@ static int main(int argc, char** argv) noexcept {
Py_Initialize(); Py_Initialize();
} }
// XXX
{
Py_Finalize();
return 0;
}
// Arguments left over after option parsing are of the form: // Arguments left over after option parsing are of the form:
// [ script | - ] [ arguments... ] // [ script | - ] [ arguments... ]
// unless we've been already parsed a `-c command` option, in which case only: // unless we've been already parsed a `-c command` option, in which case only:
...@@ -450,6 +444,12 @@ static int main(int argc, char** argv) noexcept { ...@@ -450,6 +444,12 @@ static int main(int argc, char** argv) noexcept {
_t.split("to run"); _t.split("to run");
BoxedModule* main_module = NULL; BoxedModule* main_module = NULL;
// XXX
{
Py_Finalize();
return 0;
}
// if the user invoked `pyston -c command` // if the user invoked `pyston -c command`
if (command != NULL) { if (command != NULL) {
try { try {
......
...@@ -207,15 +207,16 @@ extern "C" void PySys_WriteStderr(const char* format, ...) noexcept { ...@@ -207,15 +207,16 @@ extern "C" void PySys_WriteStderr(const char* format, ...) noexcept {
} }
void addToSysArgv(const char* str) { void addToSysArgv(const char* str) {
Box* sys_argv = sys_module->getattr(internStringMortal("argv")); static BoxedString* argv_str = getStaticString("argv");
Box* sys_argv = sys_module->getattr(argv_str);
assert(sys_argv); assert(sys_argv);
assert(sys_argv->cls == list_cls); assert(sys_argv->cls == list_cls);
listAppendInternal(sys_argv, boxString(str)); listAppendInternal(sys_argv, autoDecref(boxString(str)));
} }
void appendToSysPath(llvm::StringRef path) { void appendToSysPath(llvm::StringRef path) {
BoxedList* sys_path = getSysPath(); BoxedList* sys_path = getSysPath();
listAppendInternal(sys_path, boxString(path)); listAppendInternal(sys_path, autoDecref(boxString(path)));
} }
void prependToSysPath(llvm::StringRef path) { void prependToSysPath(llvm::StringRef path) {
......
...@@ -4224,6 +4224,7 @@ void setupRuntime() { ...@@ -4224,6 +4224,7 @@ void setupRuntime() {
TRACK_ALLOCATIONS = true; TRACK_ALLOCATIONS = true;
#if 0
Box* l = NULL; Box* l = NULL;
for (int i = 0; i < 1000000000; i++) { for (int i = 0; i < 1000000000; i++) {
//if (i % 10000 == 0) { //if (i % 10000 == 0) {
...@@ -4261,7 +4262,7 @@ void setupRuntime() { ...@@ -4261,7 +4262,7 @@ void setupRuntime() {
PRINT_TOTAL_REFS(); PRINT_TOTAL_REFS();
exit(0); exit(0);
// XXX // XXX
#endif
} }
BoxedModule* createModule(BoxedString* name, const char* fn, const char* doc) noexcept { BoxedModule* createModule(BoxedString* name, const char* fn, const char* doc) noexcept {
...@@ -4320,9 +4321,29 @@ extern "C" void Py_Finalize() noexcept { ...@@ -4320,9 +4321,29 @@ extern "C" void Py_Finalize() noexcept {
call_sys_exitfunc(); call_sys_exitfunc();
// initialized = 0; // initialized = 0;
// PyOS_FiniInterrupts(); // XXX
PyGC_Collect(); // To make sure it creates any static objects
IN_SHUTDOWN = true;
PyOS_FiniInterrupts();
PyType_ClearCache(); PyType_ClearCache();
_PyUnicode_Fini();
for (auto b : constants) {
Py_DECREF(b);
}
// May need to run multiple collections to collect everything:
while (PyGC_Collect())
;
_Py_ReleaseInternedStrings();
for (auto b : classes) {
if (!PyObject_IS_GC(b)) {
b->clearAttrs();
Py_CLEAR(b->tp_mro);
}
Py_DECREF(b);
}
// May need to run multiple collections to collect everything:
while (PyGC_Collect())
;
// PyGC_Collect()); // PyGC_Collect());
...@@ -4333,46 +4354,6 @@ extern "C" void Py_Finalize() noexcept { ...@@ -4333,46 +4354,6 @@ extern "C" void Py_Finalize() noexcept {
// _PyGILState_Fini(); // _PyGILState_Fini();
// TODO it's probably a waste of time to tear these down in non-debugging mode
/*
// clear all the attributes on the base classes before freeing the classes themselves,
// since we will run into problem if we free a class but there is an object somewhere
// else that refers to it.
clearAttrs(bool_cls);
clearAttrs(int_cls);
clearAttrs(float_cls);
clearAttrs(none_cls);
clearAttrs(function_cls);
clearAttrs(instancemethod_cls);
clearAttrs(str_cls);
clearAttrs(list_cls);
clearAttrs(slice_cls);
clearAttrs(type_cls);
clearAttrs(module_cls);
clearAttrs(dict_cls);
clearAttrs(tuple_cls);
clearAttrs(file_cls);
decref(bool_cls);
decref(int_cls);
decref(float_cls);
decref(function_cls);
decref(instancemethod_cls);
decref(str_cls);
decref(list_cls);
decref(slice_cls);
decref(module_cls);
decref(dict_cls);
decref(tuple_cls);
decref(file_cls);
ASSERT(None->nrefs == 1, "%ld", None->nrefs);
decref(None);
decref(none_cls);
decref(type_cls);
*/
#if 0 #if 0
/* Delete current thread */ /* Delete current thread */
PyThreadState_Swap(NULL); PyThreadState_Swap(NULL);
......
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