[Python-checkins] CVS: python/dist/src/Python ceval.c,2.196,2.197 compile.c,2.137,2.138 import.c,2.148,2.149
Thomas Wouters
python-dev@python.org
Sun, 27 Aug 2000 13:31:30 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv10284/Python
Modified Files:
ceval.c compile.c import.c
Log Message:
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
how 'import' was called with a compiletime mechanism: create either a tuple
of the import arguments, or None (in the case of a normal import), add it to
the code-block constants, and load it onto the stack before calling
IMPORT_NAME.
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.196
retrieving revision 2.197
diff -C2 -r2.196 -r2.197
*** ceval.c 2000/08/27 17:33:16 2.196
--- ceval.c 2000/08/27 20:31:27 2.197
***************
*** 72,76 ****
static int exec_statement(PyFrameObject *,
PyObject *, PyObject *, PyObject *);
- static PyObject *find_from_args(PyFrameObject *, int);
static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
static void reset_exc_info(PyThreadState *);
--- 72,75 ----
***************
*** 1628,1636 ****
break;
}
! u = find_from_args(f, INSTR_OFFSET());
! if (u == NULL) {
! x = u;
! break;
! }
w = Py_BuildValue("(OOOO)",
w,
--- 1627,1631 ----
break;
}
! u = POP();
w = Py_BuildValue("(OOOO)",
w,
***************
*** 3067,3119 ****
Py_DECREF(v);
return 0;
- }
-
- /* Hack for ni.py */
- static PyObject *
- find_from_args(PyFrameObject *f, int nexti)
- {
- int opcode;
- int oparg;
- PyObject *list, *name;
- unsigned char *next_instr;
-
- _PyCode_GETCODEPTR(f->f_code, &next_instr);
- next_instr += nexti;
-
- opcode = (*next_instr++);
- if (opcode != IMPORT_FROM && opcode != IMPORT_STAR) {
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- list = PyList_New(0);
- if (list == NULL)
- return NULL;
-
- if (opcode == IMPORT_STAR) {
- name = PyString_FromString("*");
- if (!name)
- Py_DECREF(list);
- else {
- if (PyList_Append(list, name) < 0) {
- Py_DECREF(list);
- }
- Py_DECREF(name);
- }
- } else {
- do {
- oparg = (next_instr[1]<<8) + next_instr[0];
- /* Jump over our own argument, the next instruction
- (which is a STORE), and its argument.*/
- next_instr += 5;
- name = Getnamev(f, oparg);
- if (PyList_Append(list, name) < 0) {
- Py_DECREF(list);
- break;
- }
- opcode = (*next_instr++);
- } while (opcode == IMPORT_FROM);
- }
- return list;
}
--- 3062,3065 ----
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.137
retrieving revision 2.138
diff -C2 -r2.137 -r2.138
*** compile.c 2000/08/27 20:16:32 2.137
--- compile.c 2000/08/27 20:31:27 2.138
***************
*** 2330,2333 ****
--- 2330,2334 ----
{
int i;
+ PyObject *tup;
REQ(n, import_stmt);
/* 'import' dotted_name (',' dotted_name)* |
***************
*** 2336,2341 ****
/* 'from' dotted_name 'import' ... */
REQ(CHILD(n, 1), dotted_name);
! com_addopname(c, IMPORT_NAME, CHILD(n, 1));
com_push(c, 1);
if (TYPE(CHILD(n, 3)) == STAR)
com_addbyte(c, IMPORT_STAR);
--- 2337,2354 ----
/* 'from' dotted_name 'import' ... */
REQ(CHILD(n, 1), dotted_name);
!
! if (TYPE(CHILD(n, 3)) == STAR) {
! tup = Py_BuildValue("(s)", "*");
! } else {
! tup = PyTuple_New((NCH(n) - 2)/2);
! for (i = 3; i < NCH(n); i += 2) {
! PyTuple_SET_ITEM(tup, (i-3)/2,
! PyString_FromString(STR(
! CHILD(CHILD(n, i), 0))));
! }
! }
! com_addoparg(c, LOAD_CONST, com_addconst(c, tup));
com_push(c, 1);
+ com_addopname(c, IMPORT_NAME, CHILD(n, 1));
if (TYPE(CHILD(n, 3)) == STAR)
com_addbyte(c, IMPORT_STAR);
***************
*** 2352,2357 ****
node *subn = CHILD(n, i);
REQ(subn, dotted_as_name);
! com_addopname(c, IMPORT_NAME, CHILD(subn, 0));
com_push(c, 1);
if (NCH(subn) > 1) {
int j;
--- 2365,2371 ----
node *subn = CHILD(n, i);
REQ(subn, dotted_as_name);
! com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None));
com_push(c, 1);
+ com_addopname(c, IMPORT_NAME, CHILD(subn, 0));
if (NCH(subn) > 1) {
int j;
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.148
retrieving revision 2.149
diff -C2 -r2.148 -r2.149
*** import.c 2000/08/24 20:11:32 2.148
--- import.c 2000/08/27 20:31:27 2.149
***************
*** 67,71 ****
added to the .pyc file header? */
/* New way to come up with the magic number: (YEAR-1995), MONTH, DAY */
! #define MAGIC (50822 | ((long)'\r'<<16) | ((long)'\n'<<24))
/* Magic word as global; note that _PyImport_Init() can change the
--- 67,71 ----
added to the .pyc file header? */
/* New way to come up with the magic number: (YEAR-1995), MONTH, DAY */
! #define MAGIC (50823 | ((long)'\r'<<16) | ((long)'\n'<<24))
/* Magic word as global; note that _PyImport_Init() can change the
***************
*** 1402,1406 ****
static PyObject *fromlist = NULL;
if (fromlist == NULL && strchr(name, '.') != NULL) {
! fromlist = Py_BuildValue("[s]", "*");
if (fromlist == NULL)
return NULL;
--- 1402,1406 ----
static PyObject *fromlist = NULL;
if (fromlist == NULL && strchr(name, '.') != NULL) {
! fromlist = Py_BuildValue("(s)", "*");
if (fromlist == NULL)
return NULL;