Mercurial > cpython-lru_cache-weakref
annotate Objects/codeobject.c @ 57303:4aa4c19dfaed legacy-trunk
#1757126: fix typo with the cyrillic_asian alias
| author | Philip Jenvey <pjenvey@underboss.org> |
|---|---|
| date | Tue, 17 Nov 2009 02:42:26 +0000 |
| parents | dddf424bd669 |
| children | 22f589a8e3ab |
| 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 | |
| 11 all_name_chars(unsigned char *s) | |
| 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) { | |
| 22 if (ok_name_char[*s++] == 0) | |
| 23 return 0; | |
| 24 } | |
| 25 return 1; | |
| 26 } | |
| 27 | |
| 28 static void | |
| 29 intern_strings(PyObject *tuple) | |
| 30 { | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
31 Py_ssize_t i; |
| 35742 | 32 |
| 33 for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { | |
| 34 PyObject *v = PyTuple_GET_ITEM(tuple, i); | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
35 if (v == NULL || !PyString_CheckExact(v)) { |
| 35742 | 36 Py_FatalError("non-string found in code slot"); |
| 37 } | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
38 PyString_InternInPlace(&PyTuple_GET_ITEM(tuple, i)); |
| 35742 | 39 } |
| 40 } | |
| 41 | |
| 42 | |
| 43 PyCodeObject * | |
| 44 PyCode_New(int argcount, int nlocals, int stacksize, int flags, | |
| 45 PyObject *code, PyObject *consts, PyObject *names, | |
| 46 PyObject *varnames, PyObject *freevars, PyObject *cellvars, | |
| 47 PyObject *filename, PyObject *name, int firstlineno, | |
| 48 PyObject *lnotab) | |
| 49 { | |
| 50 PyCodeObject *co; | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
51 Py_ssize_t i; |
| 35742 | 52 /* Check argument types */ |
| 53 if (argcount < 0 || nlocals < 0 || | |
| 54 code == NULL || | |
| 55 consts == NULL || !PyTuple_Check(consts) || | |
| 56 names == NULL || !PyTuple_Check(names) || | |
| 57 varnames == NULL || !PyTuple_Check(varnames) || | |
| 58 freevars == NULL || !PyTuple_Check(freevars) || | |
| 59 cellvars == NULL || !PyTuple_Check(cellvars) || | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
60 name == NULL || !PyString_Check(name) || |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
61 filename == NULL || !PyString_Check(filename) || |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
62 lnotab == NULL || !PyString_Check(lnotab) || |
| 35742 | 63 !PyObject_CheckReadBuffer(code)) { |
| 64 PyErr_BadInternalCall(); | |
| 65 return NULL; | |
| 66 } | |
| 67 intern_strings(names); | |
| 68 intern_strings(varnames); | |
| 69 intern_strings(freevars); | |
| 70 intern_strings(cellvars); | |
| 71 /* Intern selected string constants */ | |
| 72 for (i = PyTuple_Size(consts); --i >= 0; ) { | |
| 73 PyObject *v = PyTuple_GetItem(consts, i); | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
74 if (!PyString_Check(v)) |
| 35742 | 75 continue; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
76 if (!all_name_chars((unsigned char *)PyString_AS_STRING(v))) |
| 35742 | 77 continue; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
78 PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i)); |
| 35742 | 79 } |
| 80 co = PyObject_NEW(PyCodeObject, &PyCode_Type); | |
| 81 if (co != NULL) { | |
| 82 co->co_argcount = argcount; | |
| 83 co->co_nlocals = nlocals; | |
| 84 co->co_stacksize = stacksize; | |
| 85 co->co_flags = flags; | |
| 86 Py_INCREF(code); | |
| 87 co->co_code = code; | |
| 88 Py_INCREF(consts); | |
| 89 co->co_consts = consts; | |
| 90 Py_INCREF(names); | |
| 91 co->co_names = names; | |
| 92 Py_INCREF(varnames); | |
| 93 co->co_varnames = varnames; | |
| 94 Py_INCREF(freevars); | |
| 95 co->co_freevars = freevars; | |
| 96 Py_INCREF(cellvars); | |
| 97 co->co_cellvars = cellvars; | |
| 98 Py_INCREF(filename); | |
| 99 co->co_filename = filename; | |
| 100 Py_INCREF(name); | |
| 101 co->co_name = name; | |
| 102 co->co_firstlineno = firstlineno; | |
| 103 Py_INCREF(lnotab); | |
| 104 co->co_lnotab = lnotab; | |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37838
diff
changeset
|
105 co->co_zombieframe = NULL; |
| 35742 | 106 } |
| 107 return co; | |
| 108 } | |
| 109 | |
| 53930 | 110 PyCodeObject * |
| 111 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) | |
| 112 { | |
| 113 static PyObject *emptystring = NULL; | |
| 114 static PyObject *nulltuple = NULL; | |
| 115 PyObject *filename_ob = NULL; | |
| 116 PyObject *funcname_ob = NULL; | |
| 117 PyCodeObject *result = NULL; | |
| 118 if (emptystring == NULL) { | |
| 119 emptystring = PyString_FromString(""); | |
| 120 if (emptystring == NULL) | |
| 121 goto failed; | |
| 122 } | |
| 123 if (nulltuple == NULL) { | |
| 124 nulltuple = PyTuple_New(0); | |
| 125 if (nulltuple == NULL) | |
| 126 goto failed; | |
| 127 } | |
| 128 funcname_ob = PyString_FromString(funcname); | |
| 129 if (funcname_ob == NULL) | |
| 130 goto failed; | |
| 131 filename_ob = PyString_FromString(filename); | |
| 132 if (filename_ob == NULL) | |
| 133 goto failed; | |
| 134 | |
| 135 result = PyCode_New(0, /* argcount */ | |
| 136 0, /* nlocals */ | |
| 137 0, /* stacksize */ | |
| 138 0, /* flags */ | |
| 139 emptystring, /* code */ | |
| 140 nulltuple, /* consts */ | |
| 141 nulltuple, /* names */ | |
| 142 nulltuple, /* varnames */ | |
| 143 nulltuple, /* freevars */ | |
| 144 nulltuple, /* cellvars */ | |
| 145 filename_ob, /* filename */ | |
| 146 funcname_ob, /* name */ | |
| 147 firstlineno, /* firstlineno */ | |
| 148 emptystring /* lnotab */ | |
| 149 ); | |
| 150 | |
| 151 failed: | |
| 152 Py_XDECREF(funcname_ob); | |
| 153 Py_XDECREF(filename_ob); | |
| 154 return result; | |
| 155 } | |
| 35742 | 156 |
| 157 #define OFF(x) offsetof(PyCodeObject, x) | |
| 158 | |
| 159 static PyMemberDef code_memberlist[] = { | |
| 160 {"co_argcount", T_INT, OFF(co_argcount), READONLY}, | |
| 161 {"co_nlocals", T_INT, OFF(co_nlocals), READONLY}, | |
| 162 {"co_stacksize",T_INT, OFF(co_stacksize), READONLY}, | |
| 163 {"co_flags", T_INT, OFF(co_flags), READONLY}, | |
| 164 {"co_code", T_OBJECT, OFF(co_code), READONLY}, | |
| 165 {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, | |
| 166 {"co_names", T_OBJECT, OFF(co_names), READONLY}, | |
| 167 {"co_varnames", T_OBJECT, OFF(co_varnames), READONLY}, | |
| 168 {"co_freevars", T_OBJECT, OFF(co_freevars), READONLY}, | |
| 169 {"co_cellvars", T_OBJECT, OFF(co_cellvars), READONLY}, | |
| 170 {"co_filename", T_OBJECT, OFF(co_filename), READONLY}, | |
| 171 {"co_name", T_OBJECT, OFF(co_name), READONLY}, | |
| 172 {"co_firstlineno", T_INT, OFF(co_firstlineno), READONLY}, | |
| 173 {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY}, | |
| 174 {NULL} /* Sentinel */ | |
| 175 }; | |
| 176 | |
| 177 /* Helper for code_new: return a shallow copy of a tuple that is | |
| 178 guaranteed to contain exact strings, by converting string subclasses | |
| 179 to exact strings and complaining if a non-string is found. */ | |
| 180 static PyObject* | |
| 181 validate_and_copy_tuple(PyObject *tup) | |
| 182 { | |
| 183 PyObject *newtuple; | |
| 184 PyObject *item; | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
185 Py_ssize_t i, len; |
| 35742 | 186 |
| 187 len = PyTuple_GET_SIZE(tup); | |
| 188 newtuple = PyTuple_New(len); | |
| 189 if (newtuple == NULL) | |
| 190 return NULL; | |
| 191 | |
| 192 for (i = 0; i < len; i++) { | |
| 193 item = PyTuple_GET_ITEM(tup, i); | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
194 if (PyString_CheckExact(item)) { |
| 35742 | 195 Py_INCREF(item); |
| 196 } | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
197 else if (!PyString_Check(item)) { |
| 35742 | 198 PyErr_Format( |
| 199 PyExc_TypeError, | |
| 200 "name tuples must contain only " | |
| 201 "strings, not '%.500s'", | |
| 202 item->ob_type->tp_name); | |
| 203 Py_DECREF(newtuple); | |
| 204 return NULL; | |
| 205 } | |
| 206 else { | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
207 item = PyString_FromStringAndSize( |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
208 PyString_AS_STRING(item), |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
209 PyString_GET_SIZE(item)); |
| 35742 | 210 if (item == NULL) { |
| 211 Py_DECREF(newtuple); | |
| 212 return NULL; | |
| 213 } | |
| 214 } | |
| 215 PyTuple_SET_ITEM(newtuple, i, item); | |
| 216 } | |
| 217 | |
| 218 return newtuple; | |
| 219 } | |
| 220 | |
| 221 PyDoc_STRVAR(code_doc, | |
| 222 "code(argcount, nlocals, stacksize, flags, codestring, constants, names,\n\ | |
| 223 varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]])\n\ | |
| 224 \n\ | |
| 225 Create a code object. Not for the faint of heart."); | |
| 226 | |
| 227 static PyObject * | |
| 228 code_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |
| 229 { | |
| 230 int argcount; | |
| 231 int nlocals; | |
| 232 int stacksize; | |
| 233 int flags; | |
| 234 PyObject *co = NULL; | |
| 235 PyObject *code; | |
| 236 PyObject *consts; | |
| 237 PyObject *names, *ournames = NULL; | |
| 238 PyObject *varnames, *ourvarnames = NULL; | |
| 239 PyObject *freevars = NULL, *ourfreevars = NULL; | |
| 240 PyObject *cellvars = NULL, *ourcellvars = NULL; | |
| 241 PyObject *filename; | |
| 242 PyObject *name; | |
| 243 int firstlineno; | |
| 244 PyObject *lnotab; | |
| 245 | |
| 246 if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS|O!O!:code", | |
| 247 &argcount, &nlocals, &stacksize, &flags, | |
| 248 &code, | |
| 249 &PyTuple_Type, &consts, | |
| 250 &PyTuple_Type, &names, | |
| 251 &PyTuple_Type, &varnames, | |
| 252 &filename, &name, | |
| 253 &firstlineno, &lnotab, | |
| 254 &PyTuple_Type, &freevars, | |
| 255 &PyTuple_Type, &cellvars)) | |
| 256 return NULL; | |
| 257 | |
| 258 if (argcount < 0) { | |
| 259 PyErr_SetString( | |
| 260 PyExc_ValueError, | |
| 261 "code: argcount must not be negative"); | |
| 262 goto cleanup; | |
| 263 } | |
| 264 | |
| 265 if (nlocals < 0) { | |
| 266 PyErr_SetString( | |
| 267 PyExc_ValueError, | |
| 268 "code: nlocals must not be negative"); | |
| 269 goto cleanup; | |
| 270 } | |
| 271 | |
| 272 ournames = validate_and_copy_tuple(names); | |
| 273 if (ournames == NULL) | |
| 274 goto cleanup; | |
| 275 ourvarnames = validate_and_copy_tuple(varnames); | |
| 276 if (ourvarnames == NULL) | |
| 277 goto cleanup; | |
| 278 if (freevars) | |
| 279 ourfreevars = validate_and_copy_tuple(freevars); | |
| 280 else | |
| 281 ourfreevars = PyTuple_New(0); | |
| 282 if (ourfreevars == NULL) | |
| 283 goto cleanup; | |
| 284 if (cellvars) | |
| 285 ourcellvars = validate_and_copy_tuple(cellvars); | |
| 286 else | |
| 287 ourcellvars = PyTuple_New(0); | |
| 288 if (ourcellvars == NULL) | |
| 289 goto cleanup; | |
| 290 | |
| 291 co = (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags, | |
| 292 code, consts, ournames, ourvarnames, | |
| 293 ourfreevars, ourcellvars, filename, | |
| 294 name, firstlineno, lnotab); | |
| 295 cleanup: | |
| 296 Py_XDECREF(ournames); | |
| 297 Py_XDECREF(ourvarnames); | |
| 298 Py_XDECREF(ourfreevars); | |
| 299 Py_XDECREF(ourcellvars); | |
| 300 return co; | |
| 301 } | |
| 302 | |
| 303 static void | |
| 304 code_dealloc(PyCodeObject *co) | |
| 305 { | |
| 306 Py_XDECREF(co->co_code); | |
| 307 Py_XDECREF(co->co_consts); | |
| 308 Py_XDECREF(co->co_names); | |
| 309 Py_XDECREF(co->co_varnames); | |
| 310 Py_XDECREF(co->co_freevars); | |
| 311 Py_XDECREF(co->co_cellvars); | |
| 312 Py_XDECREF(co->co_filename); | |
| 313 Py_XDECREF(co->co_name); | |
| 314 Py_XDECREF(co->co_lnotab); | |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37838
diff
changeset
|
315 if (co->co_zombieframe != NULL) |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37838
diff
changeset
|
316 PyObject_GC_Del(co->co_zombieframe); |
| 35742 | 317 PyObject_DEL(co); |
| 318 } | |
| 319 | |
| 320 static PyObject * | |
| 321 code_repr(PyCodeObject *co) | |
| 322 { | |
| 323 char buf[500]; | |
| 324 int lineno = -1; | |
| 325 char *filename = "???"; | |
| 326 char *name = "???"; | |
| 327 | |
| 328 if (co->co_firstlineno != 0) | |
| 329 lineno = co->co_firstlineno; | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
330 if (co->co_filename && PyString_Check(co->co_filename)) |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
331 filename = PyString_AS_STRING(co->co_filename); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
332 if (co->co_name && PyString_Check(co->co_name)) |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
333 name = PyString_AS_STRING(co->co_name); |
| 35742 | 334 PyOS_snprintf(buf, sizeof(buf), |
| 335 "<code object %.100s at %p, file \"%.300s\", line %d>", | |
| 336 name, co, filename, lineno); | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
337 return PyString_FromString(buf); |
| 35742 | 338 } |
| 339 | |
| 340 static int | |
| 341 code_compare(PyCodeObject *co, PyCodeObject *cp) | |
| 342 { | |
| 343 int cmp; | |
| 344 cmp = PyObject_Compare(co->co_name, cp->co_name); | |
| 345 if (cmp) return cmp; | |
| 346 cmp = co->co_argcount - cp->co_argcount; | |
| 347 if (cmp) goto normalize; | |
| 348 cmp = co->co_nlocals - cp->co_nlocals; | |
| 349 if (cmp) goto normalize; | |
| 350 cmp = co->co_flags - cp->co_flags; | |
| 351 if (cmp) goto normalize; | |
| 352 cmp = co->co_firstlineno - cp->co_firstlineno; | |
| 353 if (cmp) goto normalize; | |
| 354 cmp = PyObject_Compare(co->co_code, cp->co_code); | |
| 355 if (cmp) return cmp; | |
| 356 cmp = PyObject_Compare(co->co_consts, cp->co_consts); | |
| 357 if (cmp) return cmp; | |
| 358 cmp = PyObject_Compare(co->co_names, cp->co_names); | |
| 359 if (cmp) return cmp; | |
| 360 cmp = PyObject_Compare(co->co_varnames, cp->co_varnames); | |
| 361 if (cmp) return cmp; | |
| 362 cmp = PyObject_Compare(co->co_freevars, cp->co_freevars); | |
| 363 if (cmp) return cmp; | |
| 364 cmp = PyObject_Compare(co->co_cellvars, cp->co_cellvars); | |
| 365 return cmp; | |
| 366 | |
| 367 normalize: | |
| 368 if (cmp > 0) | |
| 369 return 1; | |
| 370 else if (cmp < 0) | |
| 371 return -1; | |
| 372 else | |
| 373 return 0; | |
| 374 } | |
| 375 | |
|
45885
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
376 static PyObject * |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
377 code_richcompare(PyObject *self, PyObject *other, int op) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
378 { |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
379 PyCodeObject *co, *cp; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
380 int eq; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
381 PyObject *res; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
382 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
383 if ((op != Py_EQ && op != Py_NE) || |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
384 !PyCode_Check(self) || |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
385 !PyCode_Check(other)) { |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
386 |
|
46075
84bb7701efba
Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents:
45885
diff
changeset
|
387 /* Py3K warning if types are not equal and comparison |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
388 isn't == or != */ |
|
46573
aef3501d8e77
Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents:
46075
diff
changeset
|
389 if (PyErr_WarnPy3k("code inequality comparisons not supported " |
|
46578
7670005da8c5
A little reformating of Py3k warnings
Benjamin Peterson <benjamin@python.org>
parents:
46573
diff
changeset
|
390 "in 3.x", 1) < 0) { |
|
45885
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
391 return NULL; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
392 } |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
393 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
394 Py_INCREF(Py_NotImplemented); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
395 return Py_NotImplemented; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
396 } |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
397 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
398 co = (PyCodeObject *)self; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
399 cp = (PyCodeObject *)other; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
400 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
401 eq = PyObject_RichCompareBool(co->co_name, cp->co_name, Py_EQ); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
402 if (eq <= 0) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
403 eq = co->co_argcount == cp->co_argcount; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
404 if (!eq) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
405 eq = co->co_nlocals == cp->co_nlocals; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
406 if (!eq) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
407 eq = co->co_flags == cp->co_flags; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
408 if (!eq) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
409 eq = co->co_firstlineno == cp->co_firstlineno; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
410 if (!eq) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
411 eq = PyObject_RichCompareBool(co->co_code, cp->co_code, Py_EQ); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
412 if (eq <= 0) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
413 eq = PyObject_RichCompareBool(co->co_consts, cp->co_consts, Py_EQ); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
414 if (eq <= 0) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
415 eq = PyObject_RichCompareBool(co->co_names, cp->co_names, Py_EQ); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
416 if (eq <= 0) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
417 eq = PyObject_RichCompareBool(co->co_varnames, cp->co_varnames, Py_EQ); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
418 if (eq <= 0) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
419 eq = PyObject_RichCompareBool(co->co_freevars, cp->co_freevars, Py_EQ); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
420 if (eq <= 0) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
421 eq = PyObject_RichCompareBool(co->co_cellvars, cp->co_cellvars, Py_EQ); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
422 if (eq <= 0) goto unequal; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
423 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
424 if (op == Py_EQ) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
425 res = Py_True; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
426 else |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
427 res = Py_False; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
428 goto done; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
429 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
430 unequal: |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
431 if (eq < 0) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
432 return NULL; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
433 if (op == Py_NE) |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
434 res = Py_True; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
435 else |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
436 res = Py_False; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
437 |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
438 done: |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
439 Py_INCREF(res); |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
440 return res; |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
441 } |
|
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
442 |
| 35742 | 443 static long |
| 444 code_hash(PyCodeObject *co) | |
| 445 { | |
| 446 long h, h0, h1, h2, h3, h4, h5, h6; | |
| 447 h0 = PyObject_Hash(co->co_name); | |
| 448 if (h0 == -1) return -1; | |
| 449 h1 = PyObject_Hash(co->co_code); | |
| 450 if (h1 == -1) return -1; | |
| 451 h2 = PyObject_Hash(co->co_consts); | |
| 452 if (h2 == -1) return -1; | |
| 453 h3 = PyObject_Hash(co->co_names); | |
| 454 if (h3 == -1) return -1; | |
| 455 h4 = PyObject_Hash(co->co_varnames); | |
| 456 if (h4 == -1) return -1; | |
| 457 h5 = PyObject_Hash(co->co_freevars); | |
| 458 if (h5 == -1) return -1; | |
| 459 h6 = PyObject_Hash(co->co_cellvars); | |
| 460 if (h6 == -1) return -1; | |
| 461 h = h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5 ^ h6 ^ | |
| 462 co->co_argcount ^ co->co_nlocals ^ co->co_flags; | |
| 463 if (h == -1) h = -2; | |
| 464 return h; | |
| 465 } | |
| 466 | |
| 467 /* XXX code objects need to participate in GC? */ | |
| 468 | |
| 469 PyTypeObject PyCode_Type = { | |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
39069
diff
changeset
|
470 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 35742 | 471 "code", |
| 472 sizeof(PyCodeObject), | |
| 473 0, | |
| 474 (destructor)code_dealloc, /* tp_dealloc */ | |
| 475 0, /* tp_print */ | |
| 476 0, /* tp_getattr */ | |
| 477 0, /* tp_setattr */ | |
| 478 (cmpfunc)code_compare, /* tp_compare */ | |
| 479 (reprfunc)code_repr, /* tp_repr */ | |
| 480 0, /* tp_as_number */ | |
| 481 0, /* tp_as_sequence */ | |
| 482 0, /* tp_as_mapping */ | |
| 483 (hashfunc)code_hash, /* tp_hash */ | |
| 484 0, /* tp_call */ | |
| 485 0, /* tp_str */ | |
| 486 PyObject_GenericGetAttr, /* tp_getattro */ | |
| 487 0, /* tp_setattro */ | |
| 488 0, /* tp_as_buffer */ | |
| 489 Py_TPFLAGS_DEFAULT, /* tp_flags */ | |
| 490 code_doc, /* tp_doc */ | |
| 491 0, /* tp_traverse */ | |
| 492 0, /* tp_clear */ | |
|
45885
860e23a61e55
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents:
42333
diff
changeset
|
493 code_richcompare, /* tp_richcompare */ |
| 35742 | 494 0, /* tp_weaklistoffset */ |
| 495 0, /* tp_iter */ | |
| 496 0, /* tp_iternext */ | |
| 497 0, /* tp_methods */ | |
| 498 code_memberlist, /* tp_members */ | |
| 499 0, /* tp_getset */ | |
| 500 0, /* tp_base */ | |
| 501 0, /* tp_dict */ | |
| 502 0, /* tp_descr_get */ | |
| 503 0, /* tp_descr_set */ | |
| 504 0, /* tp_dictoffset */ | |
| 505 0, /* tp_init */ | |
| 506 0, /* tp_alloc */ | |
| 507 code_new, /* tp_new */ | |
| 508 }; | |
| 509 | |
| 54297 | 510 /* Use co_lnotab to compute the line number from a bytecode index, addrq. See |
| 511 lnotab_notes.txt for the details of the lnotab representation. | |
| 35742 | 512 */ |
| 513 | |
| 514 int | |
| 515 PyCode_Addr2Line(PyCodeObject *co, int addrq) | |
| 516 { | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
517 int size = PyString_Size(co->co_lnotab) / 2; |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
518 unsigned char *p = (unsigned char*)PyString_AsString(co->co_lnotab); |
| 35742 | 519 int line = co->co_firstlineno; |
| 520 int addr = 0; | |
| 521 while (--size >= 0) { | |
| 522 addr += *p++; | |
| 523 if (addr > addrq) | |
| 524 break; | |
| 525 line += *p++; | |
| 526 } | |
| 527 return line; | |
| 528 } | |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
529 |
| 54297 | 530 /* Update *bounds to describe the first and one-past-the-last instructions in |
| 531 the same line as lasti. Return the number of that line. */ | |
| 532 int | |
| 533 _PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds) | |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
534 { |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
535 int size, addr, line; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
536 unsigned char* p; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
537 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
538 p = (unsigned char*)PyString_AS_STRING(co->co_lnotab); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
539 size = PyString_GET_SIZE(co->co_lnotab) / 2; |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
540 |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
541 addr = 0; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
542 line = co->co_firstlineno; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
543 assert(line > 0); |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
544 |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
545 /* possible optimization: if f->f_lasti == instr_ub |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
546 (likely to be a common case) then we already know |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
547 instr_lb -- if we stored the matching value of p |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
548 somwhere we could skip the first while loop. */ |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
549 |
| 54297 | 550 /* See lnotab_notes.txt for the description of |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
551 co_lnotab. A point to remember: increments to p |
| 54297 | 552 come in (addr, line) pairs. */ |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
553 |
|
39069
476cd83777f2
Fix uninitialized memory read reported by Valgrind when running doctest.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38244
diff
changeset
|
554 bounds->ap_lower = 0; |
|
37838
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
555 while (size > 0) { |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
556 if (addr + *p > lasti) |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
557 break; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
558 addr += *p++; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
559 if (*p) |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
560 bounds->ap_lower = addr; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
561 line += *p++; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
562 --size; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
563 } |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
564 |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
565 if (size > 0) { |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
566 while (--size >= 0) { |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
567 addr += *p++; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
568 if (*p++) |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
569 break; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
570 } |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
571 bounds->ap_upper = addr; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
572 } |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
573 else { |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
574 bounds->ap_upper = INT_MAX; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
575 } |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
576 |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
577 return line; |
|
cc48985c3266
Refactor: Move code that uses co_lnotab from ceval to codeobject
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36501
diff
changeset
|
578 } |
