comparison Python/pythonrun.c @ 78117:27e13497d545

Refcounting fixes
author Nick Coghlan <ncoghlan@gmail.com>
date Sun, 15 Jul 2012 23:21:08 +1000
parents 8bf691d0b004
children 2f1494d243ad
comparison
equal deleted inserted replaced
78116:8bf691d0b004 78117:27e13497d545
1354 static set_main_loader(PyObject *d, const char *filename, const char *loader_name) 1354 static set_main_loader(PyObject *d, const char *filename, const char *loader_name)
1355 { 1355 {
1356 PyInterpreterState *interp; 1356 PyInterpreterState *interp;
1357 PyThreadState *tstate; 1357 PyThreadState *tstate;
1358 PyObject *loader_type, *loader; 1358 PyObject *loader_type, *loader;
1359 int result = 0;
1359 /* Get current thread state and interpreter pointer */ 1360 /* Get current thread state and interpreter pointer */
1360 tstate = PyThreadState_GET(); 1361 tstate = PyThreadState_GET();
1361 interp = tstate->interp; 1362 interp = tstate->interp;
1362 loader_type = PyObject_GetAttrString(interp->importlib, loader_name); 1363 loader_type = PyObject_GetAttrString(interp->importlib, loader_name);
1363 if (loader_type == NULL) { 1364 if (loader_type == NULL) {
1364 return -1; 1365 return -1;
1365 } 1366 }
1366 loader = PyObject_CallFunction(loader_type, "ss", "__main__", filename); 1367 loader = PyObject_CallFunction(loader_type, "ss", "__main__", filename);
1367 if (loader == NULL || 1368 Py_DECREF(loader_type);
1368 (PyDict_SetItemString(d, "__loader__", loader) < 0)) { 1369 if (loader == NULL) {
1369 return -1; 1370 return -1;
1370 } 1371 }
1372 if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
1373 result = -1;
1374 }
1371 Py_DECREF(loader); 1375 Py_DECREF(loader);
1372 return 0; 1376 return result;
1373 } 1377 }
1374 1378
1375 int 1379 int
1376 PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, 1380 PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
1377 PyCompilerFlags *flags) 1381 PyCompilerFlags *flags)