Mercurial > cpython-lru_cache-weakref
annotate Modules/xxmodule.c @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 88a42a7c238a |
| children | 4808ee62b156 1af7f719ed28 |
| 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 { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
22 PyObject_HEAD |
|
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
23 PyObject *x_attr; /* Attributes dictionary */ |
|
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 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
28 #define XxoObject_Check(v) ((v)->ob_type == &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 { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
33 XxoObject *self; |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
34 self = PyObject_New(XxoObject, &Xxo_Type); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
35 if (self == NULL) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
36 return NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
37 self->x_attr = NULL; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
38 return self; |
|
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 { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
46 Py_XDECREF(self->x_attr); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
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 { |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
10202
diff
changeset
|
53 if (!PyArg_ParseTuple(args, ":demo")) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
54 return NULL; |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
55 Py_INCREF(Py_None); |
|
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
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[] = { |
|
24804
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
60 {"demo", (PyCFunction)Xxo_demo, METH_VARARGS, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
61 PyDoc_STR("demo() -> None")}, |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
62 {NULL, NULL} /* sentinel */ |
|
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 { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
68 if (self->x_attr != NULL) { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
69 PyObject *v = PyDict_GetItemString(self->x_attr, name); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
70 if (v != NULL) { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
71 Py_INCREF(v); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
72 return v; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
73 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
74 } |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
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 { |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
81 if (self->x_attr == NULL) { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
82 self->x_attr = PyDict_New(); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
83 if (self->x_attr == NULL) |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
84 return -1; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
85 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
86 if (v == NULL) { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
87 int rv = PyDict_DelItemString(self->x_attr, name); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
88 if (rv < 0) |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
89 PyErr_SetString(PyExc_AttributeError, |
|
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
90 "delete non-existing Xxo attribute"); |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
91 return rv; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
92 } |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
93 else |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
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 = { |
|
10202
e1da290acc5f
Use the portable form of initializing the ob_type field for new types.
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
98 /* The ob_type field must be initialized in the module init function |
|
e1da290acc5f
Use the portable form of initializing the ob_type field for new types.
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
99 * to be portable to Windows without using C++. */ |
|
e1da290acc5f
Use the portable form of initializing the ob_type field for new types.
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
100 PyObject_HEAD_INIT(NULL) |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
101 0, /*ob_size*/ |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
20441
diff
changeset
|
102 "xxmodule.Xxo", /*tp_name*/ |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
103 sizeof(XxoObject), /*tp_basicsize*/ |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
104 0, /*tp_itemsize*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
105 /* methods */ |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
106 (destructor)Xxo_dealloc, /*tp_dealloc*/ |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
107 0, /*tp_print*/ |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
108 (getattrfunc)Xxo_getattr, /*tp_getattr*/ |
|
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
109 (setattrfunc)Xxo_setattr, /*tp_setattr*/ |
|
1915
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
110 0, /*tp_compare*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
111 0, /*tp_repr*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
112 0, /*tp_as_number*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
113 0, /*tp_as_sequence*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
114 0, /*tp_as_mapping*/ |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
115 0, /*tp_hash*/ |
|
20326
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
116 0, /*tp_call*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
117 0, /*tp_str*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
118 0, /*tp_getattro*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
119 0, /*tp_setattro*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
120 0, /*tp_as_buffer*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
121 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
122 0, /*tp_doc*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
123 0, /*tp_traverse*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
124 0, /*tp_clear*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
125 0, /*tp_richcompare*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
126 0, /*tp_weaklistoffset*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
127 0, /*tp_iter*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
128 0, /*tp_iternext*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
129 0, /*tp_methods*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
130 0, /*tp_members*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
131 0, /*tp_getset*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
132 0, /*tp_base*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
133 0, /*tp_dict*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
134 0, /*tp_descr_get*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
135 0, /*tp_descr_set*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
136 0, /*tp_dictoffset*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
137 0, /*tp_init*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
138 0, /*tp_alloc*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
139 0, /*tp_new*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
140 0, /*tp_free*/ |
|
b32d66a4b5e6
Add additional fields to Xxo_Type declaration. Fixes bug #469250.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
141 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
|
142 }; |
|
80818c106e3e
* Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents:
1473
diff
changeset
|
143 /* --------------------------------------------------------------------- */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 /* Function of two integers returning integer */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 |
|
24804
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
147 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
|
148 "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
|
149 \n\ |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
150 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
|
151 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
152 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
153 xx_foo(PyObject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 long i, j; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 long res; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
10202
diff
changeset
|
157 if (!PyArg_ParseTuple(args, "ll:foo", &i, &j)) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 return NULL; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 res = i+j; /* XXX Do something here */ |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
160 return PyInt_FromLong(res); |
|
923
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 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
164 /* Function of no arguments returning new Xxo object */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
166 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
167 xx_new(PyObject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 { |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
169 XxoObject *rv; |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
170 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
10202
diff
changeset
|
171 if (!PyArg_ParseTuple(args, ":new")) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 return NULL; |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
173 rv = newXxoObject(args); |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
174 if (rv == NULL) |
|
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
175 return NULL; |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
176 return (PyObject *)rv; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 |
|
4714
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
179 /* 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
|
180 |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
181 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
182 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
|
183 { |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
184 PyObject *list, *item; |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
185 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
10202
diff
changeset
|
186 if (!PyArg_ParseTuple(args, "O:bug", &list)) |
|
4714
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
187 return NULL; |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
188 |
|
4714
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
189 item = PyList_GetItem(list, 0); |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
190 /* Py_INCREF(item); */ |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
191 PyList_SetItem(list, 1, PyInt_FromLong(0L)); |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
192 PyObject_Print(item, stdout, 0); |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
193 printf("\n"); |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
194 /* Py_DECREF(item); */ |
|
23522
2aff12e2a94f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
22910
diff
changeset
|
195 |
|
4714
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
196 Py_INCREF(Py_None); |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
197 return Py_None; |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
198 } |
|
0c6c69b0d3e9
Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
199 |
|
6806
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
200 /* Test bad format character */ |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
201 |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
202 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
203 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
|
204 { |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
205 PyObject *a; |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
206 long b; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
10202
diff
changeset
|
207 if (!PyArg_ParseTuple(args, "O#:roj", &a, &b)) |
|
6806
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
208 return NULL; |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
209 Py_INCREF(Py_None); |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
210 return Py_None; |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
211 } |
|
ac1b261f1690
Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
212 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 |
|
27823
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 |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
216 static PyTypeObject Str_Type = { |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
217 /* The ob_type field must be initialized in the module init function |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
218 * to be portable to Windows without using C++. */ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
219 PyObject_HEAD_INIT(NULL) |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
220 0, /*ob_size*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
221 "xxmodule.Str", /*tp_name*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
222 0, /*tp_basicsize*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
223 0, /*tp_itemsize*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
224 /* methods */ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
225 0, /*tp_dealloc*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
226 0, /*tp_print*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
227 0, /*tp_getattr*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
228 0, /*tp_setattr*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
229 0, /*tp_compare*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
230 0, /*tp_repr*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
231 0, /*tp_as_number*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
232 0, /*tp_as_sequence*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
233 0, /*tp_as_mapping*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
234 0, /*tp_hash*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
235 0, /*tp_call*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
236 0, /*tp_str*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
237 0, /*tp_getattro*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
238 0, /*tp_setattro*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
239 0, /*tp_as_buffer*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
240 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
241 0, /*tp_doc*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
242 0, /*tp_traverse*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
243 0, /*tp_clear*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
244 0, /*tp_richcompare*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
245 0, /*tp_weaklistoffset*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
246 0, /*tp_iter*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
247 0, /*tp_iternext*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
248 0, /*tp_methods*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
249 0, /*tp_members*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
250 0, /*tp_getset*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
251 &PyString_Type, /*tp_base*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
252 0, /*tp_dict*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
253 0, /*tp_descr_get*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
254 0, /*tp_descr_set*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
255 0, /*tp_dictoffset*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
256 0, /*tp_init*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
257 0, /*tp_alloc*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
258 0, /*tp_new*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
259 0, /*tp_free*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
260 0, /*tp_is_gc*/ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
261 }; |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
262 |
| 27873 | 263 /* ---------- */ |
| 264 | |
| 265 static PyObject * | |
| 266 null_richcompare(PyObject *self, PyObject *other, int op) | |
| 267 { | |
| 268 Py_INCREF(Py_NotImplemented); | |
| 269 return Py_NotImplemented; | |
| 270 } | |
| 271 | |
| 272 static PyTypeObject Null_Type = { | |
| 273 /* The ob_type field must be initialized in the module init function | |
| 274 * to be portable to Windows without using C++. */ | |
| 275 PyObject_HEAD_INIT(NULL) | |
| 276 0, /*ob_size*/ | |
| 277 "xxmodule.Null", /*tp_name*/ | |
| 278 0, /*tp_basicsize*/ | |
| 279 0, /*tp_itemsize*/ | |
| 280 /* methods */ | |
| 281 0, /*tp_dealloc*/ | |
| 282 0, /*tp_print*/ | |
| 283 0, /*tp_getattr*/ | |
| 284 0, /*tp_setattr*/ | |
| 285 0, /*tp_compare*/ | |
| 286 0, /*tp_repr*/ | |
| 287 0, /*tp_as_number*/ | |
| 288 0, /*tp_as_sequence*/ | |
| 289 0, /*tp_as_mapping*/ | |
| 290 0, /*tp_hash*/ | |
| 291 0, /*tp_call*/ | |
| 292 0, /*tp_str*/ | |
| 293 0, /*tp_getattro*/ | |
| 294 0, /*tp_setattro*/ | |
| 295 0, /*tp_as_buffer*/ | |
| 296 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ | |
| 297 0, /*tp_doc*/ | |
| 298 0, /*tp_traverse*/ | |
| 299 0, /*tp_clear*/ | |
| 300 null_richcompare, /*tp_richcompare*/ | |
| 301 0, /*tp_weaklistoffset*/ | |
| 302 0, /*tp_iter*/ | |
| 303 0, /*tp_iternext*/ | |
| 304 0, /*tp_methods*/ | |
| 305 0, /*tp_members*/ | |
| 306 0, /*tp_getset*/ | |
| 307 &PyBaseObject_Type, /*tp_base*/ | |
| 308 0, /*tp_dict*/ | |
| 309 0, /*tp_descr_get*/ | |
| 310 0, /*tp_descr_set*/ | |
| 311 0, /*tp_dictoffset*/ | |
| 312 0, /*tp_init*/ | |
| 313 0, /*tp_alloc*/ | |
| 314 PyType_GenericNew, /*tp_new*/ | |
| 315 0, /*tp_free*/ | |
| 316 0, /*tp_is_gc*/ | |
| 317 }; | |
| 318 | |
|
27823
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
319 |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
320 /* ---------- */ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
321 |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
322 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 /* List of functions defined in the module */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 |
|
3845
d19338fd38eb
Converted to new style
Guido van Rossum <guido@python.org>
parents:
2377
diff
changeset
|
325 static PyMethodDef xx_methods[] = { |
|
24804
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
326 {"roj", xx_roj, METH_VARARGS, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
327 PyDoc_STR("roj(a,b) -> None")}, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
328 {"foo", xx_foo, METH_VARARGS, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
329 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
|
330 {"new", xx_new, METH_VARARGS, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
331 PyDoc_STR("new() -> new Xx object")}, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
332 {"bug", xx_bug, METH_VARARGS, |
|
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
333 PyDoc_STR("bug(o) -> None")}, |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 {NULL, NULL} /* sentinel */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 |
|
24804
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
337 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
|
338 "This is a template module just for instruction."); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 /* Initialization function for the module (*must* be called initxx) */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24283
diff
changeset
|
342 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13499
diff
changeset
|
343 initxx(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 { |
| 22910 | 345 PyObject *m; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 |
|
26822
fea92e7ec67a
Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents:
24804
diff
changeset
|
347 /* Finalize the type object including setting type of the new type |
|
fea92e7ec67a
Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents:
24804
diff
changeset
|
348 * object; doing it here is required for portability to Windows |
|
fea92e7ec67a
Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents:
24804
diff
changeset
|
349 * without requiring C++. */ |
|
fea92e7ec67a
Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents:
24804
diff
changeset
|
350 if (PyType_Ready(&Xxo_Type) < 0) |
|
fea92e7ec67a
Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents:
24804
diff
changeset
|
351 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
|
352 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 /* Create the module and add the functions */ |
|
24804
30cff9c1bf69
add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
354 m = Py_InitModule3("xx", xx_methods, module_doc); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 /* Add some symbolic constants to the module */ |
|
22257
aa3bf525f482
Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents:
21313
diff
changeset
|
357 if (ErrorObject == NULL) { |
|
aa3bf525f482
Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents:
21313
diff
changeset
|
358 ErrorObject = PyErr_NewException("xx.error", NULL, NULL); |
|
aa3bf525f482
Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents:
21313
diff
changeset
|
359 if (ErrorObject == NULL) |
|
aa3bf525f482
Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents:
21313
diff
changeset
|
360 return; |
|
aa3bf525f482
Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents:
21313
diff
changeset
|
361 } |
|
aa3bf525f482
Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents:
21313
diff
changeset
|
362 Py_INCREF(ErrorObject); |
| 22910 | 363 PyModule_AddObject(m, "error", ErrorObject); |
|
27823
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
364 |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
365 /* Add Str */ |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
366 if (PyType_Ready(&Str_Type) < 0) |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
367 return; |
|
651d1123ed6e
Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents:
26822
diff
changeset
|
368 PyModule_AddObject(m, "Str", (PyObject *)&Str_Type); |
| 27873 | 369 |
| 370 /* Add Null */ | |
| 371 if (PyType_Ready(&Null_Type) < 0) | |
| 372 return; | |
| 373 PyModule_AddObject(m, "Null", (PyObject *)&Null_Type); | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 } |
