Mercurial > cpython-lru_cache-weakref
annotate Objects/funcobject.c @ 16413:8819867f14ef legacy-trunk
Patch derived from Trent's 101162: a Python/C API testing framework.
STILL NEEDS UNIX BUILD CHANGES.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Fri, 02 Feb 2001 05:57:15 +0000 |
| parents | abd383f1905c |
| children | 51cf451faae4 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Function object implementation */ |
| 3 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
4 #include "Python.h" |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
5 #include "compile.h" |
| 86 | 6 #include "structmember.h" |
| 6 | 7 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
8 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13265
diff
changeset
|
9 PyFunction_New(PyObject *code, PyObject *globals) |
| 6 | 10 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
11 PyFunctionObject *op = PyObject_NEW(PyFunctionObject, |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
12 &PyFunction_Type); |
| 6 | 13 if (op != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
14 PyObject *doc; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
15 PyObject *consts; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
16 Py_INCREF(code); |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
17 op->func_code = code; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
18 Py_INCREF(globals); |
| 6 | 19 op->func_globals = globals; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
20 op->func_name = ((PyCodeObject *)code)->co_name; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
21 Py_INCREF(op->func_name); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
22 op->func_defaults = NULL; /* No default arguments */ |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
23 op->func_closure = NULL; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
24 consts = ((PyCodeObject *)code)->co_consts; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
25 if (PyTuple_Size(consts) >= 1) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
26 doc = PyTuple_GetItem(consts, 0); |
| 12512 | 27 if (!PyString_Check(doc) && !PyUnicode_Check(doc)) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
28 doc = Py_None; |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
29 } |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
30 else |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
31 doc = Py_None; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
32 Py_INCREF(doc); |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
33 op->func_doc = doc; |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
34 op->func_dict = NULL; |
| 6 | 35 } |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
36 else |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
37 return NULL; |
|
13183
54bffdddc0ef
final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13141
diff
changeset
|
38 PyObject_GC_Init(op); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
39 return (PyObject *)op; |
| 6 | 40 } |
| 41 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
42 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13265
diff
changeset
|
43 PyFunction_GetCode(PyObject *op) |
| 6 | 44 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
45 if (!PyFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
46 PyErr_BadInternalCall(); |
| 6 | 47 return NULL; |
| 48 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
49 return ((PyFunctionObject *) op) -> func_code; |
| 6 | 50 } |
| 51 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
52 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13265
diff
changeset
|
53 PyFunction_GetGlobals(PyObject *op) |
| 6 | 54 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
55 if (!PyFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
56 PyErr_BadInternalCall(); |
| 6 | 57 return NULL; |
| 58 } | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
59 return ((PyFunctionObject *) op) -> func_globals; |
| 6 | 60 } |
| 61 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
62 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13265
diff
changeset
|
63 PyFunction_GetDefaults(PyObject *op) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
64 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
65 if (!PyFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
66 PyErr_BadInternalCall(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
67 return NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
68 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
69 return ((PyFunctionObject *) op) -> func_defaults; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
70 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
71 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
72 int |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13265
diff
changeset
|
73 PyFunction_SetDefaults(PyObject *op, PyObject *defaults) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
74 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
75 if (!PyFunction_Check(op)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
76 PyErr_BadInternalCall(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
77 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
78 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
79 if (defaults == Py_None) |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
80 defaults = NULL; |
|
7981
09963a2a24db
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5945
diff
changeset
|
81 else if (PyTuple_Check(defaults)) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
82 Py_XINCREF(defaults); |
|
7981
09963a2a24db
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5945
diff
changeset
|
83 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
84 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
85 PyErr_SetString(PyExc_SystemError, "non-tuple default args"); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
86 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
87 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
88 Py_XDECREF(((PyFunctionObject *) op) -> func_defaults); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
89 ((PyFunctionObject *) op) -> func_defaults = defaults; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
90 return 0; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
91 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
92 |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
93 PyObject * |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
94 PyFunction_GetClosure(PyObject *op) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
95 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
96 if (!PyFunction_Check(op)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
97 PyErr_BadInternalCall(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
98 return NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
99 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
100 return ((PyFunctionObject *) op) -> func_closure; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
101 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
102 |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
103 int |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
104 PyFunction_SetClosure(PyObject *op, PyObject *closure) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
105 { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
106 if (!PyFunction_Check(op)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
107 PyErr_BadInternalCall(); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
108 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
109 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
110 if (closure == Py_None) |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
111 closure = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
112 else if (PyTuple_Check(closure)) { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
113 Py_XINCREF(closure); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
114 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
115 else { |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
116 PyErr_SetString(PyExc_SystemError, "non-tuple closure"); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
117 return -1; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
118 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
119 Py_XDECREF(((PyFunctionObject *) op) -> func_closure); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
120 ((PyFunctionObject *) op) -> func_closure = closure; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
121 return 0; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
122 } |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
123 |
| 6 | 124 /* Methods */ |
| 125 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
126 #define OFF(x) offsetof(PyFunctionObject, x) |
| 86 | 127 |
| 128 static struct memberlist func_memberlist[] = { | |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
129 {"func_code", T_OBJECT, OFF(func_code)}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
130 {"func_globals", T_OBJECT, OFF(func_globals), READONLY}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
131 {"func_name", T_OBJECT, OFF(func_name), READONLY}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
132 {"__name__", T_OBJECT, OFF(func_name), READONLY}, |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16042
diff
changeset
|
133 {"func_closure", T_OBJECT, OFF(func_closure)}, |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
134 {"func_defaults", T_OBJECT, OFF(func_defaults)}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
135 {"func_doc", T_OBJECT, OFF(func_doc)}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
136 {"__doc__", T_OBJECT, OFF(func_doc)}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
137 {"func_dict", T_OBJECT, OFF(func_dict)}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
138 {"__dict__", T_OBJECT, OFF(func_dict)}, |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
139 {NULL} /* Sentinel */ |
| 86 | 140 }; |
| 141 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
142 static PyObject * |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
143 func_getattro(PyFunctionObject *op, PyObject *name) |
| 86 | 144 { |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
145 PyObject *rtn; |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
146 char *sname = PyString_AsString(name); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
147 |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
148 if (sname[0] != '_' && PyEval_GetRestricted()) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
149 PyErr_SetString(PyExc_RuntimeError, |
|
2105
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
150 "function attributes not accessible in restricted mode"); |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
151 return NULL; |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
152 } |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
153 |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
154 /* no API for PyMember_HasAttr() */ |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
155 rtn = PyMember_Get((char *)op, func_memberlist, sname); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
156 |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
157 if (rtn == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
158 PyErr_Clear(); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
159 if (op->func_dict != NULL) { |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
160 rtn = PyDict_GetItem(op->func_dict, name); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
161 Py_XINCREF(rtn); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
162 } |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
163 if (rtn == NULL) |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
164 PyErr_SetObject(PyExc_AttributeError, name); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
165 } |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
166 return rtn; |
| 86 | 167 } |
| 168 | |
|
8407
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
169 static int |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
170 func_setattro(PyFunctionObject *op, PyObject *name, PyObject *value) |
|
8407
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
171 { |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
172 int rtn; |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
173 char *sname = PyString_AsString(name); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
174 |
|
8407
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
175 if (PyEval_GetRestricted()) { |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
176 PyErr_SetString(PyExc_RuntimeError, |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
177 "function attributes not settable in restricted mode"); |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
178 return -1; |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
179 } |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
180 if (strcmp(sname, "func_code") == 0) { |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
181 /* not legal to del f.func_code or to set it to anything |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
182 * other than a code object. |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
183 */ |
|
8407
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
184 if (value == NULL || !PyCode_Check(value)) { |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
185 PyErr_SetString( |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
186 PyExc_TypeError, |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
187 "func_code must be set to a code object"); |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
188 return -1; |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
189 } |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
190 } |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
191 else if (strcmp(sname, "func_defaults") == 0) { |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
192 /* legal to del f.func_defaults. Can only set |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
193 * func_defaults to NULL or a tuple. |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
194 */ |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
195 if (value == Py_None) |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
196 value = NULL; |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
197 if (value != NULL && !PyTuple_Check(value)) { |
|
8407
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
198 PyErr_SetString( |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
199 PyExc_TypeError, |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
200 "func_defaults must be set to a tuple object"); |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
201 return -1; |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
202 } |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
203 } |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
204 else if (!strcmp(sname, "func_dict") || !strcmp(sname, "__dict__")) { |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
205 /* legal to del f.func_dict. Can only set func_dict to |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
206 * NULL or a dictionary. |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
207 */ |
|
8407
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
208 if (value == Py_None) |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
209 value = NULL; |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
210 if (value != NULL && !PyDict_Check(value)) { |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
211 PyErr_SetString( |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
212 PyExc_TypeError, |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
213 "func_dict must be set to a dict object"); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
214 return -1; |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
215 } |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
216 } |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
217 |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
218 rtn = PyMember_Set((char *)op, func_memberlist, sname, value); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
219 if (rtn < 0 && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
220 PyErr_Clear(); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
221 if (op->func_dict == NULL) { |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
222 /* don't create the dict if we're deleting an |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
223 * attribute. In that case, we know we'll get an |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
224 * AttributeError. |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
225 */ |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
226 if (value == NULL) { |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
227 PyErr_SetString(PyExc_AttributeError, sname); |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
228 return -1; |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
229 } |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
230 op->func_dict = PyDict_New(); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
231 if (op->func_dict == NULL) |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
232 return -1; |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
233 } |
|
16042
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
234 if (value == NULL) |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
235 rtn = PyDict_DelItem(op->func_dict, name); |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
236 else |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
237 rtn = PyDict_SetItem(op->func_dict, name, value); |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
238 /* transform KeyError into AttributeError */ |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
239 if (rtn < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) |
|
78bd97d8413c
Application and elaboration of patch #103305 to fix core dumps when
Barry Warsaw <barry@python.org>
parents:
15894
diff
changeset
|
240 PyErr_SetString(PyExc_AttributeError, sname); |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
241 } |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
242 return rtn; |
|
8407
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
243 } |
|
096857b0e4b8
Make function objects somewhat mutable -- the members func_code,
Guido van Rossum <guido@python.org>
parents:
7981
diff
changeset
|
244 |
| 6 | 245 static void |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13265
diff
changeset
|
246 func_dealloc(PyFunctionObject *op) |
| 6 | 247 { |
|
13183
54bffdddc0ef
final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13141
diff
changeset
|
248 PyObject_GC_Fini(op); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
249 Py_DECREF(op->func_code); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
250 Py_DECREF(op->func_globals); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
251 Py_DECREF(op->func_name); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
252 Py_XDECREF(op->func_defaults); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
253 Py_XDECREF(op->func_doc); |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
254 Py_XDECREF(op->func_dict); |
|
13265
e8bb0d536633
Neil Schemenauer: small fixes for GC
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
255 op = (PyFunctionObject *) PyObject_AS_GC(op); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12512
diff
changeset
|
256 PyObject_DEL(op); |
| 6 | 257 } |
| 258 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
259 static PyObject* |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13265
diff
changeset
|
260 func_repr(PyFunctionObject *op) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
261 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
262 char buf[140]; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
263 if (op->func_name == Py_None) |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13183
diff
changeset
|
264 sprintf(buf, "<anonymous function at %p>", op); |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1399
diff
changeset
|
265 else |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13183
diff
changeset
|
266 sprintf(buf, "<function %.100s at %p>", |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
267 PyString_AsString(op->func_name), |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13183
diff
changeset
|
268 op); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
269 return PyString_FromString(buf); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
270 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
271 |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
272 static int |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
273 func_traverse(PyFunctionObject *f, visitproc visit, void *arg) |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
274 { |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
275 int err; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
276 if (f->func_code) { |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
277 err = visit(f->func_code, arg); |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
278 if (err) |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
279 return err; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
280 } |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
281 if (f->func_globals) { |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
282 err = visit(f->func_globals, arg); |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
283 if (err) |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
284 return err; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
285 } |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
286 if (f->func_defaults) { |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
287 err = visit(f->func_defaults, arg); |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
288 if (err) |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
289 return err; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
290 } |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
291 if (f->func_doc) { |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
292 err = visit(f->func_doc, arg); |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
293 if (err) |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
294 return err; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
295 } |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
296 if (f->func_name) { |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
297 err = visit(f->func_name, arg); |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
298 if (err) |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
299 return err; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
300 } |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
301 if (f->func_dict) { |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
302 err = visit(f->func_dict, arg); |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
303 if (err) |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
304 return err; |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
305 } |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
306 return 0; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
307 } |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
308 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
309 PyTypeObject PyFunction_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
310 PyObject_HEAD_INIT(&PyType_Type) |
| 6 | 311 0, |
| 312 "function", | |
|
13183
54bffdddc0ef
final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13141
diff
changeset
|
313 sizeof(PyFunctionObject) + PyGC_HEAD_SIZE, |
| 6 | 314 0, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
315 (destructor)func_dealloc, /*tp_dealloc*/ |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
316 0, /*tp_print*/ |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
317 0, /*tp_getattr*/ |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
318 0, /*tp_setattr*/ |
|
16328
abd383f1905c
The one thing I love more then writing code is deleting code.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
16257
diff
changeset
|
319 0, /*tp_compare*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
320 (reprfunc)func_repr, /*tp_repr*/ |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
321 0, /*tp_as_number*/ |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
322 0, /*tp_as_sequence*/ |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
323 0, /*tp_as_mapping*/ |
|
16328
abd383f1905c
The one thing I love more then writing code is deleting code.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
16257
diff
changeset
|
324 0, /*tp_hash*/ |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
325 0, /*tp_call*/ |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
326 0, /*tp_str*/ |
|
15894
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
327 (getattrofunc)func_getattro, /*tp_getattro*/ |
|
1c6b0d3a58ea
Committing PEP 232, function attribute feature, approved by Guido.
Barry Warsaw <barry@python.org>
parents:
14375
diff
changeset
|
328 (setattrofunc)func_setattro, /*tp_setattro*/ |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
329 0, /* tp_as_buffer */ |
|
12993
8f79c5b69e0a
part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12990
diff
changeset
|
330 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/ |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
331 0, /* tp_doc */ |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
332 (traverseproc)func_traverse, /* tp_traverse */ |
| 6 | 333 }; |
