Commit ea1c4746 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #481 from kmod/capi_gcroots

Add PyGC_AddRoot calls any time we assign to a static variable
parents 27e04718 961be6f6
...@@ -529,6 +529,7 @@ quick_check: ...@@ -529,6 +529,7 @@ quick_check:
$(MAKE) pyston_dbg $(MAKE) pyston_dbg
$(MAKE) check_format $(MAKE) check_format
$(MAKE) unittests $(MAKE) unittests
$(MAKE) ext_pyston ext_python
$(PYTHON) $(TOOLS_DIR)/tester.py -R pyston_dbg -j$(TEST_THREADS) -a=-S -k --order-by-mtime $(TESTS_DIR) $(ARGS) $(PYTHON) $(TOOLS_DIR)/tester.py -R pyston_dbg -j$(TEST_THREADS) -a=-S -k --order-by-mtime $(TESTS_DIR) $(ARGS)
$(PYTHON) $(TOOLS_DIR)/tester.py -R pyston_dbg -j$(TEST_THREADS) -a=-S -k --exit-code-only --skip-failing $(TEST_DIR)/cpython $(ARGS) $(PYTHON) $(TOOLS_DIR)/tester.py -R pyston_dbg -j$(TEST_THREADS) -a=-S -k --exit-code-only --skip-failing $(TEST_DIR)/cpython $(ARGS)
......
...@@ -1603,7 +1603,7 @@ init_csv(void) ...@@ -1603,7 +1603,7 @@ init_csv(void)
return; return;
/* Add _dialects dictionary */ /* Add _dialects dictionary */
dialects = PyDict_New(); dialects = PyGC_AddRoot(PyDict_New());
if (dialects == NULL) if (dialects == NULL)
return; return;
if (PyModule_AddObject(module, "_dialects", dialects)) if (PyModule_AddObject(module, "_dialects", dialects))
...@@ -1622,7 +1622,7 @@ init_csv(void) ...@@ -1622,7 +1622,7 @@ init_csv(void)
return; return;
/* Add the CSV exception object to the module. */ /* Add the CSV exception object to the module. */
error_obj = PyErr_NewException("_csv.Error", NULL, NULL); error_obj = PyGC_AddRoot(PyErr_NewException("_csv.Error", NULL, NULL));
if (error_obj == NULL) if (error_obj == NULL)
return; return;
PyModule_AddObject(module, "Error", error_obj); PyModule_AddObject(module, "Error", error_obj);
......
...@@ -730,7 +730,7 @@ _PyIO_trap_eintr(void) ...@@ -730,7 +730,7 @@ _PyIO_trap_eintr(void)
PyEnvironmentErrorObject *env_err; PyEnvironmentErrorObject *env_err;
if (eintr_int == NULL) { if (eintr_int == NULL) {
eintr_int = PyLong_FromLong(EINTR); eintr_int = PyGC_AddRoot(PyLong_FromLong(EINTR));
assert(eintr_int != NULL); assert(eintr_int != NULL);
} }
if (!PyErr_ExceptionMatches(PyExc_EnvironmentError)) if (!PyErr_ExceptionMatches(PyExc_EnvironmentError))
......
...@@ -1777,9 +1777,9 @@ init_ssl(void) ...@@ -1777,9 +1777,9 @@ init_ssl(void)
OpenSSL_add_all_algorithms(); OpenSSL_add_all_algorithms();
/* Add symbols to module dict */ /* Add symbols to module dict */
PySSLErrorObject = PyErr_NewException("ssl.SSLError", PySSLErrorObject = PyGC_AddRoot(PyErr_NewException("ssl.SSLError",
PySocketModule.error, PySocketModule.error,
NULL); NULL));
if (PySSLErrorObject == NULL) if (PySSLErrorObject == NULL)
return; return;
if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0) if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0)
......
...@@ -2077,7 +2077,7 @@ init_struct(void) ...@@ -2077,7 +2077,7 @@ init_struct(void)
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
if (StructError == NULL) { if (StructError == NULL) {
StructError = PyErr_NewException("struct.error", NULL, NULL); StructError = PyGC_AddRoot(PyErr_NewException("struct.error", NULL, NULL));
if (StructError == NULL) if (StructError == NULL)
return; return;
} }
......
...@@ -1511,8 +1511,8 @@ initbinascii(void) ...@@ -1511,8 +1511,8 @@ initbinascii(void)
PyDict_SetItemString(d, "__doc__", x); PyDict_SetItemString(d, "__doc__", x);
Py_XDECREF(x); Py_XDECREF(x);
Error = PyErr_NewException("binascii.Error", NULL, NULL); Error = PyGC_AddRoot(PyErr_NewException("binascii.Error", NULL, NULL));
PyDict_SetItemString(d, "Error", Error); PyDict_SetItemString(d, "Error", Error);
Incomplete = PyErr_NewException("binascii.Incomplete", NULL, NULL); Incomplete = PyGC_AddRoot(PyErr_NewException("binascii.Incomplete", NULL, NULL));
PyDict_SetItemString(d, "Incomplete", Incomplete); PyDict_SetItemString(d, "Incomplete", Incomplete);
} }
...@@ -3936,7 +3936,7 @@ datetime_strptime(PyObject *cls, PyObject *args) ...@@ -3936,7 +3936,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
return NULL; return NULL;
if (module == NULL && if (module == NULL &&
(module = PyImport_ImportModuleNoBlock("_strptime")) == NULL) (module = PyGC_AddRoot(PyImport_ImportModuleNoBlock("_strptime"))) == NULL)
return NULL; return NULL;
/* _strptime._strptime returns a two-element tuple. The first /* _strptime._strptime returns a two-element tuple. The first
......
...@@ -4935,7 +4935,7 @@ _PyPopen(char *cmdstring, int mode, int n, int bufsize) ...@@ -4935,7 +4935,7 @@ _PyPopen(char *cmdstring, int mode, int n, int bufsize)
*/ */
if (!_PyPopenProcs) if (!_PyPopenProcs)
{ {
_PyPopenProcs = PyDict_New(); _PyPopenProcs = PyGC_AddRoot(PyDict_New());
} }
if (_PyPopenProcs) if (_PyPopenProcs)
...@@ -5682,7 +5682,7 @@ _PyPopen(char *cmdstring, int mode, int n) ...@@ -5682,7 +5682,7 @@ _PyPopen(char *cmdstring, int mode, int n)
* and variable number of files involved. * and variable number of files involved.
*/ */
if (!_PyPopenProcs) { if (!_PyPopenProcs) {
_PyPopenProcs = PyDict_New(); _PyPopenProcs = PyGC_AddRoot(PyDict_New());
} }
if (_PyPopenProcs) { if (_PyPopenProcs) {
...@@ -6105,7 +6105,7 @@ wait_helper(pid_t pid, int status, struct rusage *ru) ...@@ -6105,7 +6105,7 @@ wait_helper(pid_t pid, int status, struct rusage *ru)
PyObject *m = PyImport_ImportModuleNoBlock("resource"); PyObject *m = PyImport_ImportModuleNoBlock("resource");
if (m == NULL) if (m == NULL)
return NULL; return NULL;
struct_rusage = PyObject_GetAttrString(m, "struct_rusage"); struct_rusage = PyGC_AddRoot(PyObject_GetAttrString(m, "struct_rusage"));
Py_DECREF(m); Py_DECREF(m);
if (struct_rusage == NULL) if (struct_rusage == NULL)
return NULL; return NULL;
......
...@@ -254,8 +254,8 @@ initresource(void) ...@@ -254,8 +254,8 @@ initresource(void)
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
if (ResourceError == NULL) { if (ResourceError == NULL) {
ResourceError = PyErr_NewException("resource.error", ResourceError = PyGC_AddRoot(PyErr_NewException("resource.error",
NULL, NULL); NULL, NULL));
} }
Py_INCREF(ResourceError); Py_INCREF(ResourceError);
PyModule_AddObject(m, "error", ResourceError); PyModule_AddObject(m, "error", ResourceError);
......
...@@ -1807,7 +1807,7 @@ initselect(void) ...@@ -1807,7 +1807,7 @@ initselect(void)
if (m == NULL) if (m == NULL)
return; return;
SelectError = PyErr_NewException("select.error", NULL, NULL); SelectError = PyGC_AddRoot(PyErr_NewException("select.error", NULL, NULL));
Py_INCREF(SelectError); Py_INCREF(SelectError);
PyModule_AddObject(m, "error", SelectError); PyModule_AddObject(m, "error", SelectError);
......
...@@ -587,11 +587,11 @@ initsignal(void) ...@@ -587,11 +587,11 @@ initsignal(void)
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
x = DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL); x = DefaultHandler = PyGC_AddRoot(PyLong_FromVoidPtr((void *)SIG_DFL));
if (!x || PyDict_SetItemString(d, "SIG_DFL", x) < 0) if (!x || PyDict_SetItemString(d, "SIG_DFL", x) < 0)
goto finally; goto finally;
x = IgnoreHandler = PyLong_FromVoidPtr((void *)SIG_IGN); x = IgnoreHandler = PyGC_AddRoot(PyLong_FromVoidPtr((void *)SIG_IGN));
if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0) if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0)
goto finally; goto finally;
...@@ -600,7 +600,7 @@ initsignal(void) ...@@ -600,7 +600,7 @@ initsignal(void)
goto finally; goto finally;
Py_DECREF(x); Py_DECREF(x);
x = IntHandler = PyDict_GetItemString(d, "default_int_handler"); x = IntHandler = PyGC_AddRoot(PyDict_GetItemString(d, "default_int_handler"));
if (!x) if (!x)
goto finally; goto finally;
Py_INCREF(IntHandler); Py_INCREF(IntHandler);
...@@ -834,8 +834,8 @@ initsignal(void) ...@@ -834,8 +834,8 @@ initsignal(void)
#endif #endif
#if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER) #if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
ItimerError = PyErr_NewException("signal.ItimerError", ItimerError = PyGC_AddRoot(PyErr_NewException("signal.ItimerError",
PyExc_IOError, NULL); PyExc_IOError, NULL));
if (ItimerError != NULL) if (ItimerError != NULL)
PyDict_SetItemString(d, "ItimerError", ItimerError); PyDict_SetItemString(d, "ItimerError", ItimerError);
#endif #endif
......
...@@ -4588,27 +4588,27 @@ init_socket(void) ...@@ -4588,27 +4588,27 @@ init_socket(void)
if (m == NULL) if (m == NULL)
return; return;
socket_error = PyErr_NewException("socket.error", socket_error = PyGC_AddRoot(PyErr_NewException("socket.error",
PyExc_IOError, NULL); PyExc_IOError, NULL));
if (socket_error == NULL) if (socket_error == NULL)
return; return;
PySocketModuleAPI.error = socket_error; PySocketModuleAPI.error = socket_error;
Py_INCREF(socket_error); Py_INCREF(socket_error);
PyModule_AddObject(m, "error", socket_error); PyModule_AddObject(m, "error", socket_error);
socket_herror = PyErr_NewException("socket.herror", socket_herror = PyGC_AddRoot(PyErr_NewException("socket.herror",
socket_error, NULL); socket_error, NULL));
if (socket_herror == NULL) if (socket_herror == NULL)
return; return;
Py_INCREF(socket_herror); Py_INCREF(socket_herror);
PyModule_AddObject(m, "herror", socket_herror); PyModule_AddObject(m, "herror", socket_herror);
socket_gaierror = PyErr_NewException("socket.gaierror", socket_error, socket_gaierror = PyGC_AddRoot(PyErr_NewException("socket.gaierror", socket_error,
NULL); NULL));
if (socket_gaierror == NULL) if (socket_gaierror == NULL)
return; return;
Py_INCREF(socket_gaierror); Py_INCREF(socket_gaierror);
PyModule_AddObject(m, "gaierror", socket_gaierror); PyModule_AddObject(m, "gaierror", socket_gaierror);
socket_timeout = PyErr_NewException("socket.timeout", socket_timeout = PyGC_AddRoot(PyErr_NewException("socket.timeout",
socket_error, NULL); socket_error, NULL));
if (socket_timeout == NULL) if (socket_timeout == NULL)
return; return;
Py_INCREF(socket_timeout); Py_INCREF(socket_timeout);
......
...@@ -911,7 +911,7 @@ initthread(void) ...@@ -911,7 +911,7 @@ initthread(void)
/* Add a symbolic constant */ /* Add a symbolic constant */
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
ThreadError = PyErr_NewException("thread.error", NULL, NULL); ThreadError = PyGC_AddRoot(PyErr_NewException("thread.error", NULL, NULL));
PyDict_SetItemString(d, "error", ThreadError); PyDict_SetItemString(d, "error", ThreadError);
Locktype.tp_doc = lock_doc; Locktype.tp_doc = lock_doc;
if (PyType_Ready(&Locktype) < 0) if (PyType_Ready(&Locktype) < 0)
...@@ -925,7 +925,7 @@ initthread(void) ...@@ -925,7 +925,7 @@ initthread(void)
nb_threads = 0; nb_threads = 0;
str_dict = PyString_InternFromString("__dict__"); str_dict = PyGC_AddRoot(PyString_InternFromString("__dict__"));
if (str_dict == NULL) if (str_dict == NULL)
return; return;
......
...@@ -864,7 +864,7 @@ inittime(void) ...@@ -864,7 +864,7 @@ inittime(void)
*/ */
Py_XDECREF(moddict); Py_XDECREF(moddict);
/* Squirrel away the module's dictionary for the y2k check */ /* Squirrel away the module's dictionary for the y2k check */
moddict = PyModule_GetDict(m); moddict = PyGC_AddRoot(PyModule_GetDict(m));
Py_INCREF(moddict); Py_INCREF(moddict);
/* Set, or reset, module variables like time.timezone */ /* Set, or reset, module variables like time.timezone */
......
...@@ -1246,8 +1246,8 @@ initzipimport(void) ...@@ -1246,8 +1246,8 @@ initzipimport(void)
if (mod == NULL) if (mod == NULL)
return; return;
ZipImportError = PyErr_NewException("zipimport.ZipImportError", ZipImportError = PyGC_AddRoot(PyErr_NewException("zipimport.ZipImportError",
PyExc_ImportError, NULL); PyExc_ImportError, NULL));
if (ZipImportError == NULL) if (ZipImportError == NULL)
return; return;
...@@ -1261,7 +1261,7 @@ initzipimport(void) ...@@ -1261,7 +1261,7 @@ initzipimport(void)
(PyObject *)&ZipImporter_Type) < 0) (PyObject *)&ZipImporter_Type) < 0)
return; return;
zip_directory_cache = PyDict_New(); zip_directory_cache = PyGC_AddRoot(PyDict_New());
if (zip_directory_cache == NULL) if (zip_directory_cache == NULL)
return; return;
Py_INCREF(zip_directory_cache); Py_INCREF(zip_directory_cache);
......
...@@ -1066,7 +1066,7 @@ PyInit_zlib(void) ...@@ -1066,7 +1066,7 @@ PyInit_zlib(void)
if (m == NULL) if (m == NULL)
return; return;
ZlibError = PyErr_NewException("zlib.error", NULL, NULL); ZlibError = PyGC_AddRoot(PyErr_NewException("zlib.error", NULL, NULL));
if (ZlibError != NULL) { if (ZlibError != NULL) {
Py_INCREF(ZlibError); Py_INCREF(ZlibError);
PyModule_AddObject(m, "error", ZlibError); PyModule_AddObject(m, "error", ZlibError);
......
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