Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1875247

Browse files
committed
Quickly renamed.
1 parent 9d0a3df commit 1875247

1 file changed

Lines changed: 101 additions & 100 deletions

File tree

Objects/frameobject.c

Lines changed: 101 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ PERFORMANCE OF THIS SOFTWARE.
3131

3232
/* Frame object implementation */
3333

34-
#include "allobjects.h"
34+
#include "Python.h"
3535

3636
#include "compile.h"
3737
#include "frameobject.h"
3838
#include "opcode.h"
3939
#include "structmember.h"
40-
#include "bltinmodule.h"
4140

42-
#define OFF(x) offsetof(frameobject, x)
41+
#define OFF(x) offsetof(PyFrameObject, x)
4342

4443
static struct memberlist frame_memberlist[] = {
4544
{"f_back", T_OBJECT, OFF(f_back), RO},
@@ -54,23 +53,23 @@ static struct memberlist frame_memberlist[] = {
5453
{NULL} /* Sentinel */
5554
};
5655

57-
static object *
56+
static PyObject *
5857
frame_getattr(f, name)
59-
frameobject *f;
58+
PyFrameObject *f;
6059
char *name;
6160
{
6261
if (strcmp(name, "f_locals") == 0)
63-
fast_2_locals(f);
64-
return getmember((char *)f, frame_memberlist, name);
62+
PyFrame_FastToLocals(f);
63+
return PyMember_Get((char *)f, frame_memberlist, name);
6564
}
6665

6766
static int
6867
frame_setattr(f, name, value)
69-
frameobject *f;
68+
PyFrameObject *f;
7069
char *name;
71-
object *value;
70+
PyObject *value;
7271
{
73-
return setmember((char *)f, frame_memberlist, name, value);
72+
return PyMember_Set((char *)f, frame_memberlist, name, value);
7473
}
7574

7675
/* Stack frames are allocated and deallocated at a considerable rate.
@@ -92,36 +91,36 @@ frame_setattr(f, name, value)
9291
unless the program contains run-away recursion. I hope.
9392
*/
9493

95-
static frameobject *free_list = NULL;
94+
static PyFrameObject *free_list = NULL;
9695

9796
static void
9897
frame_dealloc(f)
99-
frameobject *f;
98+
PyFrameObject *f;
10099
{
101100
int i;
102101
PyObject **fastlocals;
103102

104103
/* Kill all local variables */
105104
fastlocals = f->f_localsplus;
106105
for (i = f->f_nlocals; --i >= 0; ++fastlocals) {
107-
XDECREF(*fastlocals);
106+
Py_XDECREF(*fastlocals);
108107
}
109108

110-
XDECREF(f->f_back);
111-
XDECREF(f->f_code);
112-
XDECREF(f->f_builtins);
113-
XDECREF(f->f_globals);
114-
XDECREF(f->f_locals);
115-
XDECREF(f->f_trace);
109+
Py_XDECREF(f->f_back);
110+
Py_XDECREF(f->f_code);
111+
Py_XDECREF(f->f_builtins);
112+
Py_XDECREF(f->f_globals);
113+
Py_XDECREF(f->f_locals);
114+
Py_XDECREF(f->f_trace);
116115
f->f_back = free_list;
117116
free_list = f;
118117
}
119118

120-
typeobject Frametype = {
121-
OB_HEAD_INIT(&Typetype)
119+
PyTypeObject PyFrame_Type = {
120+
PyObject_HEAD_INIT(&PyType_Type)
122121
0,
123122
"frame",
124-
sizeof(frameobject),
123+
sizeof(PyFrameObject),
125124
0,
126125
(destructor)frame_dealloc, /*tp_dealloc*/
127126
0, /*tp_print*/
@@ -134,89 +133,91 @@ typeobject Frametype = {
134133
0, /*tp_as_mapping*/
135134
};
136135

137-
frameobject *
138-
newframeobject(back, code, globals, locals)
139-
frameobject *back;
140-
codeobject *code;
141-
object *globals;
142-
object *locals;
136+
PyFrameObject *
137+
PyFrame_New(back, code, globals, locals)
138+
PyFrameObject *back;
139+
PyCodeObject *code;
140+
PyObject *globals;
141+
PyObject *locals;
143142
{
144-
static object *builtin_object;
145-
frameobject *f;
146-
object *builtins;
143+
static PyObject *builtin_object;
144+
PyFrameObject *f;
145+
PyObject *builtins;
147146
int extras = code->co_stacksize + code->co_nlocals;
148147

149148
if (builtin_object == NULL) {
150149
builtin_object = PyString_InternFromString("__builtins__");
151150
if (builtin_object == NULL)
152151
return NULL;
153152
}
154-
if ((back != NULL && !is_frameobject(back)) ||
155-
code == NULL || !is_codeobject(code) ||
156-
globals == NULL || !is_dictobject(globals) ||
157-
(locals != NULL && !is_dictobject(locals))) {
158-
err_badcall();
153+
if ((back != NULL && !PyFrame_Check(back)) ||
154+
code == NULL || !PyCode_Check(code) ||
155+
globals == NULL || !PyDict_Check(globals) ||
156+
(locals != NULL && !PyDict_Check(locals))) {
157+
PyErr_BadInternalCall();
159158
return NULL;
160159
}
161-
builtins = mappinglookup(globals, builtin_object);
162-
if (builtins != NULL && is_moduleobject(builtins))
163-
builtins = getmoduledict(builtins);
164-
if (builtins == NULL || !is_mappingobject(builtins)) {
165-
err_setstr(TypeError, "bad __builtins__ dictionary");
160+
builtins = PyDict_GetItem(globals, builtin_object);
161+
if (builtins != NULL && PyModule_Check(builtins))
162+
builtins = PyModule_GetDict(builtins);
163+
if (builtins == NULL || !PyDict_Check(builtins)) {
164+
PyErr_SetString(PyExc_TypeError,
165+
"bad __builtins__ dictionary");
166166
return NULL;
167167
}
168168
if (free_list == NULL) {
169-
f = (frameobject *)
170-
malloc(sizeof(frameobject) + extras*sizeof(object *));
169+
f = (PyFrameObject *)
170+
malloc(sizeof(PyFrameObject) +
171+
extras*sizeof(PyObject *));
171172
if (f == NULL)
172-
return (PyFrameObject *)err_nomem();
173-
f->ob_type = &Frametype;
174-
NEWREF(f);
173+
return (PyFrameObject *)PyErr_NoMemory();
174+
f->ob_type = &PyFrame_Type;
175+
_Py_NewReference(f);
175176
}
176177
else {
177178
f = free_list;
178179
free_list = free_list->f_back;
179180
if (f->f_nlocals + f->f_stacksize < extras) {
180-
f = realloc(f, sizeof(frameobject) +
181-
extras*sizeof(object *));
181+
f = realloc(f, sizeof(PyFrameObject) +
182+
extras*sizeof(PyObject *));
182183
if (f == NULL)
183-
return (PyFrameObject *)err_nomem();
184+
return (PyFrameObject *)PyErr_NoMemory();
184185
}
185186
else
186187
extras = f->f_nlocals + f->f_stacksize;
187-
f->ob_type = &Frametype;
188-
NEWREF(f);
188+
f->ob_type = &PyFrame_Type;
189+
_Py_NewReference(f);
189190
}
190-
XINCREF(back);
191+
Py_XINCREF(back);
191192
f->f_back = back;
192-
INCREF(code);
193+
Py_INCREF(code);
193194
f->f_code = code;
194-
XINCREF(builtins);
195+
Py_XINCREF(builtins);
195196
f->f_builtins = builtins;
196-
INCREF(globals);
197+
Py_INCREF(globals);
197198
f->f_globals = globals;
198199
if (code->co_flags & CO_NEWLOCALS) {
199200
if (code->co_flags & CO_OPTIMIZED)
200201
locals = NULL; /* Let fast_2_locals handle it */
201202
else {
202-
locals = newdictobject();
203+
locals = PyDict_New();
203204
if (locals == NULL) {
204-
DECREF(f);
205+
Py_DECREF(f);
205206
return NULL;
206207
}
207208
}
208209
}
209210
else {
210211
if (locals == NULL)
211212
locals = globals;
212-
INCREF(locals);
213+
Py_INCREF(locals);
213214
}
214215
f->f_locals = locals;
215216
f->f_trace = NULL;
216217

217218
f->f_lasti = 0;
218219
f->f_lineno = code->co_firstlineno;
219-
f->f_restricted = (builtins != getbuiltindict());
220+
f->f_restricted = (builtins != PyBuiltin_GetDict());
220221
f->f_iblock = 0;
221222
f->f_nlocals = code->co_nlocals;
222223
f->f_stacksize = extras - code->co_nlocals;
@@ -232,113 +233,113 @@ newframeobject(back, code, globals, locals)
232233
/* Block management */
233234

234235
void
235-
setup_block(f, type, handler, level)
236-
frameobject *f;
236+
PyFrame_BlockSetup(f, type, handler, level)
237+
PyFrameObject *f;
237238
int type;
238239
int handler;
239240
int level;
240241
{
241-
block *b;
242+
PyTryBlock *b;
242243
if (f->f_iblock >= CO_MAXBLOCKS)
243-
fatal("XXX block stack overflow");
244+
Py_FatalError("XXX block stack overflow");
244245
b = &f->f_blockstack[f->f_iblock++];
245246
b->b_type = type;
246247
b->b_level = level;
247248
b->b_handler = handler;
248249
}
249250

250-
block *
251-
pop_block(f)
252-
frameobject *f;
251+
PyTryBlock *
252+
PyFrame_BlockPop(f)
253+
PyFrameObject *f;
253254
{
254-
block *b;
255+
PyTryBlock *b;
255256
if (f->f_iblock <= 0)
256-
fatal("XXX block stack underflow");
257+
Py_FatalError("XXX block stack underflow");
257258
b = &f->f_blockstack[--f->f_iblock];
258259
return b;
259260
}
260261

261262
/* Convert between "fast" version of locals and dictionary version */
262263

263264
void
264-
fast_2_locals(f)
265-
frameobject *f;
265+
PyFrame_FastToLocals(f)
266+
PyFrameObject *f;
266267
{
267268
/* Merge fast locals into f->f_locals */
268-
object *locals, *map;
269-
object **fast;
270-
object *error_type, *error_value, *error_traceback;
269+
PyObject *locals, *map;
270+
PyObject **fast;
271+
PyObject *error_type, *error_value, *error_traceback;
271272
int j;
272273
if (f == NULL)
273274
return;
274275
locals = f->f_locals;
275276
if (locals == NULL) {
276-
locals = f->f_locals = newdictobject();
277+
locals = f->f_locals = PyDict_New();
277278
if (locals == NULL) {
278-
err_clear(); /* Can't report it :-( */
279+
PyErr_Clear(); /* Can't report it :-( */
279280
return;
280281
}
281282
}
282283
if (f->f_nlocals == 0)
283284
return;
284285
map = f->f_code->co_varnames;
285-
if (!is_dictobject(locals) || !is_tupleobject(map))
286+
if (!PyDict_Check(locals) || !PyTuple_Check(map))
286287
return;
287-
err_fetch(&error_type, &error_value, &error_traceback);
288+
PyErr_Fetch(&error_type, &error_value, &error_traceback);
288289
fast = f->f_localsplus;
289-
j = gettuplesize(map);
290+
j = PyTuple_Size(map);
290291
if (j > f->f_nlocals)
291292
j = f->f_nlocals;
292293
for (; --j >= 0; ) {
293-
object *key = gettupleitem(map, j);
294-
object *value = fast[j];
294+
PyObject *key = PyTuple_GetItem(map, j);
295+
PyObject *value = fast[j];
295296
if (value == NULL) {
296-
err_clear();
297-
if (dict2remove(locals, key) != 0)
298-
err_clear();
297+
PyErr_Clear();
298+
if (PyDict_DelItem(locals, key) != 0)
299+
PyErr_Clear();
299300
}
300301
else {
301-
if (dict2insert(locals, key, value) != 0)
302-
err_clear();
302+
if (PyDict_SetItem(locals, key, value) != 0)
303+
PyErr_Clear();
303304
}
304305
}
305-
err_restore(error_type, error_value, error_traceback);
306+
PyErr_Restore(error_type, error_value, error_traceback);
306307
}
307308

308309
void
309-
locals_2_fast(f, clear)
310-
frameobject *f;
310+
PyFrame_LocalsToFast(f, clear)
311+
PyFrameObject *f;
311312
int clear;
312313
{
313314
/* Merge f->f_locals into fast locals */
314-
object *locals, *map;
315-
object **fast;
316-
object *error_type, *error_value, *error_traceback;
315+
PyObject *locals, *map;
316+
PyObject **fast;
317+
PyObject *error_type, *error_value, *error_traceback;
317318
int j;
318319
if (f == NULL)
319320
return;
320321
locals = f->f_locals;
321322
map = f->f_code->co_varnames;
322323
if (locals == NULL || f->f_code->co_nlocals == 0)
323324
return;
324-
if (!is_dictobject(locals) || !is_tupleobject(map))
325+
if (!PyDict_Check(locals) || !PyTuple_Check(map))
325326
return;
326-
err_fetch(&error_type, &error_value, &error_traceback);
327+
PyErr_Fetch(&error_type, &error_value, &error_traceback);
327328
fast = f->f_localsplus;
328-
j = gettuplesize(map);
329+
j = PyTuple_Size(map);
329330
if (j > f->f_nlocals)
330331
j = f->f_nlocals;
331332
for (; --j >= 0; ) {
332-
object *key = gettupleitem(map, j);
333-
object *value = dict2lookup(locals, key);
333+
PyObject *key = PyTuple_GetItem(map, j);
334+
PyObject *value = PyDict_GetItem(locals, key);
334335
if (value == NULL)
335-
err_clear();
336+
PyErr_Clear();
336337
else
337-
INCREF(value);
338+
Py_INCREF(value);
338339
if (value != NULL || clear) {
339-
XDECREF(fast[j]);
340+
Py_XDECREF(fast[j]);
340341
fast[j] = value;
341342
}
342343
}
343-
err_restore(error_type, error_value, error_traceback);
344+
PyErr_Restore(error_type, error_value, error_traceback);
344345
}

0 commit comments

Comments
 (0)