Mercurial > cpython-lru_cache-weakref
annotate Modules/xxmodule.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | fd25030223b0 |
| children |
| rev | line source |
|---|---|
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
2 /* Use this file as a template to start implementing a module that |
|
14073
314ec59e4e14
Use METH_VARARGS constant in example module.
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
3 also declares object types. All occurrences of 'Xxo' should be changed |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
4 to something reasonable for your objects. After that, all other |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
5 occurrences of 'xx' should be changed to something reasonable for your |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
6 module. If your module is named foo your sourcefile should be named |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
7 foomodule.c. |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
8 |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
9 You will probably want to delete all references to 'x_attr' and add |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
10 your own types of attributes instead. Maybe you want to name your |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
11 local variables other than 'self'. If your object type is needed in |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
12 other files, you'll have to create a file "foobarobject.h"; see |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
13 intobject.h for an example. */ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
14 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
15 /* Xxo objects */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
17 #include "Python.h" |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
18 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
19 static PyObject *ErrorObject; |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
20 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
21 typedef struct { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
22 PyObject_HEAD |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
23 PyObject *x_attr; /* Attributes dictionary */ |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
24 } XxoObject; |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
25 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23522
diff
changeset
|
26 static PyTypeObject Xxo_Type; |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
27 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
28 #define XxoObject_Check(v) (Py_TYPE(v) == &Xxo_Type) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
29 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
30 static XxoObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
31 newXxoObject(PyObject *arg) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
32 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
33 XxoObject *self; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
34 self = PyObject_New(XxoObject, &Xxo_Type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
35 if (self == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
36 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
37 self->x_attr = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
38 return self; |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
39 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
40 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
41 /* Xxo methods */ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
42 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
43 static void |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
44 Xxo_dealloc(XxoObject *self) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
45 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
46 Py_XDECREF(self->x_attr); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
47 PyObject_Del(self); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
48 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
49 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
50 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
51 Xxo_demo(XxoObject *self, PyObject *args) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
52 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
53 if (!PyArg_ParseTuple(args, ":demo")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
54 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
55 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
56 return Py_None; |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
57 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
58 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
59 static PyMethodDef Xxo_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
60 {"demo", (PyCFunction)Xxo_demo, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
61 PyDoc_STR("demo() -> None")}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
62 {NULL, NULL} /* sentinel */ |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
63 }; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
65 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
66 Xxo_getattr(XxoObject *self, char *name) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
67 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
68 if (self->x_attr != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
69 PyObject *v = PyDict_GetItemString(self->x_attr, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
70 if (v != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
71 Py_INCREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
72 return v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
73 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
74 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
75 return Py_FindMethod(Xxo_methods, (PyObject *)self, name); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
76 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
77 |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
78 static int |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
79 Xxo_setattr(XxoObject *self, char *name, PyObject *v) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
80 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
81 if (self->x_attr == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
82 self->x_attr = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
83 if (self->x_attr == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
84 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
85 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
86 if (v == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
87 int rv = PyDict_DelItemString(self->x_attr, name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
88 if (rv < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
89 PyErr_SetString(PyExc_AttributeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
90 "delete non-existing Xxo attribute"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
91 return rv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
92 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
93 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
94 return PyDict_SetItemString(self->x_attr, name, v); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
95 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
96 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
97 static PyTypeObject Xxo_Type = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
98 /* The ob_type field must be initialized in the module init function |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
99 * to be portable to Windows without using C++. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
100 PyVarObject_HEAD_INIT(NULL, 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
101 "xxmodule.Xxo", /*tp_name*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
102 sizeof(XxoObject), /*tp_basicsize*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
103 0, /*tp_itemsize*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
104 /* methods */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
105 (destructor)Xxo_dealloc, /*tp_dealloc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
106 0, /*tp_print*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
107 (getattrfunc)Xxo_getattr, /*tp_getattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
108 (setattrfunc)Xxo_setattr, /*tp_setattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
109 0, /*tp_compare*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
110 0, /*tp_repr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
111 0, /*tp_as_number*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
112 0, /*tp_as_sequence*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
113 0, /*tp_as_mapping*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
114 0, /*tp_hash*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
115 0, /*tp_call*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
116 0, /*tp_str*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
117 0, /*tp_getattro*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
118 0, /*tp_setattro*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
119 0, /*tp_as_buffer*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
120 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
121 0, /*tp_doc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
122 0, /*tp_traverse*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
123 0, /*tp_clear*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
124 0, /*tp_richcompare*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
125 0, /*tp_weaklistoffset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
126 0, /*tp_iter*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
127 0, /*tp_iternext*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
128 0, /*tp_methods*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
129 0, /*tp_members*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
130 0, /*tp_getset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
131 0, /*tp_base*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
132 0, /*tp_dict*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
133 0, /*tp_descr_get*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
134 0, /*tp_descr_set*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
135 0, /*tp_dictoffset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
136 0, /*tp_init*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
137 0, /*tp_alloc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
138 0, /*tp_new*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
139 0, /*tp_free*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
140 0, /*tp_is_gc*/ |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
141 }; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
142 /* --------------------------------------------------------------------- */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 /* Function of two integers returning integer */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 |
|
24804
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
146 PyDoc_STRVAR(xx_foo_doc, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
147 "foo(i,j)\n\ |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
148 \n\ |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
149 Return the sum of i and j."); |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
150 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
151 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
152 xx_foo(PyObject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
154 long i, j; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
155 long res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
156 if (!PyArg_ParseTuple(args, "ll:foo", &i, &j)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
157 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
158 res = i+j; /* XXX Do something here */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
159 return PyInt_FromLong(res); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
163 /* Function of no arguments returning new Xxo object */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
165 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
166 xx_new(PyObject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
168 XxoObject *rv; |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
169 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
170 if (!PyArg_ParseTuple(args, ":new")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
171 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
172 rv = newXxoObject(args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
173 if (rv == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
174 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
175 return (PyObject *)rv; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 |
|
4714
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
178 /* Example with subtle bug from extensions manual ("Thin Ice"). */ |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
179 |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
180 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
181 xx_bug(PyObject *self, PyObject *args) |
|
4714
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
182 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
183 PyObject *list, *item; |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
184 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
185 if (!PyArg_ParseTuple(args, "O:bug", &list)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
186 return NULL; |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
187 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
188 item = PyList_GetItem(list, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
189 /* Py_INCREF(item); */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
190 PyList_SetItem(list, 1, PyInt_FromLong(0L)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
191 PyObject_Print(item, stdout, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
192 printf("\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
193 /* Py_DECREF(item); */ |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
194 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
195 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
196 return Py_None; |
|
4714
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
197 } |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
198 |
|
6806
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
199 /* Test bad format character */ |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
200 |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
201 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
202 xx_roj(PyObject *self, PyObject *args) |
|
6806
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
203 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
204 PyObject *a; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
205 long b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
206 if (!PyArg_ParseTuple(args, "O#:roj", &a, &b)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
207 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
208 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
209 return Py_None; |
|
6806
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
210 } |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
211 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 |
|
27823
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
213 /* ---------- */ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
214 |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
215 static PyTypeObject Str_Type = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
216 /* The ob_type field must be initialized in the module init function |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
217 * to be portable to Windows without using C++. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
218 PyVarObject_HEAD_INIT(NULL, 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
219 "xxmodule.Str", /*tp_name*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
220 0, /*tp_basicsize*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
221 0, /*tp_itemsize*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
222 /* methods */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
223 0, /*tp_dealloc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
224 0, /*tp_print*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
225 0, /*tp_getattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
226 0, /*tp_setattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
227 0, /*tp_compare*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
228 0, /*tp_repr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
229 0, /*tp_as_number*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
230 0, /*tp_as_sequence*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
231 0, /*tp_as_mapping*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
232 0, /*tp_hash*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
233 0, /*tp_call*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
234 0, /*tp_str*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
235 0, /*tp_getattro*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
236 0, /*tp_setattro*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
237 0, /*tp_as_buffer*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
238 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
239 0, /*tp_doc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
240 0, /*tp_traverse*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
241 0, /*tp_clear*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
242 0, /*tp_richcompare*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
243 0, /*tp_weaklistoffset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
244 0, /*tp_iter*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
245 0, /*tp_iternext*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
246 0, /*tp_methods*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
247 0, /*tp_members*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
248 0, /*tp_getset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
249 0, /* see initxx */ /*tp_base*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
250 0, /*tp_dict*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
251 0, /*tp_descr_get*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
252 0, /*tp_descr_set*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
253 0, /*tp_dictoffset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
254 0, /*tp_init*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
255 0, /*tp_alloc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
256 0, /*tp_new*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
257 0, /*tp_free*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
258 0, /*tp_is_gc*/ |
|
27823
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
259 }; |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
260 |
| 27873 | 261 /* ---------- */ |
| 262 | |
| 263 static PyObject * | |
| 264 null_richcompare(PyObject *self, PyObject *other, int op) | |
| 265 { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
266 Py_INCREF(Py_NotImplemented); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
267 return Py_NotImplemented; |
| 27873 | 268 } |
| 269 | |
| 270 static PyTypeObject Null_Type = { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
271 /* The ob_type field must be initialized in the module init function |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
272 * to be portable to Windows without using C++. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
273 PyVarObject_HEAD_INIT(NULL, 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
274 "xxmodule.Null", /*tp_name*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
275 0, /*tp_basicsize*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
276 0, /*tp_itemsize*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
277 /* methods */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
278 0, /*tp_dealloc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
279 0, /*tp_print*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
280 0, /*tp_getattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
281 0, /*tp_setattr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
282 0, /*tp_compare*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
283 0, /*tp_repr*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
284 0, /*tp_as_number*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
285 0, /*tp_as_sequence*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
286 0, /*tp_as_mapping*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
287 0, /*tp_hash*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
288 0, /*tp_call*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
289 0, /*tp_str*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
290 0, /*tp_getattro*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
291 0, /*tp_setattro*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
292 0, /*tp_as_buffer*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
293 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
294 0, /*tp_doc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
295 0, /*tp_traverse*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
296 0, /*tp_clear*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
297 null_richcompare, /*tp_richcompare*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
298 0, /*tp_weaklistoffset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
299 0, /*tp_iter*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
300 0, /*tp_iternext*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
301 0, /*tp_methods*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
302 0, /*tp_members*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
303 0, /*tp_getset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
304 0, /* see initxx */ /*tp_base*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
305 0, /*tp_dict*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
306 0, /*tp_descr_get*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
307 0, /*tp_descr_set*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
308 0, /*tp_dictoffset*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
309 0, /*tp_init*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
310 0, /*tp_alloc*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
311 0, /* see initxx */ /*tp_new*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
312 0, /*tp_free*/ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
313 0, /*tp_is_gc*/ |
| 27873 | 314 }; |
| 315 | |
|
27823
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
316 |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
317 /* ---------- */ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
318 |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
319 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 /* List of functions defined in the module */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
322 static PyMethodDef xx_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
323 {"roj", xx_roj, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
324 PyDoc_STR("roj(a,b) -> None")}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
325 {"foo", xx_foo, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
326 xx_foo_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
327 {"new", xx_new, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
328 PyDoc_STR("new() -> new Xx object")}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
329 {"bug", xx_bug, METH_VARARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
330 PyDoc_STR("bug(o) -> None")}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
331 {NULL, NULL} /* sentinel */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 |
|
24804
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
334 PyDoc_STRVAR(module_doc, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
335 "This is a template module just for instruction."); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 /* Initialization function for the module (*must* be called initxx) */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24283
diff
changeset
|
339 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13499
diff
changeset
|
340 initxx(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
342 PyObject *m; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
344 /* Due to cross platform compiler issues the slots must be filled |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
345 * here. It's required for portability to Windows without requiring |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
346 * C++. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
347 Null_Type.tp_base = &PyBaseObject_Type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
348 Null_Type.tp_new = PyType_GenericNew; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
349 Str_Type.tp_base = &PyUnicode_Type; |
|
44117
ead0d47b012b
Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
350 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
351 /* Finalize the type object including setting type of the new type |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
352 * object; doing it here is required for portability, too. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
353 if (PyType_Ready(&Xxo_Type) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
354 return; |
|
10202
e1da290acc5f
Use the portable form of initializing the ob_type field for new types.
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
355 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
356 /* Create the module and add the functions */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
357 m = Py_InitModule3("xx", xx_methods, module_doc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
358 if (m == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
359 return; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
361 /* Add some symbolic constants to the module */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
362 if (ErrorObject == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
363 ErrorObject = PyErr_NewException("xx.error", NULL, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
364 if (ErrorObject == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
365 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
366 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
367 Py_INCREF(ErrorObject); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
368 PyModule_AddObject(m, "error", ErrorObject); |
|
27823
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
369 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
370 /* Add Str */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
371 if (PyType_Ready(&Str_Type) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
372 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
373 PyModule_AddObject(m, "Str", (PyObject *)&Str_Type); |
| 27873 | 374 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
375 /* Add Null */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
376 if (PyType_Ready(&Null_Type) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
377 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
44350
diff
changeset
|
378 PyModule_AddObject(m, "Null", (PyObject *)&Null_Type); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 } |
