comparison Python/import.c @ 36065:ea083efdc96c legacy-trunk

Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines, simplifies a lot of error handling code, and fixes many memory leaks.
author Neal Norwitz <nnorwitz@gmail.com>
date Sat, 17 Dec 2005 20:54:49 +0000
parents 9541369b0dca
children 1af7f719ed28
comparison
equal deleted inserted replaced
36064:fb6e64eb86c0 36065:ea083efdc96c
2 /* Module definition and import implementation */ 2 /* Module definition and import implementation */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 5
6 #include "Python-ast.h" 6 #include "Python-ast.h"
7 #include "pyarena.h"
7 #include "pythonrun.h" 8 #include "pythonrun.h"
8 #include "errcode.h" 9 #include "errcode.h"
9 #include "marshal.h" 10 #include "marshal.h"
10 #include "code.h" 11 #include "code.h"
11 #include "compile.h" 12 #include "compile.h"
771 static PyCodeObject * 772 static PyCodeObject *
772 parse_source_module(const char *pathname, FILE *fp) 773 parse_source_module(const char *pathname, FILE *fp)
773 { 774 {
774 PyCodeObject *co = NULL; 775 PyCodeObject *co = NULL;
775 mod_ty mod; 776 mod_ty mod;
777 PyArena *arena = PyArena_New();
776 778
777 mod = PyParser_ASTFromFile(fp, pathname, Py_file_input, 0, 0, 0, 779 mod = PyParser_ASTFromFile(fp, pathname, Py_file_input, 0, 0, 0,
778 NULL); 780 NULL, arena);
779 if (mod) { 781 if (mod) {
780 co = PyAST_Compile(mod, pathname, NULL); 782 co = PyAST_Compile(mod, pathname, NULL, arena);
781 free_mod(mod); 783 }
782 } 784 PyArena_Free(arena);
783 return co; 785 return co;
784 } 786 }
785 787
786 788
787 /* Helper to open a bytecode file for writing in exclusive mode */ 789 /* Helper to open a bytecode file for writing in exclusive mode */