Mercurial > cpython-lru_cache-weakref
annotate Objects/funcobject.c @ 1330:409ea74feb21 legacy-trunk
Minor fixes / changes for Mac compatibility.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 29 Jul 1993 08:25:09 +0000 |
| parents | 9fed5726a36d |
| children | cc172ce05561 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
3 Amsterdam, The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* Function object implementation */ |
| 26 | |
| 86 | 27 #include "allobjects.h" |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
28 #include "compile.h" |
| 86 | 29 #include "structmember.h" |
| 6 | 30 |
| 31 object * | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
32 newfuncobject(code, globals) |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
33 object *code; |
| 6 | 34 object *globals; |
| 35 { | |
| 36 funcobject *op = NEWOBJ(funcobject, &Functype); | |
| 37 if (op != NULL) { | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
38 INCREF(code); |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
39 op->func_code = code; |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
40 INCREF(globals); |
| 6 | 41 op->func_globals = globals; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
42 op->func_name = ((codeobject*)(op->func_code))->co_name; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
43 INCREF(op->func_name); |
| 6 | 44 } |
| 45 return (object *)op; | |
| 46 } | |
| 47 | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
48 object * |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
49 getfunccode(op) |
| 6 | 50 object *op; |
| 51 { | |
| 52 if (!is_funcobject(op)) { | |
| 27 | 53 err_badcall(); |
| 6 | 54 return NULL; |
| 55 } | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
56 return ((funcobject *) op) -> func_code; |
| 6 | 57 } |
| 58 | |
| 59 object * | |
| 60 getfuncglobals(op) | |
| 61 object *op; | |
| 62 { | |
| 63 if (!is_funcobject(op)) { | |
| 27 | 64 err_badcall(); |
| 6 | 65 return NULL; |
| 66 } | |
| 67 return ((funcobject *) op) -> func_globals; | |
| 68 } | |
| 69 | |
| 70 /* Methods */ | |
| 71 | |
| 86 | 72 #define OFF(x) offsetof(funcobject, x) |
| 73 | |
| 74 static struct memberlist func_memberlist[] = { | |
|
588
7d24de643fb5
Added READONLY specifier to data members.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
75 {"func_code", T_OBJECT, OFF(func_code), READONLY}, |
|
7d24de643fb5
Added READONLY specifier to data members.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
76 {"func_globals",T_OBJECT, OFF(func_globals), READONLY}, |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
77 {"func_name", T_OBJECT, OFF(func_name), READONLY}, |
| 86 | 78 {NULL} /* Sentinel */ |
| 79 }; | |
| 80 | |
| 81 static object * | |
| 82 func_getattr(op, name) | |
| 83 funcobject *op; | |
| 84 char *name; | |
| 85 { | |
| 86 return getmember((char *)op, func_memberlist, name); | |
| 87 } | |
| 88 | |
| 6 | 89 static void |
| 86 | 90 func_dealloc(op) |
| 6 | 91 funcobject *op; |
| 92 { | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
93 DECREF(op->func_code); |
| 6 | 94 DECREF(op->func_globals); |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
95 DEL(op); |
| 6 | 96 } |
| 97 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
98 static object* |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
99 func_repr(op) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
100 funcobject *op; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
101 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
102 char buf[140]; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
103 sprintf(buf, "<function %.100s at %lx>", |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
104 getstringvalue(op->func_name), |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
105 (long)op); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
106 return newstringobject(buf); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
107 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
108 |
| 6 | 109 typeobject Functype = { |
| 110 OB_HEAD_INIT(&Typetype) | |
| 111 0, | |
| 112 "function", | |
| 113 sizeof(funcobject), | |
| 114 0, | |
| 86 | 115 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
|
116 0, /*tp_print*/ |
| 86 | 117 func_getattr, /*tp_getattr*/ |
| 6 | 118 0, /*tp_setattr*/ |
| 119 0, /*tp_compare*/ | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
120 func_repr, /*tp_repr*/ |
| 6 | 121 }; |
