blob: 3817ef314e6e74f6ecbdb2879a0a16fc05437089 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* Module object implementation */
3
Guido van Rossumc0b618a1997-05-02 03:12:38 +00004#include "Python.h"
Tim Peters6d6c1a32001-08-02 04:15:00 +00005#include "structmember.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00006
Martin v. Löwis1a214512008-06-11 05:26:20 +00007static Py_ssize_t max_module_number;
8
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00009typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000010 PyObject_HEAD
11 PyObject *md_dict;
12 struct PyModuleDef *md_def;
13 void *md_state;
Guido van Rossumc0b618a1997-05-02 03:12:38 +000014} PyModuleObject;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000015
Neil Schemenauerf23473f2001-10-21 22:28:58 +000016static PyMemberDef module_members[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000017 {"__dict__", T_OBJECT, offsetof(PyModuleObject, md_dict), READONLY},
18 {0}
Tim Peters6d6c1a32001-08-02 04:15:00 +000019};
20
Martin v. Löwis1a214512008-06-11 05:26:20 +000021static PyTypeObject moduledef_type = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000022 PyVarObject_HEAD_INIT(&PyType_Type, 0)
23 "moduledef", /* tp_name */
24 sizeof(struct PyModuleDef), /* tp_size */
25 0, /* tp_itemsize */
Martin v. Löwis1a214512008-06-11 05:26:20 +000026};
27
28
Guido van Rossumc0b618a1997-05-02 03:12:38 +000029PyObject *
Victor Stinner0639b562011-03-04 12:57:07 +000030PyModule_NewObject(PyObject *name)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000031{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000032 PyModuleObject *m;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000033 m = PyObject_GC_New(PyModuleObject, &PyModule_Type);
34 if (m == NULL)
35 return NULL;
36 m->md_def = NULL;
37 m->md_state = NULL;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000038 m->md_dict = PyDict_New();
Victor Stinner0639b562011-03-04 12:57:07 +000039 if (m->md_dict == NULL)
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000040 goto fail;
Victor Stinner0639b562011-03-04 12:57:07 +000041 if (PyDict_SetItemString(m->md_dict, "__name__", name) != 0)
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000042 goto fail;
43 if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0)
44 goto fail;
45 if (PyDict_SetItemString(m->md_dict, "__package__", Py_None) != 0)
46 goto fail;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000047 PyObject_GC_Track(m);
48 return (PyObject *)m;
Guido van Rossumc45611d1993-11-17 22:58:56 +000049
50 fail:
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000051 Py_DECREF(m);
52 return NULL;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000053}
54
Martin v. Löwis1a214512008-06-11 05:26:20 +000055PyObject *
Victor Stinner0639b562011-03-04 12:57:07 +000056PyModule_New(const char *name)
57{
58 PyObject *nameobj, *module;
59 nameobj = PyUnicode_FromString(name);
60 if (nameobj == NULL)
61 return NULL;
62 module = PyModule_NewObject(nameobj);
63 Py_DECREF(nameobj);
64 return module;
65}
66
67
68PyObject *
Martin v. Löwis1a214512008-06-11 05:26:20 +000069PyModule_Create2(struct PyModuleDef* module, int module_api_version)
70{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000071 PyObject *d, *v, *n;
72 PyMethodDef *ml;
73 const char* name;
74 PyModuleObject *m;
R. David Murrayce4b1702010-12-14 23:06:25 +000075 PyInterpreterState *interp = PyThreadState_Get()->interp;
76 if (interp->modules == NULL)
77 Py_FatalError("Python import machinery not initialized");
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000078 if (PyType_Ready(&moduledef_type) < 0)
79 return NULL;
80 if (module->m_base.m_index == 0) {
81 max_module_number++;
82 Py_REFCNT(module) = 1;
83 Py_TYPE(module) = &moduledef_type;
84 module->m_base.m_index = max_module_number;
85 }
86 name = module->m_name;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000087 if (module_api_version != PYTHON_API_VERSION && module_api_version != PYTHON_ABI_VERSION) {
Victor Stinner4a2b7a12010-08-13 14:03:48 +000088 int err;
89 err = PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
90 "Python C API version mismatch for module %.100s: "
91 "This Python has API version %d, module %.100s has version %d.",
92 name,
93 PYTHON_API_VERSION, name, module_api_version);
94 if (err)
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000095 return NULL;
96 }
97 /* Make sure name is fully qualified.
Martin v. Löwis1a214512008-06-11 05:26:20 +000098
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000099 This is a bit of a hack: when the shared library is loaded,
100 the module name is "package.module", but the module calls
101 PyModule_Create*() with just "module" for the name. The shared
102 library loader squirrels away the true name of the module in
103 _Py_PackageContext, and PyModule_Create*() will substitute this
104 (if the name actually matches).
105 */
106 if (_Py_PackageContext != NULL) {
107 char *p = strrchr(_Py_PackageContext, '.');
108 if (p != NULL && strcmp(module->m_name, p+1) == 0) {
109 name = _Py_PackageContext;
110 _Py_PackageContext = NULL;
111 }
112 }
113 if ((m = (PyModuleObject*)PyModule_New(name)) == NULL)
114 return NULL;
Martin v. Löwis1a214512008-06-11 05:26:20 +0000115
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000116 if (module->m_size > 0) {
117 m->md_state = PyMem_MALLOC(module->m_size);
118 if (!m->md_state) {
119 PyErr_NoMemory();
120 Py_DECREF(m);
121 return NULL;
122 }
123 memset(m->md_state, 0, module->m_size);
124 }
125
126 d = PyModule_GetDict((PyObject*)m);
127 if (module->m_methods != NULL) {
128 n = PyUnicode_FromString(name);
129 if (n == NULL)
130 return NULL;
131 for (ml = module->m_methods; ml->ml_name != NULL; ml++) {
132 if ((ml->ml_flags & METH_CLASS) ||
133 (ml->ml_flags & METH_STATIC)) {
134 PyErr_SetString(PyExc_ValueError,
135 "module functions cannot set"
136 " METH_CLASS or METH_STATIC");
137 Py_DECREF(n);
138 return NULL;
139 }
140 v = PyCFunction_NewEx(ml, (PyObject*)m, n);
141 if (v == NULL) {
142 Py_DECREF(n);
143 return NULL;
144 }
145 if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
146 Py_DECREF(v);
147 Py_DECREF(n);
148 return NULL;
149 }
150 Py_DECREF(v);
151 }
152 Py_DECREF(n);
153 }
154 if (module->m_doc != NULL) {
155 v = PyUnicode_FromString(module->m_doc);
156 if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {
157 Py_XDECREF(v);
158 return NULL;
159 }
160 Py_DECREF(v);
161 }
162 m->md_def = module;
163 return (PyObject*)m;
Martin v. Löwis1a214512008-06-11 05:26:20 +0000164}
165
166
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000167PyObject *
Fred Drakeee238b92000-07-09 06:03:25 +0000168PyModule_GetDict(PyObject *m)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000169{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000170 PyObject *d;
171 if (!PyModule_Check(m)) {
172 PyErr_BadInternalCall();
173 return NULL;
174 }
175 d = ((PyModuleObject *)m) -> md_dict;
176 if (d == NULL)
177 ((PyModuleObject *)m) -> md_dict = d = PyDict_New();
178 return d;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000179}
180
Victor Stinnerbd475112011-02-23 00:21:43 +0000181PyObject*
182PyModule_GetNameObject(PyObject *m)
Guido van Rossum0558a201990-10-26 15:00:11 +0000183{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000184 PyObject *d;
Victor Stinnerbd475112011-02-23 00:21:43 +0000185 PyObject *name;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000186 if (!PyModule_Check(m)) {
187 PyErr_BadArgument();
188 return NULL;
189 }
190 d = ((PyModuleObject *)m)->md_dict;
191 if (d == NULL ||
Victor Stinnerbd475112011-02-23 00:21:43 +0000192 (name = PyDict_GetItemString(d, "__name__")) == NULL ||
193 !PyUnicode_Check(name))
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000194 {
195 PyErr_SetString(PyExc_SystemError, "nameless module");
196 return NULL;
197 }
Victor Stinnerbd475112011-02-23 00:21:43 +0000198 Py_INCREF(name);
199 return name;
200}
201
202const char *
203PyModule_GetName(PyObject *m)
204{
205 PyObject *name = PyModule_GetNameObject(m);
206 if (name == NULL)
207 return NULL;
208 Py_DECREF(name); /* module dict has still a reference */
209 return _PyUnicode_AsString(name);
Guido van Rossum0558a201990-10-26 15:00:11 +0000210}
211
Victor Stinner6c00c142010-08-17 23:37:11 +0000212PyObject*
213PyModule_GetFilenameObject(PyObject *m)
Guido van Rossum98cc19f1999-02-15 14:47:16 +0000214{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000215 PyObject *d;
216 PyObject *fileobj;
217 if (!PyModule_Check(m)) {
218 PyErr_BadArgument();
219 return NULL;
220 }
221 d = ((PyModuleObject *)m)->md_dict;
222 if (d == NULL ||
223 (fileobj = PyDict_GetItemString(d, "__file__")) == NULL ||
224 !PyUnicode_Check(fileobj))
225 {
226 PyErr_SetString(PyExc_SystemError, "module filename missing");
227 return NULL;
228 }
Victor Stinner6c00c142010-08-17 23:37:11 +0000229 Py_INCREF(fileobj);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000230 return fileobj;
Victor Stinner8124feb2010-05-07 00:50:12 +0000231}
232
233const char *
234PyModule_GetFilename(PyObject *m)
235{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000236 PyObject *fileobj;
Victor Stinner6c00c142010-08-17 23:37:11 +0000237 char *utf8;
238 fileobj = PyModule_GetFilenameObject(m);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000239 if (fileobj == NULL)
240 return NULL;
Victor Stinner6c00c142010-08-17 23:37:11 +0000241 utf8 = _PyUnicode_AsString(fileobj);
Victor Stinnerbd475112011-02-23 00:21:43 +0000242 Py_DECREF(fileobj); /* module dict has still a reference */
Victor Stinner6c00c142010-08-17 23:37:11 +0000243 return utf8;
Guido van Rossum98cc19f1999-02-15 14:47:16 +0000244}
245
Martin v. Löwis1a214512008-06-11 05:26:20 +0000246PyModuleDef*
247PyModule_GetDef(PyObject* m)
248{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000249 if (!PyModule_Check(m)) {
250 PyErr_BadArgument();
251 return NULL;
252 }
253 return ((PyModuleObject *)m)->md_def;
Martin v. Löwis1a214512008-06-11 05:26:20 +0000254}
255
256void*
257PyModule_GetState(PyObject* m)
258{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000259 if (!PyModule_Check(m)) {
260 PyErr_BadArgument();
261 return NULL;
262 }
263 return ((PyModuleObject *)m)->md_state;
Martin v. Löwis1a214512008-06-11 05:26:20 +0000264}
265
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000266void
Fred Drakeee238b92000-07-09 06:03:25 +0000267_PyModule_Clear(PyObject *m)
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000268{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000269 /* To make the execution order of destructors for global
270 objects a bit more predictable, we first zap all objects
271 whose name starts with a single underscore, before we clear
272 the entire dictionary. We zap them by replacing them with
273 None, rather than deleting them from the dictionary, to
274 avoid rehashing the dictionary (to some extent). */
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000275
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000276 Py_ssize_t pos;
277 PyObject *key, *value;
278 PyObject *d;
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000279
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000280 d = ((PyModuleObject *)m)->md_dict;
281 if (d == NULL)
282 return;
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000283
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000284 /* First, clear only names starting with a single underscore */
285 pos = 0;
286 while (PyDict_Next(d, &pos, &key, &value)) {
287 if (value != Py_None && PyUnicode_Check(key)) {
Victor Stinnerf3f22a22010-05-19 00:03:09 +0000288 Py_UNICODE *u = PyUnicode_AS_UNICODE(key);
289 if (u[0] == '_' && u[1] != '_') {
290 if (Py_VerboseFlag > 1) {
291 const char *s = _PyUnicode_AsString(key);
292 if (s != NULL)
293 PySys_WriteStderr("# clear[1] %s\n", s);
294 else
295 PyErr_Clear();
296 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000297 PyDict_SetItem(d, key, Py_None);
298 }
299 }
300 }
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000301
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000302 /* Next, clear all names except for __builtins__ */
303 pos = 0;
304 while (PyDict_Next(d, &pos, &key, &value)) {
305 if (value != Py_None && PyUnicode_Check(key)) {
Victor Stinnerf3f22a22010-05-19 00:03:09 +0000306 Py_UNICODE *u = PyUnicode_AS_UNICODE(key);
307 if (u[0] != '_'
308 || PyUnicode_CompareWithASCIIString(key, "__builtins__") != 0)
309 {
310 if (Py_VerboseFlag > 1) {
311 const char *s = _PyUnicode_AsString(key);
312 if (s != NULL)
313 PySys_WriteStderr("# clear[2] %s\n", s);
314 else
315 PyErr_Clear();
316 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000317 PyDict_SetItem(d, key, Py_None);
318 }
319 }
320 }
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000321
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000322 /* Note: we leave __builtins__ in place, so that destructors
323 of non-global objects defined in this module can still use
324 builtins, in particularly 'None'. */
Guido van Rossumf1dc0611998-02-19 20:51:52 +0000325
326}
327
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000328/* Methods */
329
Tim Peters6d6c1a32001-08-02 04:15:00 +0000330static int
Guido van Rossumc3a787e2002-06-04 05:52:47 +0000331module_init(PyModuleObject *m, PyObject *args, PyObject *kwds)
Tim Peters6d6c1a32001-08-02 04:15:00 +0000332{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000333 static char *kwlist[] = {"name", "doc", NULL};
334 PyObject *dict, *name = Py_None, *doc = Py_None;
335 if (!PyArg_ParseTupleAndKeywords(args, kwds, "U|O:module.__init__",
336 kwlist, &name, &doc))
337 return -1;
338 dict = m->md_dict;
339 if (dict == NULL) {
340 dict = PyDict_New();
341 if (dict == NULL)
342 return -1;
343 m->md_dict = dict;
344 }
345 if (PyDict_SetItemString(dict, "__name__", name) < 0)
346 return -1;
347 if (PyDict_SetItemString(dict, "__doc__", doc) < 0)
348 return -1;
349 return 0;
Tim Peters6d6c1a32001-08-02 04:15:00 +0000350}
351
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000352static void
Fred Drakeee238b92000-07-09 06:03:25 +0000353module_dealloc(PyModuleObject *m)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000354{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000355 PyObject_GC_UnTrack(m);
356 if (m->md_def && m->md_def->m_free)
357 m->md_def->m_free(m);
358 if (m->md_dict != NULL) {
Benjamin Peterson5c4bfc42010-10-12 22:57:59 +0000359 _PyModule_Clear((PyObject *)m);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000360 Py_DECREF(m->md_dict);
361 }
362 if (m->md_state != NULL)
363 PyMem_FREE(m->md_state);
364 Py_TYPE(m)->tp_free((PyObject *)m);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000365}
366
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000367static PyObject *
Fred Drakeee238b92000-07-09 06:03:25 +0000368module_repr(PyModuleObject *m)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000369{
Victor Stinnerbd475112011-02-23 00:21:43 +0000370 PyObject *name, *filename, *repr;
Barry Warsaw2907fe62001-08-16 20:39:24 +0000371
Victor Stinnerbd475112011-02-23 00:21:43 +0000372 name = PyModule_GetNameObject((PyObject *)m);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000373 if (name == NULL) {
374 PyErr_Clear();
Victor Stinnerbd475112011-02-23 00:21:43 +0000375 name = PyUnicode_FromStringAndSize("?", 1);
376 if (name == NULL)
377 return NULL;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000378 }
Victor Stinner6c00c142010-08-17 23:37:11 +0000379 filename = PyModule_GetFilenameObject((PyObject *)m);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000380 if (filename == NULL) {
381 PyErr_Clear();
Victor Stinnerbd475112011-02-23 00:21:43 +0000382 repr = PyUnicode_FromFormat("<module %R (built-in)>", name);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000383 }
Victor Stinnerbd475112011-02-23 00:21:43 +0000384 else {
385 repr = PyUnicode_FromFormat("<module %R from %R>", name, filename);
386 Py_DECREF(filename);
387 }
388 Py_DECREF(name);
Victor Stinner6c00c142010-08-17 23:37:11 +0000389 return repr;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000390}
391
Neil Schemenauer10e31cf2001-01-02 15:58:27 +0000392static int
393module_traverse(PyModuleObject *m, visitproc visit, void *arg)
394{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000395 if (m->md_def && m->md_def->m_traverse) {
396 int res = m->md_def->m_traverse((PyObject*)m, visit, arg);
397 if (res)
398 return res;
399 }
400 Py_VISIT(m->md_dict);
401 return 0;
Neil Schemenauer10e31cf2001-01-02 15:58:27 +0000402}
403
Martin v. Löwis1a214512008-06-11 05:26:20 +0000404static int
405module_clear(PyModuleObject *m)
406{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000407 if (m->md_def && m->md_def->m_clear) {
408 int res = m->md_def->m_clear((PyObject*)m);
409 if (res)
410 return res;
411 }
412 Py_CLEAR(m->md_dict);
413 return 0;
Martin v. Löwis1a214512008-06-11 05:26:20 +0000414}
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000415
Benjamin Peterson82b00c12011-05-24 11:09:06 -0500416static PyObject *
417module_dir(PyObject *self, PyObject *args)
418{
419 PyObject *result = NULL;
420 PyObject *dict = PyObject_GetAttrString(self, "__dict__");
421
422 if (dict != NULL) {
423 if (PyDict_Check(dict))
424 result = PyDict_Keys(dict);
425 else {
426 const char *name = PyModule_GetName(self);
427 if (name)
428 PyErr_Format(PyExc_TypeError,
429 "%.200s.__dict__ is not a dictionary",
430 name);
431 }
432 }
433
434 Py_XDECREF(dict);
435 return result;
436}
437
438static PyMethodDef module_methods[] = {
439 {"__dir__", module_dir, METH_NOARGS,
Benjamin Petersonc7284122011-05-24 12:46:15 -0500440 PyDoc_STR("__dir__() -> list\nspecialized dir() implementation")},
Benjamin Peterson82b00c12011-05-24 11:09:06 -0500441 {0}
442};
443
Martin v. Löwis1a214512008-06-11 05:26:20 +0000444
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000445PyDoc_STRVAR(module_doc,
Guido van Rossumed3e09f2002-06-04 06:02:35 +0000446"module(name[, doc])\n\
447\n\
448Create a module object.\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000449The name must be a string; the optional doc argument can have any type.");
Guido van Rossumed3e09f2002-06-04 06:02:35 +0000450
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000451PyTypeObject PyModule_Type = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000452 PyVarObject_HEAD_INIT(&PyType_Type, 0)
453 "module", /* tp_name */
454 sizeof(PyModuleObject), /* tp_size */
455 0, /* tp_itemsize */
456 (destructor)module_dealloc, /* tp_dealloc */
457 0, /* tp_print */
458 0, /* tp_getattr */
459 0, /* tp_setattr */
460 0, /* tp_reserved */
461 (reprfunc)module_repr, /* tp_repr */
462 0, /* tp_as_number */
463 0, /* tp_as_sequence */
464 0, /* tp_as_mapping */
465 0, /* tp_hash */
466 0, /* tp_call */
467 0, /* tp_str */
468 PyObject_GenericGetAttr, /* tp_getattro */
469 PyObject_GenericSetAttr, /* tp_setattro */
470 0, /* tp_as_buffer */
471 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
472 Py_TPFLAGS_BASETYPE, /* tp_flags */
473 module_doc, /* tp_doc */
474 (traverseproc)module_traverse, /* tp_traverse */
475 (inquiry)module_clear, /* tp_clear */
476 0, /* tp_richcompare */
477 0, /* tp_weaklistoffset */
478 0, /* tp_iter */
479 0, /* tp_iternext */
Benjamin Peterson82b00c12011-05-24 11:09:06 -0500480 module_methods, /* tp_methods */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000481 module_members, /* tp_members */
482 0, /* tp_getset */
483 0, /* tp_base */
484 0, /* tp_dict */
485 0, /* tp_descr_get */
486 0, /* tp_descr_set */
487 offsetof(PyModuleObject, md_dict), /* tp_dictoffset */
488 (initproc)module_init, /* tp_init */
489 PyType_GenericAlloc, /* tp_alloc */
490 PyType_GenericNew, /* tp_new */
491 PyObject_GC_Del, /* tp_free */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000492};