Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(9)

Side by Side Diff: Objects/codeobject.c

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Objects/bytes_methods.c ('k') | Objects/genobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Python.h" 1 #include "Python.h"
2 #include "code.h" 2 #include "code.h"
3 #include "structmember.h" 3 #include "structmember.h"
4 4
5 #define NAME_CHARS \ 5 #define NAME_CHARS \
6 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" 6 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
7 7
8 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ 8 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
9 9
10 static int 10 static int
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 PyCodeObject * 45 PyCodeObject *
46 PyCode_New(int argcount, int kwonlyargcount, 46 PyCode_New(int argcount, int kwonlyargcount,
47 int nlocals, int stacksize, int flags, 47 int nlocals, int stacksize, int flags,
48 PyObject *code, PyObject *consts, PyObject *names, 48 PyObject *code, PyObject *consts, PyObject *names,
49 PyObject *varnames, PyObject *freevars, PyObject *cellvars, 49 PyObject *varnames, PyObject *freevars, PyObject *cellvars,
50 PyObject *filename, PyObject *name, int firstlineno, 50 PyObject *filename, PyObject *name, int firstlineno,
51 PyObject *lnotab) 51 PyObject *lnotab)
52 { 52 {
53 PyCodeObject *co; 53 PyCodeObject *co;
54 unsigned char *cell2arg = NULL; 54 Py_ssize_t i;
55 Py_ssize_t i, n_cellvars;
56 55
57 /* Check argument types */ 56 /* Check argument types */
58 if (argcount < 0 || kwonlyargcount < 0 || nlocals < 0 || 57 if (argcount < 0 || kwonlyargcount < 0 || nlocals < 0 ||
59 code == NULL || 58 code == NULL ||
60 consts == NULL || !PyTuple_Check(consts) || 59 consts == NULL || !PyTuple_Check(consts) ||
61 names == NULL || !PyTuple_Check(names) || 60 names == NULL || !PyTuple_Check(names) ||
62 varnames == NULL || !PyTuple_Check(varnames) || 61 varnames == NULL || !PyTuple_Check(varnames) ||
63 freevars == NULL || !PyTuple_Check(freevars) || 62 freevars == NULL || !PyTuple_Check(freevars) ||
64 cellvars == NULL || !PyTuple_Check(cellvars) || 63 cellvars == NULL || !PyTuple_Check(cellvars) ||
65 name == NULL || !PyUnicode_Check(name) || 64 name == NULL || !PyUnicode_Check(name) ||
66 filename == NULL || !PyUnicode_Check(filename) || 65 filename == NULL || !PyUnicode_Check(filename) ||
67 lnotab == NULL || !PyBytes_Check(lnotab) || 66 lnotab == NULL || !PyBytes_Check(lnotab) ||
68 !PyObject_CheckReadBuffer(code)) { 67 !PyObject_CheckReadBuffer(code)) {
69 PyErr_BadInternalCall(); 68 PyErr_BadInternalCall();
70 return NULL; 69 return NULL;
71 } 70 }
72 n_cellvars = PyTuple_GET_SIZE(cellvars);
73 intern_strings(names); 71 intern_strings(names);
74 intern_strings(varnames); 72 intern_strings(varnames);
75 intern_strings(freevars); 73 intern_strings(freevars);
76 intern_strings(cellvars); 74 intern_strings(cellvars);
77 /* Intern selected string constants */ 75 /* Intern selected string constants */
78 for (i = PyTuple_GET_SIZE(consts); --i >= 0; ) { 76 for (i = PyTuple_Size(consts); --i >= 0; ) {
79 PyObject *v = PyTuple_GetItem(consts, i); 77 PyObject *v = PyTuple_GetItem(consts, i);
80 if (!PyUnicode_Check(v)) 78 if (!PyUnicode_Check(v))
81 continue; 79 continue;
82 if (!all_name_chars(PyUnicode_AS_UNICODE(v))) 80 if (!all_name_chars(PyUnicode_AS_UNICODE(v)))
83 continue; 81 continue;
84 PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i)); 82 PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i));
85 } 83 }
86 /* Create mapping between cells and arguments if needed. */ 84 co = PyObject_NEW(PyCodeObject, &PyCode_Type);
87 if (n_cellvars) { 85 if (co != NULL) {
88 Py_ssize_t total_args = argcount + kwonlyargcount + 86 co->co_argcount = argcount;
89 ((flags & CO_VARARGS) != 0) + ((flags & CO_VARKEYWORDS) != 0); 87 co->co_kwonlyargcount = kwonlyargcount;
90 Py_ssize_t alloc_size = sizeof(unsigned char) * n_cellvars; 88 co->co_nlocals = nlocals;
91 int used_cell2arg = 0; 89 co->co_stacksize = stacksize;
92 cell2arg = PyMem_MALLOC(alloc_size); 90 co->co_flags = flags;
93 if (cell2arg == NULL) 91 Py_INCREF(code);
94 return NULL; 92 co->co_code = code;
95 memset(cell2arg, CO_CELL_NOT_AN_ARG, alloc_size); 93 Py_INCREF(consts);
96 /* Find cells which are also arguments. */ 94 co->co_consts = consts;
97 for (i = 0; i < n_cellvars; i++) { 95 Py_INCREF(names);
98 Py_ssize_t j; 96 co->co_names = names;
99 PyObject *cell = PyTuple_GET_ITEM(cellvars, i); 97 Py_INCREF(varnames);
100 for (j = 0; j < total_args; j++) { 98 co->co_varnames = varnames;
101 PyObject *arg = PyTuple_GET_ITEM(varnames, j); 99 Py_INCREF(freevars);
102 if (!PyUnicode_Compare(cell, arg)) { 100 co->co_freevars = freevars;
103 cell2arg[i] = j; 101 Py_INCREF(cellvars);
104 used_cell2arg = 1; 102 co->co_cellvars = cellvars;
105 break; 103 Py_INCREF(filename);
106 } 104 co->co_filename = filename;
107 } 105 Py_INCREF(name);
108 } 106 co->co_name = name;
109 if (!used_cell2arg) { 107 co->co_firstlineno = firstlineno;
110 PyMem_FREE(cell2arg); 108 Py_INCREF(lnotab);
111 cell2arg = NULL; 109 co->co_lnotab = lnotab;
112 } 110 co->co_zombieframe = NULL;
111 co->co_weakreflist = NULL;
113 } 112 }
114 co = PyObject_NEW(PyCodeObject, &PyCode_Type);
115 if (co == NULL) {
116 if (cell2arg)
117 PyMem_FREE(cell2arg);
118 return NULL;
119 }
120 co->co_argcount = argcount;
121 co->co_kwonlyargcount = kwonlyargcount;
122 co->co_nlocals = nlocals;
123 co->co_stacksize = stacksize;
124 co->co_flags = flags;
125 Py_INCREF(code);
126 co->co_code = code;
127 Py_INCREF(consts);
128 co->co_consts = consts;
129 Py_INCREF(names);
130 co->co_names = names;
131 Py_INCREF(varnames);
132 co->co_varnames = varnames;
133 Py_INCREF(freevars);
134 co->co_freevars = freevars;
135 Py_INCREF(cellvars);
136 co->co_cellvars = cellvars;
137 co->co_cell2arg = cell2arg;
138 Py_INCREF(filename);
139 co->co_filename = filename;
140 Py_INCREF(name);
141 co->co_name = name;
142 co->co_firstlineno = firstlineno;
143 Py_INCREF(lnotab);
144 co->co_lnotab = lnotab;
145 co->co_zombieframe = NULL;
146 co->co_weakreflist = NULL;
147 return co; 113 return co;
148 } 114 }
149 115
150 PyCodeObject * 116 PyCodeObject *
151 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) 117 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
152 { 118 {
153 static PyObject *emptystring = NULL; 119 static PyObject *emptystring = NULL;
154 static PyObject *nulltuple = NULL; 120 static PyObject *nulltuple = NULL;
155 PyObject *filename_ob = NULL; 121 PyObject *filename_ob = NULL;
156 PyObject *funcname_ob = NULL; 122 PyObject *funcname_ob = NULL;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 { 323 {
358 Py_XDECREF(co->co_code); 324 Py_XDECREF(co->co_code);
359 Py_XDECREF(co->co_consts); 325 Py_XDECREF(co->co_consts);
360 Py_XDECREF(co->co_names); 326 Py_XDECREF(co->co_names);
361 Py_XDECREF(co->co_varnames); 327 Py_XDECREF(co->co_varnames);
362 Py_XDECREF(co->co_freevars); 328 Py_XDECREF(co->co_freevars);
363 Py_XDECREF(co->co_cellvars); 329 Py_XDECREF(co->co_cellvars);
364 Py_XDECREF(co->co_filename); 330 Py_XDECREF(co->co_filename);
365 Py_XDECREF(co->co_name); 331 Py_XDECREF(co->co_name);
366 Py_XDECREF(co->co_lnotab); 332 Py_XDECREF(co->co_lnotab);
367 if (co->co_cell2arg != NULL)
368 PyMem_FREE(co->co_cell2arg);
369 if (co->co_zombieframe != NULL) 333 if (co->co_zombieframe != NULL)
370 PyObject_GC_Del(co->co_zombieframe); 334 PyObject_GC_Del(co->co_zombieframe);
371 if (co->co_weakreflist != NULL) 335 if (co->co_weakreflist != NULL)
372 PyObject_ClearWeakRefs((PyObject*)co); 336 PyObject_ClearWeakRefs((PyObject*)co);
373 PyObject_DEL(co); 337 PyObject_DEL(co);
374 } 338 }
375 339
376 static PyObject * 340 static PyObject *
377 code_repr(PyCodeObject *co) 341 code_repr(PyCodeObject *co)
378 { 342 {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 break; 548 break;
585 } 549 }
586 bounds->ap_upper = addr; 550 bounds->ap_upper = addr;
587 } 551 }
588 else { 552 else {
589 bounds->ap_upper = INT_MAX; 553 bounds->ap_upper = INT_MAX;
590 } 554 }
591 555
592 return line; 556 return line;
593 } 557 }
OLDNEW
« no previous file with comments | « Objects/bytes_methods.c ('k') | Objects/genobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+