Mercurial > cpython-lru_cache-weakref
annotate Objects/frameobject.c @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | e334dd4e510f |
| children |
| rev | line source |
|---|---|
| 145 | 1 |
| 86 | 2 /* Frame object implementation */ |
| 3 | |
| 5350 | 4 #include "Python.h" |
| 86 | 5 |
| 6 #include "compile.h" | |
| 7 #include "frameobject.h" | |
| 8 #include "opcode.h" | |
| 9 #include "structmember.h" | |
| 10 | |
| 5350 | 11 #define OFF(x) offsetof(PyFrameObject, x) |
| 86 | 12 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19588
diff
changeset
|
13 static PyMemberDef frame_memberlist[] = { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
14 {"f_back", T_OBJECT, OFF(f_back), RO}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
15 {"f_code", T_OBJECT, OFF(f_code), RO}, |
|
2104
7493c6805dc6
add builtins handling and restricted flag
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
16 {"f_builtins", T_OBJECT, OFF(f_builtins),RO}, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
17 {"f_globals", T_OBJECT, OFF(f_globals), RO}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
18 {"f_lasti", T_INT, OFF(f_lasti), RO}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
19 {"f_lineno", T_INT, OFF(f_lineno), RO}, |
|
2104
7493c6805dc6
add builtins handling and restricted flag
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
20 {"f_restricted",T_INT, OFF(f_restricted),RO}, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
21 {"f_trace", T_OBJECT, OFF(f_trace)}, |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
22 {"f_exc_type", T_OBJECT, OFF(f_exc_type)}, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
23 {"f_exc_value", T_OBJECT, OFF(f_exc_value)}, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
24 {"f_exc_traceback", T_OBJECT, OFF(f_exc_traceback)}, |
| 86 | 25 {NULL} /* Sentinel */ |
| 26 }; | |
| 27 | |
| 5350 | 28 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
29 frame_getlocals(PyFrameObject *f, void *closure) |
| 86 | 30 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
31 PyFrame_FastToLocals(f); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
32 Py_INCREF(f->f_locals); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
33 return f->f_locals; |
| 86 | 34 } |
| 35 | |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
36 static PyGetSetDef frame_getsetlist[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
37 {"f_locals", (getter)frame_getlocals, NULL, NULL}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
38 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
39 }; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
40 |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
41 /* Stack frames are allocated and deallocated at a considerable rate. |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
42 In an attempt to improve the speed of function calls, we maintain a |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
43 separate free list of stack frames (just like integers are |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
44 allocated in a special way -- see intobject.c). When a stack frame |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
45 is on the free list, only the following members have a meaning: |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
46 ob_type == &Frametype |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
47 f_back next item on free list, or NULL |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
48 f_nlocals number of locals |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
49 f_stacksize size of value stack |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
50 ob_size size of localsplus |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
51 Note that the value and block stacks are preserved -- this can save |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
52 another malloc() call or two (and two free() calls as well!). |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
53 Also note that, unlike for integers, each frame object is a |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
54 malloc'ed object in its own right -- it is only the actual calls to |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
55 malloc() that we are trying to save here, not the administration. |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
56 After all, while a typical program may make millions of calls, a |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
57 call depth of more than 20 or 30 is probably already exceptional |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
58 unless the program contains run-away recursion. I hope. |
|
23019
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
59 |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
60 Later, MAXFREELIST was added to bound the # of frames saved on |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
61 free_list. Else programs creating lots of cyclic trash involving |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
62 frames could provoke free_list into growing without bound. |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
63 */ |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
64 |
| 5350 | 65 static PyFrameObject *free_list = NULL; |
|
23019
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
66 static int numfree = 0; /* number of frames currently in free_list */ |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
67 #define MAXFREELIST 200 /* max value for numfree */ |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
68 |
| 86 | 69 static void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
70 frame_dealloc(PyFrameObject *f) |
| 86 | 71 { |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
72 int i, slots; |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
73 PyObject **fastlocals; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17701
diff
changeset
|
74 PyObject **p; |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
75 |
| 22626 | 76 PyObject_GC_UnTrack(f); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
77 Py_TRASHCAN_SAFE_BEGIN(f) |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
78 /* Kill all local variables */ |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
79 slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
80 fastlocals = f->f_localsplus; |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
81 for (i = slots; --i >= 0; ++fastlocals) { |
| 5350 | 82 Py_XDECREF(*fastlocals); |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
83 } |
|
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
84 |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17701
diff
changeset
|
85 /* Free stack */ |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
86 if (f->f_stacktop != NULL) { |
|
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
87 for (p = f->f_valuestack; p < f->f_stacktop; p++) |
|
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
88 Py_XDECREF(*p); |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17701
diff
changeset
|
89 } |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
90 |
| 5350 | 91 Py_XDECREF(f->f_back); |
| 92 Py_XDECREF(f->f_code); | |
| 93 Py_XDECREF(f->f_builtins); | |
| 94 Py_XDECREF(f->f_globals); | |
| 95 Py_XDECREF(f->f_locals); | |
| 96 Py_XDECREF(f->f_trace); | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
97 Py_XDECREF(f->f_exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
98 Py_XDECREF(f->f_exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
99 Py_XDECREF(f->f_exc_traceback); |
|
23019
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
100 if (numfree < MAXFREELIST) { |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
101 ++numfree; |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
102 f->f_back = free_list; |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
103 free_list = f; |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
104 } |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
105 else |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
106 PyObject_GC_Del(f); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
107 Py_TRASHCAN_SAFE_END(f) |
| 86 | 108 } |
| 109 | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
110 static int |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
111 frame_traverse(PyFrameObject *f, visitproc visit, void *arg) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
112 { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
113 PyObject **fastlocals, **p; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
114 int i, err, slots; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
115 #define VISIT(o) if (o) {if ((err = visit((PyObject *)(o), arg))) return err;} |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
116 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
117 VISIT(f->f_back); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
118 VISIT(f->f_code); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
119 VISIT(f->f_builtins); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
120 VISIT(f->f_globals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
121 VISIT(f->f_locals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
122 VISIT(f->f_trace); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
123 VISIT(f->f_exc_type); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
124 VISIT(f->f_exc_value); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
125 VISIT(f->f_exc_traceback); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
126 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
127 /* locals */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
128 slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
129 fastlocals = f->f_localsplus; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
130 for (i = slots; --i >= 0; ++fastlocals) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
131 VISIT(*fastlocals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
132 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
133 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
134 /* stack */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
135 if (f->f_stacktop != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
136 for (p = f->f_valuestack; p < f->f_stacktop; p++) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
137 VISIT(*p); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
138 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
139 return 0; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
140 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
141 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
142 static void |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
143 frame_clear(PyFrameObject *f) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
144 { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
145 PyObject **fastlocals, **p; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
146 int i, slots; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
147 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
148 Py_XDECREF(f->f_exc_type); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
149 f->f_exc_type = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
150 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
151 Py_XDECREF(f->f_exc_value); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
152 f->f_exc_value = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
153 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
154 Py_XDECREF(f->f_exc_traceback); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
155 f->f_exc_traceback = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
156 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
157 Py_XDECREF(f->f_trace); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
158 f->f_trace = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
159 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
160 /* locals */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
161 slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
162 fastlocals = f->f_localsplus; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
163 for (i = slots; --i >= 0; ++fastlocals) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
164 if (*fastlocals != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
165 Py_XDECREF(*fastlocals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
166 *fastlocals = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
167 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
168 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
169 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
170 /* stack */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
171 if (f->f_stacktop != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
172 for (p = f->f_valuestack; p < f->f_stacktop; p++) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
173 Py_XDECREF(*p); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
174 *p = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
175 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
176 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
177 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
178 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
179 |
| 5350 | 180 PyTypeObject PyFrame_Type = { |
| 181 PyObject_HEAD_INIT(&PyType_Type) | |
| 86 | 182 0, |
| 183 "frame", | |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
184 sizeof(PyFrameObject), |
|
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
185 sizeof(PyObject *), |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
186 (destructor)frame_dealloc, /* tp_dealloc */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
187 0, /* tp_print */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
188 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
189 0, /* tp_setattr */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
190 0, /* tp_compare */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
191 0, /* tp_repr */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
192 0, /* tp_as_number */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
193 0, /* tp_as_sequence */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
194 0, /* tp_as_mapping */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
195 0, /* tp_hash */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
196 0, /* tp_call */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
197 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
198 PyObject_GenericGetAttr, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
199 PyObject_GenericSetAttr, /* tp_setattro */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
200 0, /* tp_as_buffer */ |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
201 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
202 0, /* tp_doc */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
203 (traverseproc)frame_traverse, /* tp_traverse */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
204 (inquiry)frame_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
205 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
206 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
207 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
208 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
209 0, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
210 frame_memberlist, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
211 frame_getsetlist, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
212 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
213 0, /* tp_dict */ |
| 86 | 214 }; |
| 215 | |
| 5350 | 216 PyFrameObject * |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
217 PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
218 PyObject *locals) |
| 86 | 219 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
220 PyFrameObject *back = tstate->frame; |
| 5350 | 221 static PyObject *builtin_object; |
| 222 PyFrameObject *f; | |
| 223 PyObject *builtins; | |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
224 int extras, ncells, nfrees; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
225 |
|
2627
e9ea05702676
Use mappinglookup instead of dictlookup for looking up __builtin__.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2151
diff
changeset
|
226 if (builtin_object == NULL) { |
|
5007
e4f7c331bb1a
Intern the strings "__builtins__".
Guido van Rossum <guido@python.org>
parents:
4996
diff
changeset
|
227 builtin_object = PyString_InternFromString("__builtins__"); |
|
2627
e9ea05702676
Use mappinglookup instead of dictlookup for looking up __builtin__.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2151
diff
changeset
|
228 if (builtin_object == NULL) |
|
e9ea05702676
Use mappinglookup instead of dictlookup for looking up __builtin__.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2151
diff
changeset
|
229 return NULL; |
|
e9ea05702676
Use mappinglookup instead of dictlookup for looking up __builtin__.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2151
diff
changeset
|
230 } |
| 5350 | 231 if ((back != NULL && !PyFrame_Check(back)) || |
| 232 code == NULL || !PyCode_Check(code) || | |
| 233 globals == NULL || !PyDict_Check(globals) || | |
| 234 (locals != NULL && !PyDict_Check(locals))) { | |
| 235 PyErr_BadInternalCall(); | |
| 86 | 236 return NULL; |
| 237 } | |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
238 ncells = PyTuple_GET_SIZE(code->co_cellvars); |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
239 nfrees = PyTuple_GET_SIZE(code->co_freevars); |
|
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
240 extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
241 if (back == NULL || back->f_globals != globals) { |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
242 builtins = PyDict_GetItem(globals, builtin_object); |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
243 if (builtins != NULL && PyModule_Check(builtins)) |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
244 builtins = PyModule_GetDict(builtins); |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
245 } |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
246 else { |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
247 /* If we share the globals, we share the builtins. |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
248 Save a lookup and a call. */ |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
249 builtins = back->f_builtins; |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
250 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
251 if (builtins != NULL && !PyDict_Check(builtins)) |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
252 builtins = NULL; |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
253 if (free_list == NULL) { |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
254 f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
255 if (f == NULL) |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
256 return NULL; |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
257 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
258 else { |
|
23019
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
259 assert(numfree > 0); |
|
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
260 --numfree; |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
261 f = free_list; |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
262 free_list = free_list->f_back; |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
263 if (f->ob_size < extras) { |
|
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
264 f = PyObject_GC_Resize(PyFrameObject, f, extras); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
265 if (f == NULL) |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
266 return NULL; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
267 } |
|
19588
2fe08918fac6
Squash new compiler wng in debug build.
Tim Peters <tim.peters@gmail.com>
parents:
19579
diff
changeset
|
268 _Py_NewReference((PyObject *)f); |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
269 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
270 if (builtins == NULL) { |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
271 /* No builtins! Make up a minimal one. */ |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
272 builtins = PyDict_New(); |
|
9403
58a35e5d13cc
A Py_DECREF(f) is missing in PyFrame_New for the error case when
Guido van Rossum <guido@python.org>
parents:
9143
diff
changeset
|
273 if (builtins == NULL || /* Give them 'None', at least. */ |
|
58a35e5d13cc
A Py_DECREF(f) is missing in PyFrame_New for the error case when
Guido van Rossum <guido@python.org>
parents:
9143
diff
changeset
|
274 PyDict_SetItemString(builtins, "None", Py_None) < 0) { |
|
58a35e5d13cc
A Py_DECREF(f) is missing in PyFrame_New for the error case when
Guido van Rossum <guido@python.org>
parents:
9143
diff
changeset
|
275 Py_DECREF(f); |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
276 return NULL; |
|
9403
58a35e5d13cc
A Py_DECREF(f) is missing in PyFrame_New for the error case when
Guido van Rossum <guido@python.org>
parents:
9143
diff
changeset
|
277 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
278 } |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
279 else |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
280 Py_XINCREF(builtins); |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
281 f->f_builtins = builtins; |
| 5350 | 282 Py_XINCREF(back); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
283 f->f_back = back; |
| 5350 | 284 Py_INCREF(code); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
285 f->f_code = code; |
| 5350 | 286 Py_INCREF(globals); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
287 f->f_globals = globals; |
|
2856
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
288 if (code->co_flags & CO_NEWLOCALS) { |
|
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
289 if (code->co_flags & CO_OPTIMIZED) |
|
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
290 locals = NULL; /* Let fast_2_locals handle it */ |
|
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
291 else { |
| 5350 | 292 locals = PyDict_New(); |
|
2856
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
293 if (locals == NULL) { |
| 5350 | 294 Py_DECREF(f); |
|
2856
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
295 return NULL; |
|
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
296 } |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
297 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
298 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
299 else { |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
300 if (locals == NULL) |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
301 locals = globals; |
| 5350 | 302 Py_INCREF(locals); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
303 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
304 f->f_locals = locals; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
305 f->f_trace = NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
306 f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL; |
|
5921
800a5217e67e
Avoid function calls to access the current thread state and builtins
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
307 f->f_tstate = tstate; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
308 |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
309 f->f_lasti = 0; |
|
5045
b1d82697c0b2
When a recycled frame has more local+stack slots than needed,
Guido van Rossum <guido@python.org>
parents:
5015
diff
changeset
|
310 f->f_lineno = code->co_firstlineno; |
|
5921
800a5217e67e
Avoid function calls to access the current thread state and builtins
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
311 f->f_restricted = (builtins != tstate->interp->builtins); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
312 f->f_iblock = 0; |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
313 f->f_nlocals = code->co_nlocals; |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
314 f->f_stacksize = code->co_stacksize; |
|
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
315 f->f_ncells = ncells; |
|
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
316 f->f_nfreevars = nfrees; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
317 |
| 24464 | 318 extras = f->f_nlocals + ncells + nfrees; |
| 319 memset(f->f_localsplus, 0, extras * sizeof(f->f_localsplus[0])); | |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
320 |
| 24464 | 321 f->f_valuestack = f->f_localsplus + extras; |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
322 f->f_stacktop = f->f_valuestack; |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
323 _PyObject_GC_TRACK(f); |
| 86 | 324 return f; |
| 325 } | |
| 326 | |
| 327 /* Block management */ | |
| 328 | |
| 329 void | |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
330 PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level) |
| 86 | 331 { |
| 5350 | 332 PyTryBlock *b; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
333 if (f->f_iblock >= CO_MAXBLOCKS) |
| 5350 | 334 Py_FatalError("XXX block stack overflow"); |
| 86 | 335 b = &f->f_blockstack[f->f_iblock++]; |
| 336 b->b_type = type; | |
| 337 b->b_level = level; | |
| 338 b->b_handler = handler; | |
| 339 } | |
| 340 | |
| 5350 | 341 PyTryBlock * |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
342 PyFrame_BlockPop(PyFrameObject *f) |
| 86 | 343 { |
| 5350 | 344 PyTryBlock *b; |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
345 if (f->f_iblock <= 0) |
| 5350 | 346 Py_FatalError("XXX block stack underflow"); |
| 86 | 347 b = &f->f_blockstack[--f->f_iblock]; |
| 348 return b; | |
| 349 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
350 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
351 /* Convert between "fast" version of locals and dictionary version */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
352 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
353 static void |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
354 map_to_dict(PyObject *map, int nmap, PyObject *dict, PyObject **values, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
355 int deref) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
356 { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
357 int j; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
358 for (j = nmap; --j >= 0; ) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
359 PyObject *key = PyTuple_GET_ITEM(map, j); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
360 PyObject *value = values[j]; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
361 if (deref) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
362 value = PyCell_GET(value); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
363 if (value == NULL) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
364 if (PyDict_DelItem(dict, key) != 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
365 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
366 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
367 else { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
368 if (PyDict_SetItem(dict, key, value) != 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
369 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
370 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
371 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
372 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
373 |
|
17519
f9dfd587c142
Make one more private symbol static.
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
374 static void |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
375 dict_to_map(PyObject *map, int nmap, PyObject *dict, PyObject **values, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
376 int deref, int clear) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
377 { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
378 int j; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
379 for (j = nmap; --j >= 0; ) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
380 PyObject *key = PyTuple_GET_ITEM(map, j); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
381 PyObject *value = PyDict_GetItem(dict, key); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
382 if (deref) { |
|
17701
ded41be84da4
SF patch 419176 from MvL; fixed bug 418977
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17519
diff
changeset
|
383 if (value || clear) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
384 if (PyCell_GET(values[j]) != value) { |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
385 if (PyCell_Set(values[j], value) < 0) |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
386 PyErr_Clear(); |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
387 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
388 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
389 } else if (value != NULL || clear) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
390 if (values[j] != value) { |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
391 Py_XINCREF(value); |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
392 Py_XDECREF(values[j]); |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
393 values[j] = value; |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
394 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
395 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
396 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
397 } |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
398 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
399 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
400 PyFrame_FastToLocals(PyFrameObject *f) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
401 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
402 /* Merge fast locals into f->f_locals */ |
| 5350 | 403 PyObject *locals, *map; |
| 404 PyObject **fast; | |
| 405 PyObject *error_type, *error_value, *error_traceback; | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
406 int j; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
407 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
408 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
409 locals = f->f_locals; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
410 if (locals == NULL) { |
| 5350 | 411 locals = f->f_locals = PyDict_New(); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
412 if (locals == NULL) { |
| 5350 | 413 PyErr_Clear(); /* Can't report it :-( */ |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
414 return; |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
415 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
416 } |
|
2856
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
417 map = f->f_code->co_varnames; |
| 5350 | 418 if (!PyDict_Check(locals) || !PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
419 return; |
| 5350 | 420 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
421 fast = f->f_localsplus; |
| 5350 | 422 j = PyTuple_Size(map); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
423 if (j > f->f_nlocals) |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
424 j = f->f_nlocals; |
|
23188
2fd63d75e92f
backport fix for SF buf #505315 from trunk
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23019
diff
changeset
|
425 if (f->f_nlocals) |
|
2fd63d75e92f
backport fix for SF buf #505315 from trunk
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23019
diff
changeset
|
426 map_to_dict(map, j, locals, fast, 0); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
427 if (f->f_ncells || f->f_nfreevars) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
428 if (!(PyTuple_Check(f->f_code->co_cellvars) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
429 && PyTuple_Check(f->f_code->co_freevars))) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
430 Py_DECREF(locals); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
431 return; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
432 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
433 map_to_dict(f->f_code->co_cellvars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
434 PyTuple_GET_SIZE(f->f_code->co_cellvars), |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
435 locals, fast + f->f_nlocals, 1); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
436 map_to_dict(f->f_code->co_freevars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
437 PyTuple_GET_SIZE(f->f_code->co_freevars), |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
438 locals, fast + f->f_nlocals + f->f_ncells, 1); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
439 } |
| 5350 | 440 PyErr_Restore(error_type, error_value, error_traceback); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
441 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
442 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
443 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
444 PyFrame_LocalsToFast(PyFrameObject *f, int clear) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
445 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
446 /* Merge f->f_locals into fast locals */ |
| 5350 | 447 PyObject *locals, *map; |
| 448 PyObject **fast; | |
| 449 PyObject *error_type, *error_value, *error_traceback; | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
450 int j; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
451 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
452 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
453 locals = f->f_locals; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
454 map = f->f_code->co_varnames; |
|
23188
2fd63d75e92f
backport fix for SF buf #505315 from trunk
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23019
diff
changeset
|
455 if (locals == NULL) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
456 return; |
| 5350 | 457 if (!PyDict_Check(locals) || !PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
458 return; |
| 5350 | 459 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
460 fast = f->f_localsplus; |
| 5350 | 461 j = PyTuple_Size(map); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
462 if (j > f->f_nlocals) |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
463 j = f->f_nlocals; |
|
23188
2fd63d75e92f
backport fix for SF buf #505315 from trunk
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23019
diff
changeset
|
464 if (f->f_nlocals) |
|
2fd63d75e92f
backport fix for SF buf #505315 from trunk
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23019
diff
changeset
|
465 dict_to_map(f->f_code->co_varnames, j, locals, fast, 0, clear); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
466 if (f->f_ncells || f->f_nfreevars) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
467 if (!(PyTuple_Check(f->f_code->co_cellvars) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
468 && PyTuple_Check(f->f_code->co_freevars))) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
469 return; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
470 dict_to_map(f->f_code->co_cellvars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
471 PyTuple_GET_SIZE(f->f_code->co_cellvars), |
|
17701
ded41be84da4
SF patch 419176 from MvL; fixed bug 418977
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17519
diff
changeset
|
472 locals, fast + f->f_nlocals, 1, clear); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
473 dict_to_map(f->f_code->co_freevars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
474 PyTuple_GET_SIZE(f->f_code->co_freevars), |
|
17701
ded41be84da4
SF patch 419176 from MvL; fixed bug 418977
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17519
diff
changeset
|
475 locals, fast + f->f_nlocals + f->f_ncells, 1, clear); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
476 } |
| 5350 | 477 PyErr_Restore(error_type, error_value, error_traceback); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
478 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
479 |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
480 /* Clear out the free list */ |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
481 |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
482 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
483 PyFrame_Fini(void) |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
484 { |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
485 while (free_list != NULL) { |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
486 PyFrameObject *f = free_list; |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
487 free_list = free_list->f_back; |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
488 PyObject_GC_Del(f); |
|
23019
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
489 --numfree; |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
490 } |
|
23019
c6003de73975
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
491 assert(numfree == 0); |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
492 } |
