Mercurial > cpython-lru_cache-weakref
annotate Objects/moduleobject.c @ 58689:514b56efd89a 3.1
Merged revisions 77962 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines
Merged revisions 77943,77959-77960 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines
Explicitly mention the default value for formatdate's usegmt parameter.
........
r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line
Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert
........
r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines
Add Chris Rebert to ACKS for issue 6760 Popen doc improvements.
........
................
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 04 Feb 2010 16:44:31 +0000 |
| parents | a0951f11be3d |
| children | f197407bdba2 5260104db99d |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Module object implementation */ |
| 3 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
4 #include "Python.h" |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
5 #include "structmember.h" |
| 6 | 6 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
7 static Py_ssize_t max_module_number; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
8 |
| 6 | 9 typedef struct { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
10 PyObject_HEAD |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
11 PyObject *md_dict; |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
12 struct PyModuleDef *md_def; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
13 void *md_state; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
14 } PyModuleObject; |
| 6 | 15 |
|
20595
c4d9d8674506
Add missing "static" declarations (found by "make smelly").
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
20277
diff
changeset
|
16 static PyMemberDef module_members[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
17 {"__dict__", T_OBJECT, offsetof(PyModuleObject, md_dict), READONLY}, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
18 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
19 }; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
20 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
21 static PyTypeObject moduledef_type = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
22 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
23 "moduledef", /* tp_name */ |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
24 sizeof(struct PyModuleDef), /* tp_size */ |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
25 0, /* tp_itemsize */ |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
26 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
27 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
28 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
29 PyObject * |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
33490
diff
changeset
|
30 PyModule_New(const char *name) |
| 6 | 31 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
32 PyModuleObject *m; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
33 PyObject *nameobj; |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
34 m = PyObject_GC_New(PyModuleObject, &PyModule_Type); |
| 6 | 35 if (m == NULL) |
| 36 return NULL; | |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
37 m->md_def = NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
38 m->md_state = NULL; |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41769
diff
changeset
|
39 nameobj = PyUnicode_FromString(name); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
40 m->md_dict = PyDict_New(); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
41 if (m->md_dict == NULL || nameobj == NULL) |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
42 goto fail; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
43 if (PyDict_SetItemString(m->md_dict, "__name__", nameobj) != 0) |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
44 goto fail; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
45 if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0) |
|
2081
afecdec996ff
initialize __doc__ to None
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
46 goto fail; |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
47 if (PyDict_SetItemString(m->md_dict, "__package__", Py_None) != 0) |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
48 goto fail; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
49 Py_DECREF(nameobj); |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
50 PyObject_GC_Track(m); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
51 return (PyObject *)m; |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
52 |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
53 fail: |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
54 Py_XDECREF(nameobj); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
55 Py_DECREF(m); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
56 return NULL; |
| 6 | 57 } |
| 58 | |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
59 static char api_version_warning[] = |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
60 "Python C API version mismatch for module %.100s:\ |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
61 This Python has API version %d, module %.100s has version %d."; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
62 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
63 PyObject * |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
64 PyModule_Create2(struct PyModuleDef* module, int module_api_version) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
65 { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
66 PyObject *d, *v, *n; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
67 PyMethodDef *ml; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
68 const char* name; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
69 PyModuleObject *m; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
70 if (!Py_IsInitialized()) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
71 Py_FatalError("Interpreter not initialized (version mismatch?)"); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
72 if (PyType_Ready(&moduledef_type) < 0) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
73 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
74 if (module->m_base.m_index == 0) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
75 max_module_number++; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
76 Py_REFCNT(module) = 1; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
77 Py_TYPE(module) = &moduledef_type; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
78 module->m_base.m_index = max_module_number; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
79 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
80 name = module->m_name; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
81 if (module_api_version != PYTHON_API_VERSION) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
82 char message[512]; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
83 PyOS_snprintf(message, sizeof(message), |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
84 api_version_warning, name, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
85 PYTHON_API_VERSION, name, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
86 module_api_version); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
87 if (PyErr_WarnEx(PyExc_RuntimeWarning, message, 1)) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
88 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
89 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
90 /* Make sure name is fully qualified. |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
91 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
92 This is a bit of a hack: when the shared library is loaded, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
93 the module name is "package.module", but the module calls |
|
50557
bd0e361bd642
Merged revisions 68169-68170 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49461
diff
changeset
|
94 PyModule_Create*() with just "module" for the name. The shared |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
95 library loader squirrels away the true name of the module in |
|
50557
bd0e361bd642
Merged revisions 68169-68170 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49461
diff
changeset
|
96 _Py_PackageContext, and PyModule_Create*() will substitute this |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
97 (if the name actually matches). |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
98 */ |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
99 if (_Py_PackageContext != NULL) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
100 char *p = strrchr(_Py_PackageContext, '.'); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
101 if (p != NULL && strcmp(module->m_name, p+1) == 0) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
102 name = _Py_PackageContext; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
103 _Py_PackageContext = NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
104 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
105 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
106 if ((m = (PyModuleObject*)PyModule_New(name)) == NULL) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
107 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
108 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
109 if (module->m_size > 0) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
110 m->md_state = PyMem_MALLOC(module->m_size); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
111 if (!m->md_state) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
112 PyErr_NoMemory(); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
113 Py_DECREF(m); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
114 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
115 } |
|
49461
82091df651be
Issue #3740: Null-initialize module state.
Martin v. Löwis <martin@v.loewis.de>
parents:
48660
diff
changeset
|
116 memset(m->md_state, 0, module->m_size); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
117 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
118 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
119 d = PyModule_GetDict((PyObject*)m); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
120 if (module->m_methods != NULL) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
121 n = PyUnicode_FromString(name); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
122 if (n == NULL) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
123 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
124 for (ml = module->m_methods; ml->ml_name != NULL; ml++) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
125 if ((ml->ml_flags & METH_CLASS) || |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
126 (ml->ml_flags & METH_STATIC)) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
127 PyErr_SetString(PyExc_ValueError, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
128 "module functions cannot set" |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
129 " METH_CLASS or METH_STATIC"); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
130 Py_DECREF(n); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
131 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
132 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
133 v = PyCFunction_NewEx(ml, (PyObject*)m, n); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
134 if (v == NULL) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
135 Py_DECREF(n); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
136 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
137 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
138 if (PyDict_SetItemString(d, ml->ml_name, v) != 0) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
139 Py_DECREF(v); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
140 Py_DECREF(n); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
141 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
142 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
143 Py_DECREF(v); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
144 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
145 Py_DECREF(n); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
146 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
147 if (module->m_doc != NULL) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
148 v = PyUnicode_FromString(module->m_doc); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
149 if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
150 Py_XDECREF(v); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
151 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
152 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
153 Py_DECREF(v); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
154 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
155 m->md_def = module; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
156 return (PyObject*)m; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
157 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
158 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
159 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
160 PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
161 PyModule_GetDict(PyObject *m) |
| 6 | 162 { |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
163 PyObject *d; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
164 if (!PyModule_Check(m)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
165 PyErr_BadInternalCall(); |
| 6 | 166 return NULL; |
| 167 } | |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
168 d = ((PyModuleObject *)m) -> md_dict; |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
169 if (d == NULL) |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
170 ((PyModuleObject *)m) -> md_dict = d = PyDict_New(); |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
171 return d; |
| 6 | 172 } |
| 173 | |
|
42845
3152df70517a
Get rid of more uses of string and use const in a few places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
174 const char * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
175 PyModule_GetName(PyObject *m) |
|
43
ea21982a1532
Added getmodulename() public interface.
Guido van Rossum <guido@python.org>
parents:
25
diff
changeset
|
176 { |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
177 PyObject *d; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
178 PyObject *nameobj; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
179 if (!PyModule_Check(m)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
180 PyErr_BadArgument(); |
|
43
ea21982a1532
Added getmodulename() public interface.
Guido van Rossum <guido@python.org>
parents:
25
diff
changeset
|
181 return NULL; |
|
ea21982a1532
Added getmodulename() public interface.
Guido van Rossum <guido@python.org>
parents:
25
diff
changeset
|
182 } |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
183 d = ((PyModuleObject *)m)->md_dict; |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
184 if (d == NULL || |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
185 (nameobj = PyDict_GetItemString(d, "__name__")) == NULL || |
|
42855
d5b52d56beba
Use unicode and remove support for some uses of str8.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42845
diff
changeset
|
186 !PyUnicode_Check(nameobj)) |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
187 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
188 PyErr_SetString(PyExc_SystemError, "nameless module"); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
189 return NULL; |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
190 } |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
47580
diff
changeset
|
191 return _PyUnicode_AsString(nameobj); |
|
43
ea21982a1532
Added getmodulename() public interface.
Guido van Rossum <guido@python.org>
parents:
25
diff
changeset
|
192 } |
|
ea21982a1532
Added getmodulename() public interface.
Guido van Rossum <guido@python.org>
parents:
25
diff
changeset
|
193 |
|
42845
3152df70517a
Get rid of more uses of string and use const in a few places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
194 const char * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
195 PyModule_GetFilename(PyObject *m) |
|
10161
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
196 { |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
197 PyObject *d; |
|
10161
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
198 PyObject *fileobj; |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
199 if (!PyModule_Check(m)) { |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
200 PyErr_BadArgument(); |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
201 return NULL; |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
202 } |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
203 d = ((PyModuleObject *)m)->md_dict; |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
204 if (d == NULL || |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
205 (fileobj = PyDict_GetItemString(d, "__file__")) == NULL || |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42855
diff
changeset
|
206 !PyUnicode_Check(fileobj)) |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
207 { |
|
10161
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
208 PyErr_SetString(PyExc_SystemError, "module filename missing"); |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
209 return NULL; |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
210 } |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
47580
diff
changeset
|
211 return _PyUnicode_AsString(fileobj); |
|
10161
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
212 } |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
213 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
214 PyModuleDef* |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
215 PyModule_GetDef(PyObject* m) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
216 { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
217 if (!PyModule_Check(m)) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
218 PyErr_BadArgument(); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
219 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
220 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
221 return ((PyModuleObject *)m)->md_def; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
222 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
223 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
224 void* |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
225 PyModule_GetState(PyObject* m) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
226 { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
227 if (!PyModule_Check(m)) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
228 PyErr_BadArgument(); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
229 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
230 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
231 return ((PyModuleObject *)m)->md_state; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
232 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
233 |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
234 void |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
235 _PyModule_Clear(PyObject *m) |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
236 { |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
237 /* To make the execution order of destructors for global |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
238 objects a bit more predictable, we first zap all objects |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
239 whose name starts with a single underscore, before we clear |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
240 the entire dictionary. We zap them by replacing them with |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
241 None, rather than deleting them from the dictionary, to |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
242 avoid rehashing the dictionary (to some extent). */ |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
243 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
244 Py_ssize_t pos; |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
245 PyObject *key, *value; |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
246 PyObject *d; |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
247 |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
248 d = ((PyModuleObject *)m)->md_dict; |
|
22300
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
249 if (d == NULL) |
|
54bcc5ec3a51
backport gvanrossum's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20595
diff
changeset
|
250 return; |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
251 |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
252 /* First, clear only names starting with a single underscore */ |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
253 pos = 0; |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
254 while (PyDict_Next(d, &pos, &key, &value)) { |
|
42845
3152df70517a
Get rid of more uses of string and use const in a few places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
255 if (value != Py_None && PyUnicode_Check(key)) { |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
47580
diff
changeset
|
256 const char *s = _PyUnicode_AsString(key); |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
257 if (s[0] == '_' && s[1] != '_') { |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
258 if (Py_VerboseFlag > 1) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
7401
diff
changeset
|
259 PySys_WriteStderr("# clear[1] %s\n", s); |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
260 PyDict_SetItem(d, key, Py_None); |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
261 } |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
262 } |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
263 } |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
264 |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
265 /* Next, clear all names except for __builtins__ */ |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
266 pos = 0; |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
267 while (PyDict_Next(d, &pos, &key, &value)) { |
|
42845
3152df70517a
Get rid of more uses of string and use const in a few places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
268 if (value != Py_None && PyUnicode_Check(key)) { |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
47580
diff
changeset
|
269 const char *s = _PyUnicode_AsString(key); |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
270 if (s[0] != '_' || strcmp(s, "__builtins__") != 0) { |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
271 if (Py_VerboseFlag > 1) |
|
9329
7f242f29a45f
Replace fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
7401
diff
changeset
|
272 PySys_WriteStderr("# clear[2] %s\n", s); |
|
7401
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
273 PyDict_SetItem(d, key, Py_None); |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
274 } |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
275 } |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
276 } |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
277 |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
278 /* Note: we leave __builtins__ in place, so that destructors |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
279 of non-global objects defined in this module can still use |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
280 builtins, in particularly 'None'. */ |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
281 |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
282 } |
|
8c01cfee14ba
Add internal routine _PyModule_Clear(), which does approximately what
Guido van Rossum <guido@python.org>
parents:
5456
diff
changeset
|
283 |
| 6 | 284 /* Methods */ |
| 285 | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
286 static int |
|
23652
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
287 module_init(PyModuleObject *m, PyObject *args, PyObject *kwds) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
288 { |
|
36675
dba6494735d0
Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
289 static char *kwlist[] = {"name", "doc", NULL}; |
|
23652
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
290 PyObject *dict, *name = Py_None, *doc = Py_None; |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
291 if (!PyArg_ParseTupleAndKeywords(args, kwds, "U|O:module.__init__", |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
33490
diff
changeset
|
292 kwlist, &name, &doc)) |
|
23652
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
293 return -1; |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
294 dict = m->md_dict; |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
295 if (dict == NULL) { |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
296 dict = PyDict_New(); |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
297 if (dict == NULL) |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
298 return -1; |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
299 m->md_dict = dict; |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
300 } |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
301 if (PyDict_SetItemString(dict, "__name__", name) < 0) |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
302 return -1; |
|
b40165a4efe9
Surprising fix for SF bug 563060: module can be used as base class.
Guido van Rossum <guido@python.org>
parents:
22975
diff
changeset
|
303 if (PyDict_SetItemString(dict, "__doc__", doc) < 0) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
304 return -1; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
305 return 0; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
306 } |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
307 |
| 6 | 308 static void |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
309 module_dealloc(PyModuleObject *m) |
| 6 | 310 { |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
311 PyObject_GC_UnTrack(m); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
312 if (m->md_def && m->md_def->m_free) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
313 m->md_def->m_free(m); |
|
2238
b5dcba7b732d
apply dictclear to dict of deleted modules
Guido van Rossum <guido@python.org>
parents:
2081
diff
changeset
|
314 if (m->md_dict != NULL) { |
|
57210
a0951f11be3d
Merged revisions 76235 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
315 /* If we are the only ones holding a reference, we can clear |
|
a0951f11be3d
Merged revisions 76235 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
316 the dictionary. */ |
|
a0951f11be3d
Merged revisions 76235 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
317 if (Py_REFCNT(m->md_dict) == 1) |
|
a0951f11be3d
Merged revisions 76235 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
318 _PyModule_Clear((PyObject *)m); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
319 Py_DECREF(m->md_dict); |
|
2238
b5dcba7b732d
apply dictclear to dict of deleted modules
Guido van Rossum <guido@python.org>
parents:
2081
diff
changeset
|
320 } |
|
50832
43e0b1ee1c1b
Merged revisions 68669 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
321 if (m->md_state != NULL) |
|
43e0b1ee1c1b
Merged revisions 68669 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
322 PyMem_FREE(m->md_state); |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44129
diff
changeset
|
323 Py_TYPE(m)->tp_free((PyObject *)m); |
| 6 | 324 } |
| 325 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
326 static PyObject * |
|
13457
ef2ebb3b0c64
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
327 module_repr(PyModuleObject *m) |
| 6 | 328 { |
|
42845
3152df70517a
Get rid of more uses of string and use const in a few places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
329 const char *name; |
|
3152df70517a
Get rid of more uses of string and use const in a few places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
330 const char *filename; |
|
19322
1fec03012346
module_repr(): Instead of fixing the maximum buf size to 400,
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
331 |
|
10161
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
332 name = PyModule_GetName((PyObject *)m); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
333 if (name == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
334 PyErr_Clear(); |
|
1410
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
335 name = "?"; |
|
315272ec4d5b
* import.c (get_module): total rewrite, to ensure proper search order: for
Guido van Rossum <guido@python.org>
parents:
1293
diff
changeset
|
336 } |
|
10161
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
337 filename = PyModule_GetFilename((PyObject *)m); |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
338 if (filename == NULL) { |
|
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
339 PyErr_Clear(); |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41723
diff
changeset
|
340 return PyUnicode_FromFormat("<module '%s' (built-in)>", name); |
|
10161
5c1ebf23f1d7
Patch by Chris Petrilli to display the origin of a module in its
Guido van Rossum <guido@python.org>
parents:
9329
diff
changeset
|
341 } |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
41723
diff
changeset
|
342 return PyUnicode_FromFormat("<module '%s' from '%s'>", name, filename); |
| 6 | 343 } |
| 344 | |
|
15686
986d1c3ccdde
Add garbage collection for module objects. Closes patch #102939 and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
345 static int |
|
986d1c3ccdde
Add garbage collection for module objects. Closes patch #102939 and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
346 module_traverse(PyModuleObject *m, visitproc visit, void *arg) |
|
986d1c3ccdde
Add garbage collection for module objects. Closes patch #102939 and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
347 { |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
348 if (m->md_def && m->md_def->m_traverse) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
349 int res = m->md_def->m_traverse((PyObject*)m, visit, arg); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
350 if (res) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
351 return res; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
352 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
353 Py_VISIT(m->md_dict); |
|
15686
986d1c3ccdde
Add garbage collection for module objects. Closes patch #102939 and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
354 return 0; |
|
986d1c3ccdde
Add garbage collection for module objects. Closes patch #102939 and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
355 } |
|
986d1c3ccdde
Add garbage collection for module objects. Closes patch #102939 and
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15318
diff
changeset
|
356 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
357 static int |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
358 module_clear(PyModuleObject *m) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
359 { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
360 if (m->md_def && m->md_def->m_clear) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
361 int res = m->md_def->m_clear((PyObject*)m); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
362 if (res) |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
363 return res; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
364 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
365 Py_CLEAR(m->md_dict); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
366 return 0; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
367 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
368 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
369 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23654
diff
changeset
|
370 PyDoc_STRVAR(module_doc, |
|
23654
b86eaeb0d7dd
Add a docstring to the module type.
Guido van Rossum <guido@python.org>
parents:
23652
diff
changeset
|
371 "module(name[, doc])\n\ |
|
b86eaeb0d7dd
Add a docstring to the module type.
Guido van Rossum <guido@python.org>
parents:
23652
diff
changeset
|
372 \n\ |
|
b86eaeb0d7dd
Add a docstring to the module type.
Guido van Rossum <guido@python.org>
parents:
23652
diff
changeset
|
373 Create a module object.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23654
diff
changeset
|
374 The name must be a string; the optional doc argument can have any type."); |
|
23654
b86eaeb0d7dd
Add a docstring to the module type.
Guido van Rossum <guido@python.org>
parents:
23652
diff
changeset
|
375 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
376 PyTypeObject PyModule_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
42013
diff
changeset
|
377 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
17807
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
378 "module", /* tp_name */ |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
379 sizeof(PyModuleObject), /* tp_size */ |
|
17807
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
380 0, /* tp_itemsize */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
381 (destructor)module_dealloc, /* tp_dealloc */ |
|
17807
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
382 0, /* tp_print */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
383 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
384 0, /* tp_setattr */ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50832
diff
changeset
|
385 0, /* tp_reserved */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
386 (reprfunc)module_repr, /* tp_repr */ |
|
17807
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
387 0, /* tp_as_number */ |
|
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
388 0, /* tp_as_sequence */ |
|
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
389 0, /* tp_as_mapping */ |
|
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
390 0, /* tp_hash */ |
|
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
391 0, /* tp_call */ |
|
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
392 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
393 PyObject_GenericGetAttr, /* tp_getattro */ |
|
29910
0e2215b8226d
Remove code that tried to warn about shadowing builtin names after a
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
29397
diff
changeset
|
394 PyObject_GenericSetAttr, /* tp_setattro */ |
|
17807
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
395 0, /* tp_as_buffer */ |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
396 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
397 Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
23654
b86eaeb0d7dd
Add a docstring to the module type.
Guido van Rossum <guido@python.org>
parents:
23652
diff
changeset
|
398 module_doc, /* tp_doc */ |
|
17807
1579d309676e
Variant of patch #423262: Change module attribute get & set
Tim Peters <tim.peters@gmail.com>
parents:
15686
diff
changeset
|
399 (traverseproc)module_traverse, /* tp_traverse */ |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
400 (inquiry)module_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
401 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
402 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
403 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
404 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
405 0, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
406 module_members, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
407 0, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
408 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
409 0, /* tp_dict */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
410 0, /* tp_descr_get */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
411 0, /* tp_descr_set */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
412 offsetof(PyModuleObject, md_dict), /* tp_dictoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
413 (initproc)module_init, /* tp_init */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
414 PyType_GenericAlloc, /* tp_alloc */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17811
diff
changeset
|
415 PyType_GenericNew, /* tp_new */ |
|
22975
29e6cb832497
PyObject_GC_Del can now be used as a function designator.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22300
diff
changeset
|
416 PyObject_GC_Del, /* tp_free */ |
| 6 | 417 }; |
