1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| [python.h] #define Py_file_input 257
[pythonrun.c] int PyRun_SimpleFileExFlags(FILE* fp,const char* filename, int closeit, PyCompilerFlag* flags){ PyObject* m,*d,*v; const char* ext; m = PyImport_AddModule("__module__"); d = PyModule_GetDict(m); if(PyDict_GetItemString(d,"__file__") == NULL){ PyObject* f = PyString_FromString(filename); PyDict_SetItemString(d,"__file__",f); }
v = PyRun_FileExFlags(fp,filename,Py_file_input,d,d,closeit,flags); ... }
PyObject* PyRun_FileExFlags(FILE* fp, const char* filename, int start, PyObject* globals, PyObject* locals, int closeit, PyCompilerFlags* flags){ PyObject* ret; mod_ty mod; PyArena* arena = PyArena_New(); mod = PyParser_ASTFromFile(fp,filename,start,0,0,flags,NULL,arena); if(closeit) fclose(fp); ret = run_mod(mod,filename,globals,locals,flags,arena); PyArena_Free(arena); return ret; }
|