Mercurial > cpython-lru_cache-weakref
annotate Objects/codeobject.c @ 55580:7b495c8f2a24 3.1
Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
................
r73941 | georg.brandl | 2009-07-11 12:39:00 +0200 (Sa, 11 Jul 2009) | 9 lines
Merged revisions 73940 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73940 | georg.brandl | 2009-07-11 12:37:38 +0200 (Sa, 11 Jul 2009) | 1 line
#6430: add note about size of "u" type.
........
................
r73942 | georg.brandl | 2009-07-11 12:39:23 +0200 (Sa, 11 Jul 2009) | 1 line
#6430: remove mention of "w" array typecode.
................
r73943 | georg.brandl | 2009-07-11 12:43:08 +0200 (Sa, 11 Jul 2009) | 1 line
#6421: The self argument of module-level PyCFunctions is now a reference to the module object.
................
r74076 | georg.brandl | 2009-07-18 11:07:48 +0200 (Sa, 18 Jul 2009) | 1 line
#6502: add missing comma in docstring.
................
r74094 | georg.brandl | 2009-07-19 09:25:56 +0200 (So, 19 Jul 2009) | 10 lines
Recorded merge of revisions 74089 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74089 | senthil.kumaran | 2009-07-19 04:43:43 +0200 (So, 19 Jul 2009) | 3 lines
Fix for issue5102, timeout value propages between redirects, proxy, digest and
auth handlers. Fixed tests to reflect the same.
........
................
r74186 | georg.brandl | 2009-07-23 11:19:09 +0200 (Do, 23 Jul 2009) | 9 lines
Recorded merge of revisions 74185 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74185 | georg.brandl | 2009-07-23 11:17:09 +0200 (Do, 23 Jul 2009) | 1 line
Fix the "pylocals" gdb command.
........
................
r74211 | georg.brandl | 2009-07-26 16:48:09 +0200 (So, 26 Jul 2009) | 9 lines
Recorded merge of revisions 74210 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74210 | georg.brandl | 2009-07-26 16:44:23 +0200 (So, 26 Jul 2009) | 1 line
Move member descriptions inside the classes.
........
................
r74212 | georg.brandl | 2009-07-26 16:54:51 +0200 (So, 26 Jul 2009) | 9 lines
Merged revisions 74209 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74209 | georg.brandl | 2009-07-26 16:37:28 +0200 (So, 26 Jul 2009) | 1 line
builtin -> built-in.
........
................
r74213 | georg.brandl | 2009-07-26 17:02:41 +0200 (So, 26 Jul 2009) | 9 lines
Merged revisions 74207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74207 | georg.brandl | 2009-07-26 16:19:57 +0200 (So, 26 Jul 2009) | 1 line
#6577: fix (hopefully) all links to builtin instead of module/class-specific objects.
........
................
r74214 | georg.brandl | 2009-07-26 17:03:49 +0200 (So, 26 Jul 2009) | 9 lines
Merged revisions 74205 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74205 | georg.brandl | 2009-07-26 15:36:39 +0200 (So, 26 Jul 2009) | 1 line
#6576: fix cross-refs in re docs.
........
................
r74247 | georg.brandl | 2009-07-29 09:27:08 +0200 (Mi, 29 Jul 2009) | 9 lines
Merged revisions 74239 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74239 | georg.brandl | 2009-07-28 18:55:32 +0000 (Di, 28 Jul 2009) | 1 line
Clarify quote_plus() usage.
........
................
r74254 | georg.brandl | 2009-07-29 18:14:16 +0200 (Mi, 29 Jul 2009) | 1 line
#6586: fix return/argument type doc for os.read() and os.write().
................
r74262 | alexandre.vassalotti | 2009-07-29 21:54:39 +0200 (Mi, 29 Jul 2009) | 57 lines
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
................
r74311 | georg.brandl | 2009-08-04 22:29:27 +0200 (Di, 04 Aug 2009) | 1 line
Slightly improve buffer-related error message.
................
r74334 | georg.brandl | 2009-08-06 19:51:03 +0200 (Do, 06 Aug 2009) | 1 line
#6648: mention surrogateescape handler where all standard handlers are listed.
................
r74368 | georg.brandl | 2009-08-13 09:56:35 +0200 (Do, 13 Aug 2009) | 21 lines
Merged revisions 74328,74332-74333,74365 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74328 | georg.brandl | 2009-08-06 17:06:25 +0200 (Do, 06 Aug 2009) | 1 line
Fix base keyword arg name for int() and long().
........
r74332 | georg.brandl | 2009-08-06 19:23:21 +0200 (Do, 06 Aug 2009) | 1 line
Fix punctuation and one copy-paste error.
........
r74333 | georg.brandl | 2009-08-06 19:43:55 +0200 (Do, 06 Aug 2009) | 1 line
#6658: fix two typos.
........
r74365 | georg.brandl | 2009-08-13 09:48:05 +0200 (Do, 13 Aug 2009) | 1 line
#6679: Remove mention that sub supports no flags.
........
................
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Thu, 13 Aug 2009 08:26:44 +0000 |
| parents | 87fbbf22adf3 |
| children | f197407bdba2 79718ee03986 |
| rev | line source |
|---|---|
| 35742 | 1 #include "Python.h" |
| 2 #include "code.h" | |
| 3 #include "structmember.h" | |
| 4 | |
| 5 #define NAME_CHARS \ | |
| 6 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" | |
| 7 | |
| 8 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ | |
| 9 | |
| 10 static int | |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43672
diff
changeset
|
11 all_name_chars(Py_UNICODE *s) |
| 35742 | 12 { |
| 13 static char ok_name_char[256]; | |
| 14 static unsigned char *name_chars = (unsigned char *)NAME_CHARS; | |
| 15 | |
| 16 if (ok_name_char[*name_chars] == 0) { | |
| 17 unsigned char *p; | |
| 18 for (p = name_chars; *p; p++) | |
| 19 ok_name_char[*p] = 1; | |
| 20 } | |
| 21 while (*s) { | |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43672
diff
changeset
|
22 if (*s >= 128) |
|
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43672
diff
changeset
|
23 return 0; |
| 35742 | 24 if (ok_name_char[*s++] == 0) |
| 25 return 0; | |
| 26 } | |
| 27 return 1; | |
| 28 } | |
| 29 | |
| 30 static void | |
| 31 intern_strings(PyObject *tuple) | |
| 32 { | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
33 Py_ssize_t i; |
| 35742 | 34 |
| 35 for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { | |
| 36 PyObject *v = PyTuple_GET_ITEM(tuple, i); | |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41962
diff
changeset
|
37 if (v == NULL || !PyUnicode_CheckExact(v)) { |
| 35742 | 38 Py_FatalError("non-string found in code slot"); |
| 39 } | |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41962
diff
changeset
|
40 PyUnicode_InternInPlace(&PyTuple_GET_ITEM(tuple, i)); |
| 35742 | 41 } |
| 42 } | |
| 43 | |
| 44 | |
| 45 PyCodeObject * | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
46 PyCode_New(int argcount, int kwonlyargcount, |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
47 int nlocals, int stacksize, int flags, |
| 35742 | 48 PyObject *code, PyObject *consts, PyObject *names, |
| 49 PyObject *varnames, PyObject *freevars, PyObject *cellvars, | |
| 50 PyObject *filename, PyObject *name, int firstlineno, | |
| 51 PyObject *lnotab) | |
| 52 { | |
| 53 PyCodeObject *co; | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
54 Py_ssize_t i; |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42802
diff
changeset
|
55 |
| 35742 | 56 /* Check argument types */ |
| 57 if (argcount < 0 || nlocals < 0 || | |
| 58 code == NULL || | |
| 59 consts == NULL || !PyTuple_Check(consts) || | |
| 60 names == NULL || !PyTuple_Check(names) || | |
| 61 varnames == NULL || !PyTuple_Check(varnames) || | |
| 62 freevars == NULL || !PyTuple_Check(freevars) || | |
| 63 cellvars == NULL || !PyTuple_Check(cellvars) || | |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42802
diff
changeset
|
64 name == NULL || !PyUnicode_Check(name) || |
|
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42802
diff
changeset
|
65 filename == NULL || !PyUnicode_Check(filename) || |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44965
diff
changeset
|
66 lnotab == NULL || !PyBytes_Check(lnotab) || |
| 35742 | 67 !PyObject_CheckReadBuffer(code)) { |
| 68 PyErr_BadInternalCall(); | |
| 69 return NULL; | |
| 70 } | |
| 71 intern_strings(names); | |
| 72 intern_strings(varnames); | |
| 73 intern_strings(freevars); | |
| 74 intern_strings(cellvars); | |
| 75 /* Intern selected string constants */ | |
| 76 for (i = PyTuple_Size(consts); --i >= 0; ) { | |
| 77 PyObject *v = PyTuple_GetItem(consts, i); | |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43672
diff
changeset
|
78 if (!PyUnicode_Check(v)) |
| 35742 | 79 continue; |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43672
diff
changeset
|
80 if (!all_name_chars(PyUnicode_AS_UNICODE(v))) |
| 35742 | 81 continue; |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43672
diff
changeset
|
82 PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i)); |
| 35742 | 83 } |
| 84 co = PyObject_NEW(PyCodeObject, &PyCode_Type); | |
| 85 if (co != NULL) { | |
| 86 co->co_argcount = argcount; | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
87 co->co_kwonlyargcount = kwonlyargcount; |
| 35742 | 88 co->co_nlocals = nlocals; |
| 89 co->co_stacksize = stacksize; | |
| 90 co->co_flags = flags; | |
| 91 Py_INCREF(code); | |
| 92 co->co_code = code; | |
| 93 Py_INCREF(consts); | |
| 94 co->co_consts = consts; | |
| 95 Py_INCREF(names); | |
| 96 co->co_names = names; | |
| 97 Py_INCREF(varnames); | |
| 98 co->co_varnames = varnames; | |
| 99 Py_INCREF(freevars); | |
| 100 co->co_freevars = freevars; | |
| 101 Py_INCREF(cellvars); | |
| 102 co->co_cellvars = cellvars; | |
| 103 Py_INCREF(filename); | |
| 104 co->co_filename = filename; | |
| 105 Py_INCREF(name); | |
| 106 co->co_name = name; | |
| 107 co->co_firstlineno = firstlineno; | |
| 108 Py_INCREF(lnotab); | |
| 109 co->co_lnotab = lnotab; | |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
110 co->co_zombieframe = NULL; |
| 35742 | 111 } |
| 112 return co; | |
| 113 } | |
| 114 | |
| 115 | |
| 116 #define OFF(x) offsetof(PyCodeObject, x) | |
| 117 | |
| 118 static PyMemberDef code_memberlist[] = { | |
| 119 {"co_argcount", T_INT, OFF(co_argcount), READONLY}, | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
120 {"co_kwonlyargcount", T_INT, OFF(co_kwonlyargcount), READONLY}, |
| 35742 | 121 {"co_nlocals", T_INT, OFF(co_nlocals), READONLY}, |
| 122 {"co_stacksize",T_INT, OFF(co_stacksize), READONLY}, | |
| 123 {"co_flags", T_INT, OFF(co_flags), READONLY}, | |
| 124 {"co_code", T_OBJECT, OFF(co_code), READONLY}, | |
| 125 {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, | |
| 126 {"co_names", T_OBJECT, OFF(co_names), READONLY}, | |
| 127 {"co_varnames", T_OBJECT, OFF(co_varnames), READONLY}, | |
| 128 {"co_freevars", T_OBJECT, OFF(co_freevars), READONLY}, | |
| 129 {"co_cellvars", T_OBJECT, OFF(co_cellvars), READONLY}, | |
| 130 {"co_filename", T_OBJECT, OFF(co_filename), READONLY}, | |
| 131 {"co_name", T_OBJECT, OFF(co_name), READONLY}, | |
| 132 {"co_firstlineno", T_INT, OFF(co_firstlineno), READONLY}, | |
| 133 {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY}, | |
| 134 {NULL} /* Sentinel */ | |
| 135 }; | |
| 136 | |
| 137 /* Helper for code_new: return a shallow copy of a tuple that is | |
| 138 guaranteed to contain exact strings, by converting string subclasses | |
| 139 to exact strings and complaining if a non-string is found. */ | |
| 140 static PyObject* | |
| 141 validate_and_copy_tuple(PyObject *tup) | |
| 142 { | |
| 143 PyObject *newtuple; | |
| 144 PyObject *item; | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
145 Py_ssize_t i, len; |
| 35742 | 146 |
| 147 len = PyTuple_GET_SIZE(tup); | |
| 148 newtuple = PyTuple_New(len); | |
| 149 if (newtuple == NULL) | |
| 150 return NULL; | |
| 151 | |
| 152 for (i = 0; i < len; i++) { | |
| 153 item = PyTuple_GET_ITEM(tup, i); | |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41962
diff
changeset
|
154 if (PyUnicode_CheckExact(item)) { |
| 35742 | 155 Py_INCREF(item); |
| 156 } | |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41962
diff
changeset
|
157 else if (!PyUnicode_Check(item)) { |
| 35742 | 158 PyErr_Format( |
| 159 PyExc_TypeError, | |
| 160 "name tuples must contain only " | |
| 161 "strings, not '%.500s'", | |
| 162 item->ob_type->tp_name); | |
| 163 Py_DECREF(newtuple); | |
| 164 return NULL; | |
| 165 } | |
| 166 else { | |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41962
diff
changeset
|
167 item = PyUnicode_FromUnicode( |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41962
diff
changeset
|
168 PyUnicode_AS_UNICODE(item), |
|
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41962
diff
changeset
|
169 PyUnicode_GET_SIZE(item)); |
| 35742 | 170 if (item == NULL) { |
| 171 Py_DECREF(newtuple); | |
| 172 return NULL; | |
| 173 } | |
| 174 } | |
| 175 PyTuple_SET_ITEM(newtuple, i, item); | |
| 176 } | |
| 177 | |
| 178 return newtuple; | |
| 179 } | |
| 180 | |
| 181 PyDoc_STRVAR(code_doc, | |
|
55580
7b495c8f2a24
Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51271
diff
changeset
|
182 "code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring,\n\ |
|
44965
b70485011214
#1939: update code object docstring.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
183 constants, names, varnames, filename, name, firstlineno,\n\ |
|
b70485011214
#1939: update code object docstring.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
184 lnotab[, freevars[, cellvars]])\n\ |
| 35742 | 185 \n\ |
| 186 Create a code object. Not for the faint of heart."); | |
| 187 | |
| 188 static PyObject * | |
| 189 code_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |
| 190 { | |
| 191 int argcount; | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
192 int kwonlyargcount; |
| 35742 | 193 int nlocals; |
| 194 int stacksize; | |
| 195 int flags; | |
| 196 PyObject *co = NULL; | |
| 197 PyObject *code; | |
| 198 PyObject *consts; | |
| 199 PyObject *names, *ournames = NULL; | |
| 200 PyObject *varnames, *ourvarnames = NULL; | |
| 201 PyObject *freevars = NULL, *ourfreevars = NULL; | |
| 202 PyObject *cellvars = NULL, *ourcellvars = NULL; | |
| 203 PyObject *filename; | |
| 204 PyObject *name; | |
| 205 int firstlineno; | |
| 206 PyObject *lnotab; | |
| 207 | |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43672
diff
changeset
|
208 if (!PyArg_ParseTuple(args, "iiiiiSO!O!O!UUiS|O!O!:code", |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
209 &argcount, &kwonlyargcount, |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
210 &nlocals, &stacksize, &flags, |
| 35742 | 211 &code, |
| 212 &PyTuple_Type, &consts, | |
| 213 &PyTuple_Type, &names, | |
| 214 &PyTuple_Type, &varnames, | |
| 215 &filename, &name, | |
| 216 &firstlineno, &lnotab, | |
| 217 &PyTuple_Type, &freevars, | |
| 218 &PyTuple_Type, &cellvars)) | |
| 219 return NULL; | |
| 220 | |
| 221 if (argcount < 0) { | |
| 222 PyErr_SetString( | |
| 223 PyExc_ValueError, | |
| 224 "code: argcount must not be negative"); | |
| 225 goto cleanup; | |
| 226 } | |
| 227 | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
228 if (kwonlyargcount < 0) { |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
229 PyErr_SetString( |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
230 PyExc_ValueError, |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
231 "code: kwonlyargcount must not be negative"); |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
232 goto cleanup; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
233 } |
| 35742 | 234 if (nlocals < 0) { |
| 235 PyErr_SetString( | |
| 236 PyExc_ValueError, | |
| 237 "code: nlocals must not be negative"); | |
| 238 goto cleanup; | |
| 239 } | |
| 240 | |
| 241 ournames = validate_and_copy_tuple(names); | |
| 242 if (ournames == NULL) | |
| 243 goto cleanup; | |
| 244 ourvarnames = validate_and_copy_tuple(varnames); | |
| 245 if (ourvarnames == NULL) | |
| 246 goto cleanup; | |
| 247 if (freevars) | |
| 248 ourfreevars = validate_and_copy_tuple(freevars); | |
| 249 else | |
| 250 ourfreevars = PyTuple_New(0); | |
| 251 if (ourfreevars == NULL) | |
| 252 goto cleanup; | |
| 253 if (cellvars) | |
| 254 ourcellvars = validate_and_copy_tuple(cellvars); | |
| 255 else | |
| 256 ourcellvars = PyTuple_New(0); | |
| 257 if (ourcellvars == NULL) | |
| 258 goto cleanup; | |
| 259 | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
260 co = (PyObject *)PyCode_New(argcount, kwonlyargcount, |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
261 nlocals, stacksize, flags, |
| 35742 | 262 code, consts, ournames, ourvarnames, |
| 263 ourfreevars, ourcellvars, filename, | |
| 264 name, firstlineno, lnotab); | |
| 265 cleanup: | |
| 266 Py_XDECREF(ournames); | |
| 267 Py_XDECREF(ourvarnames); | |
| 268 Py_XDECREF(ourfreevars); | |
| 269 Py_XDECREF(ourcellvars); | |
| 270 return co; | |
| 271 } | |
| 272 | |
| 273 static void | |
| 274 code_dealloc(PyCodeObject *co) | |
| 275 { | |
| 276 Py_XDECREF(co->co_code); | |
| 277 Py_XDECREF(co->co_consts); | |
| 278 Py_XDECREF(co->co_names); | |
| 279 Py_XDECREF(co->co_varnames); | |
| 280 Py_XDECREF(co->co_freevars); | |
| 281 Py_XDECREF(co->co_cellvars); | |
| 282 Py_XDECREF(co->co_filename); | |
| 283 Py_XDECREF(co->co_name); | |
| 284 Py_XDECREF(co->co_lnotab); | |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
285 if (co->co_zombieframe != NULL) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
286 PyObject_GC_Del(co->co_zombieframe); |
| 35742 | 287 PyObject_DEL(co); |
| 288 } | |
| 289 | |
| 290 static PyObject * | |
| 291 code_repr(PyCodeObject *co) | |
| 292 { | |
| 293 int lineno = -1; | |
| 294 char *filename = "???"; | |
| 295 | |
| 296 if (co->co_firstlineno != 0) | |
| 297 lineno = co->co_firstlineno; | |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42802
diff
changeset
|
298 if (co->co_filename && PyUnicode_Check(co->co_filename)) |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
47301
diff
changeset
|
299 filename = _PyUnicode_AsString(co->co_filename); |
|
41962
11930dcf9d4f
Use PyUnicode_FromFormat() directly.
Walter Dörwald <walter@livinglogic.de>
parents:
41769
diff
changeset
|
300 return PyUnicode_FromFormat( |
|
42802
01ee6311ba46
Ensure that code object names (co_name) are unicode.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
301 "<code object %.100U at %p, file \"%.300s\", line %d>", |
|
01ee6311ba46
Ensure that code object names (co_name) are unicode.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
302 co->co_name, co, filename, lineno); |
| 35742 | 303 } |
| 304 | |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
305 static PyObject * |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
306 code_richcompare(PyObject *self, PyObject *other, int op) |
| 35742 | 307 { |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
308 PyCodeObject *co, *cp; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
309 int eq; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
310 PyObject *res; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
311 |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
312 if ((op != Py_EQ && op != Py_NE) || |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
313 !PyCode_Check(self) || |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
314 !PyCode_Check(other)) { |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
315 Py_INCREF(Py_NotImplemented); |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
316 return Py_NotImplemented; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
317 } |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
318 |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
319 co = (PyCodeObject *)self; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
320 cp = (PyCodeObject *)other; |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
321 |
|
39658
a5048c8d8f33
Fix a bunch of compiler warnings. In at least one case these were serious bugs!
Guido van Rossum <guido@python.org>
parents:
39650
diff
changeset
|
322 eq = PyObject_RichCompareBool(co->co_name, cp->co_name, Py_EQ); |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
323 if (eq <= 0) goto unequal; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
324 eq = co->co_argcount == cp->co_argcount; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
325 if (!eq) goto unequal; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
326 eq = co->co_kwonlyargcount == cp->co_kwonlyargcount; |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
327 if (!eq) goto unequal; |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
328 eq = co->co_nlocals == cp->co_nlocals; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
329 if (!eq) goto unequal; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
330 eq = co->co_flags == cp->co_flags; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
331 if (!eq) goto unequal; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
332 eq = co->co_firstlineno == cp->co_firstlineno; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
333 if (!eq) goto unequal; |
|
39658
a5048c8d8f33
Fix a bunch of compiler warnings. In at least one case these were serious bugs!
Guido van Rossum <guido@python.org>
parents:
39650
diff
changeset
|
334 eq = PyObject_RichCompareBool(co->co_code, cp->co_code, Py_EQ); |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
335 if (eq <= 0) goto unequal; |
|
39658
a5048c8d8f33
Fix a bunch of compiler warnings. In at least one case these were serious bugs!
Guido van Rossum <guido@python.org>
parents:
39650
diff
changeset
|
336 eq = PyObject_RichCompareBool(co->co_consts, cp->co_consts, Py_EQ); |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
337 if (eq <= 0) goto unequal; |
|
39658
a5048c8d8f33
Fix a bunch of compiler warnings. In at least one case these were serious bugs!
Guido van Rossum <guido@python.org>
parents:
39650
diff
changeset
|
338 eq = PyObject_RichCompareBool(co->co_names, cp->co_names, Py_EQ); |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
339 if (eq <= 0) goto unequal; |
|
39658
a5048c8d8f33
Fix a bunch of compiler warnings. In at least one case these were serious bugs!
Guido van Rossum <guido@python.org>
parents:
39650
diff
changeset
|
340 eq = PyObject_RichCompareBool(co->co_varnames, cp->co_varnames, Py_EQ); |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
341 if (eq <= 0) goto unequal; |
|
39658
a5048c8d8f33
Fix a bunch of compiler warnings. In at least one case these were serious bugs!
Guido van Rossum <guido@python.org>
parents:
39650
diff
changeset
|
342 eq = PyObject_RichCompareBool(co->co_freevars, cp->co_freevars, Py_EQ); |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
343 if (eq <= 0) goto unequal; |
|
39658
a5048c8d8f33
Fix a bunch of compiler warnings. In at least one case these were serious bugs!
Guido van Rossum <guido@python.org>
parents:
39650
diff
changeset
|
344 eq = PyObject_RichCompareBool(co->co_cellvars, cp->co_cellvars, Py_EQ); |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
345 if (eq <= 0) goto unequal; |
| 35742 | 346 |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
347 if (op == Py_EQ) |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
348 res = Py_True; |
| 35742 | 349 else |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
350 res = Py_False; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
351 goto done; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
352 |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
353 unequal: |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
354 if (eq < 0) |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
355 return NULL; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
356 if (op == Py_NE) |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
357 res = Py_True; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
358 else |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
359 res = Py_False; |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
360 |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
361 done: |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
362 Py_INCREF(res); |
|
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
363 return res; |
| 35742 | 364 } |
| 365 | |
| 366 static long | |
| 367 code_hash(PyCodeObject *co) | |
| 368 { | |
| 369 long h, h0, h1, h2, h3, h4, h5, h6; | |
| 370 h0 = PyObject_Hash(co->co_name); | |
| 371 if (h0 == -1) return -1; | |
| 372 h1 = PyObject_Hash(co->co_code); | |
| 373 if (h1 == -1) return -1; | |
| 374 h2 = PyObject_Hash(co->co_consts); | |
| 375 if (h2 == -1) return -1; | |
| 376 h3 = PyObject_Hash(co->co_names); | |
| 377 if (h3 == -1) return -1; | |
| 378 h4 = PyObject_Hash(co->co_varnames); | |
| 379 if (h4 == -1) return -1; | |
| 380 h5 = PyObject_Hash(co->co_freevars); | |
| 381 if (h5 == -1) return -1; | |
| 382 h6 = PyObject_Hash(co->co_cellvars); | |
| 383 if (h6 == -1) return -1; | |
| 384 h = h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5 ^ h6 ^ | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
385 co->co_argcount ^ co->co_kwonlyargcount ^ |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39658
diff
changeset
|
386 co->co_nlocals ^ co->co_flags; |
| 35742 | 387 if (h == -1) h = -2; |
| 388 return h; | |
| 389 } | |
| 390 | |
| 391 /* XXX code objects need to participate in GC? */ | |
| 392 | |
| 393 PyTypeObject PyCode_Type = { | |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42013
diff
changeset
|
394 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 35742 | 395 "code", |
| 396 sizeof(PyCodeObject), | |
| 397 0, | |
| 398 (destructor)code_dealloc, /* tp_dealloc */ | |
| 399 0, /* tp_print */ | |
| 400 0, /* tp_getattr */ | |
| 401 0, /* tp_setattr */ | |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48660
diff
changeset
|
402 0, /* tp_reserved */ |
| 35742 | 403 (reprfunc)code_repr, /* tp_repr */ |
| 404 0, /* tp_as_number */ | |
| 405 0, /* tp_as_sequence */ | |
| 406 0, /* tp_as_mapping */ | |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
407 (hashfunc)code_hash, /* tp_hash */ |
| 35742 | 408 0, /* tp_call */ |
| 409 0, /* tp_str */ | |
| 410 PyObject_GenericGetAttr, /* tp_getattro */ | |
| 411 0, /* tp_setattro */ | |
| 412 0, /* tp_as_buffer */ | |
| 413 Py_TPFLAGS_DEFAULT, /* tp_flags */ | |
| 414 code_doc, /* tp_doc */ | |
| 415 0, /* tp_traverse */ | |
| 416 0, /* tp_clear */ | |
|
39650
69f61f90c4fc
Implement == and != comparisons for code objects by value.
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
417 code_richcompare, /* tp_richcompare */ |
| 35742 | 418 0, /* tp_weaklistoffset */ |
| 419 0, /* tp_iter */ | |
| 420 0, /* tp_iternext */ | |
| 421 0, /* tp_methods */ | |
| 422 code_memberlist, /* tp_members */ | |
| 423 0, /* tp_getset */ | |
| 424 0, /* tp_base */ | |
| 425 0, /* tp_dict */ | |
| 426 0, /* tp_descr_get */ | |
| 427 0, /* tp_descr_set */ | |
| 428 0, /* tp_dictoffset */ | |
| 429 0, /* tp_init */ | |
| 430 0, /* tp_alloc */ | |
| 431 code_new, /* tp_new */ | |
| 432 }; | |
| 433 | |
| 434 /* All about c_lnotab. | |
| 435 | |
| 436 c_lnotab is an array of unsigned bytes disguised as a Python string. In -O | |
| 437 mode, SET_LINENO opcodes aren't generated, and bytecode offsets are mapped | |
| 438 to source code line #s (when needed for tracebacks) via c_lnotab instead. | |
| 439 The array is conceptually a list of | |
| 440 (bytecode offset increment, line number increment) | |
| 441 pairs. The details are important and delicate, best illustrated by example: | |
| 442 | |
| 443 byte code offset source code line number | |
| 444 0 1 | |
| 445 6 2 | |
| 446 50 7 | |
| 447 350 307 | |
| 448 361 308 | |
| 449 | |
| 450 The first trick is that these numbers aren't stored, only the increments | |
| 451 from one row to the next (this doesn't really work, but it's a start): | |
| 452 | |
| 453 0, 1, 6, 1, 44, 5, 300, 300, 11, 1 | |
| 454 | |
| 455 The second trick is that an unsigned byte can't hold negative values, or | |
| 456 values larger than 255, so (a) there's a deep assumption that byte code | |
| 457 offsets and their corresponding line #s both increase monotonically, and (b) | |
| 458 if at least one column jumps by more than 255 from one row to the next, more | |
| 459 than one pair is written to the table. In case #b, there's no way to know | |
| 460 from looking at the table later how many were written. That's the delicate | |
| 461 part. A user of c_lnotab desiring to find the source line number | |
| 462 corresponding to a bytecode address A should do something like this | |
| 463 | |
| 464 lineno = addr = 0 | |
| 465 for addr_incr, line_incr in c_lnotab: | |
| 466 addr += addr_incr | |
| 467 if addr > A: | |
| 468 return lineno | |
| 469 lineno += line_incr | |
| 470 | |
| 471 In order for this to work, when the addr field increments by more than 255, | |
| 472 the line # increment in each pair generated must be 0 until the remaining addr | |
| 473 increment is < 256. So, in the example above, com_set_lineno should not (as | |
| 474 was actually done until 2.2) expand 300, 300 to 255, 255, 45, 45, but to | |
| 475 255, 0, 45, 255, 0, 45. | |
| 476 */ | |
| 477 | |
| 478 int | |
| 479 PyCode_Addr2Line(PyCodeObject *co, int addrq) | |
| 480 { | |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44965
diff
changeset
|
481 int size = PyBytes_Size(co->co_lnotab) / 2; |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44965
diff
changeset
|
482 unsigned char *p = (unsigned char*)PyBytes_AsString(co->co_lnotab); |
| 35742 | 483 int line = co->co_firstlineno; |
| 484 int addr = 0; | |
| 485 while (--size >= 0) { | |
| 486 addr += *p++; | |
| 487 if (addr > addrq) | |
| 488 break; | |
| 489 line += *p++; | |
| 490 } | |
| 491 return line; | |
| 492 } | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
493 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
494 /* |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
495 Check whether the current instruction is at the start of a line. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
496 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
497 */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
498 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
499 /* The theory of SET_LINENO-less tracing. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
500 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
501 In a nutshell, we use the co_lnotab field of the code object |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
502 to tell when execution has moved onto a different line. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
503 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
504 As mentioned above, the basic idea is so set things up so |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
505 that |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
506 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
507 *instr_lb <= frame->f_lasti < *instr_ub |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
508 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
509 is true so long as execution does not change lines. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
510 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
511 This is all fairly simple. Digging the information out of |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
512 co_lnotab takes some work, but is conceptually clear. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
513 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
514 Somewhat harder to explain is why we don't *always* call the |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
515 line trace function when the above test fails. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
516 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
517 Consider this code: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
518 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
519 1: def f(a): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
520 2: if a: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
521 3: print 1 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
522 4: else: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
523 5: print 2 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
524 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
525 which compiles to this: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
526 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
527 2 0 LOAD_FAST 0 (a) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
528 3 JUMP_IF_FALSE 9 (to 15) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
529 6 POP_TOP |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
530 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
531 3 7 LOAD_CONST 1 (1) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
532 10 PRINT_ITEM |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
533 11 PRINT_NEWLINE |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
534 12 JUMP_FORWARD 6 (to 21) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
535 >> 15 POP_TOP |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
536 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
537 5 16 LOAD_CONST 2 (2) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
538 19 PRINT_ITEM |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
539 20 PRINT_NEWLINE |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
540 >> 21 LOAD_CONST 0 (None) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
541 24 RETURN_VALUE |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
542 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
543 If 'a' is false, execution will jump to instruction at offset |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
544 15 and the co_lnotab will claim that execution has moved to |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
545 line 3. This is at best misleading. In this case we could |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
546 associate the POP_TOP with line 4, but that doesn't make |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
547 sense in all cases (I think). |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
548 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
549 What we do is only call the line trace function if the co_lnotab |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
550 indicates we have jumped to the *start* of a line, i.e. if the |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
551 current instruction offset matches the offset given for the |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
552 start of a line by the co_lnotab. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
553 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
554 This also takes care of the situation where 'a' is true. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
555 Execution will jump from instruction offset 12 to offset 21. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
556 Then the co_lnotab would imply that execution has moved to line |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
557 5, which is again misleading. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
558 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
559 Why do we set f_lineno when tracing? Well, consider the code |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
560 above when 'a' is true. If stepping through this with 'n' in |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
561 pdb, you would stop at line 1 with a "call" type event, then |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
562 line events on lines 2 and 3, then a "return" type event -- but |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
563 you would be shown line 5 during this event. This is a change |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
564 from the behaviour in 2.2 and before, and I've found it |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
565 confusing in practice. By setting and using f_lineno when |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
566 tracing, one can report a line number different from that |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
567 suggested by f_lasti on this one occasion where it's desirable. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
568 */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
569 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
570 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
571 int |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
572 PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
573 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
574 int size, addr, line; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
575 unsigned char* p; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
576 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44965
diff
changeset
|
577 p = (unsigned char*)PyBytes_AS_STRING(co->co_lnotab); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44965
diff
changeset
|
578 size = PyBytes_GET_SIZE(co->co_lnotab) / 2; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
579 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
580 addr = 0; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
581 line = co->co_firstlineno; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
582 assert(line > 0); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
583 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
584 /* possible optimization: if f->f_lasti == instr_ub |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
585 (likely to be a common case) then we already know |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
586 instr_lb -- if we stored the matching value of p |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
587 somwhere we could skip the first while loop. */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
588 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
589 /* see comments in compile.c for the description of |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
590 co_lnotab. A point to remember: increments to p |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
591 should come in pairs -- although we don't care about |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
592 the line increments here, treating them as byte |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
593 increments gets confusing, to say the least. */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
594 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
595 bounds->ap_lower = 0; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
596 while (size > 0) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
597 if (addr + *p > lasti) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
598 break; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
599 addr += *p++; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
600 if (*p) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
601 bounds->ap_lower = addr; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
602 line += *p++; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
603 --size; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
604 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
605 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
606 /* If lasti and addr don't match exactly, we don't want to |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
607 change the lineno slot on the frame or execute a trace |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
608 function. Return -1 instead. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
609 */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
610 if (addr != lasti) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
611 line = -1; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
612 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
613 if (size > 0) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
614 while (--size >= 0) { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
615 addr += *p++; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
616 if (*p++) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
617 break; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
618 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
619 bounds->ap_upper = addr; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
620 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
621 else { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
622 bounds->ap_upper = INT_MAX; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
623 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
624 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
625 return line; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
626 } |
