annotate Modules/xxmodule.c @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 26384b8180c7
children fd25030223b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 44278
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 {
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++. */
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 36989
diff changeset
100 PyVarObject_HEAD_INIT(NULL, 0)
21313
91dd223829c6 Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents: 20441
diff changeset
101 "xxmodule.Xxo", /*tp_name*/
3845
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
diff changeset
102 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
103 0, /*tp_itemsize*/
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1473
diff changeset
104 /* methods */
3845
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
diff changeset
105 (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
106 0, /*tp_print*/
3845
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
diff changeset
107 (getattrfunc)Xxo_getattr, /*tp_getattr*/
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
diff changeset
108 (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
109 0, /*tp_compare*/
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1473
diff changeset
110 0, /*tp_repr*/
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1473
diff changeset
111 0, /*tp_as_number*/
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1473
diff changeset
112 0, /*tp_as_sequence*/
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1473
diff changeset
113 0, /*tp_as_mapping*/
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1473
diff changeset
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
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 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 long i, j;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 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
156 if (!PyArg_ParseTuple(args, "ll:foo", &i, &j))
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 return NULL;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 res = i+j; /* XXX Do something here */
3845
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
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 {
3845
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
diff changeset
168 XxoObject *rv;
23522
2aff12e2a94f Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 22910
diff changeset
169
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 10202
diff changeset
170 if (!PyArg_ParseTuple(args, ":new"))
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 return NULL;
3845
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
diff changeset
172 rv = newXxoObject(args);
23522
2aff12e2a94f Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 22910
diff changeset
173 if (rv == NULL)
2aff12e2a94f Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 22910
diff changeset
174 return NULL;
3845
d19338fd38eb Converted to new style
Guido van Rossum <guido@python.org>
parents: 2377
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 {
0c6c69b0d3e9 Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
183 PyObject *list, *item;
23522
2aff12e2a94f Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 22910
diff changeset
184
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 10202
diff changeset
185 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
186 return NULL;
23522
2aff12e2a94f Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 22910
diff changeset
187
4714
0c6c69b0d3e9 Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
188 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
189 /* Py_INCREF(item); */
0c6c69b0d3e9 Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
190 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
191 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
192 printf("\n");
0c6c69b0d3e9 Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
193 /* Py_DECREF(item); */
23522
2aff12e2a94f Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 22910
diff changeset
194
4714
0c6c69b0d3e9 Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
195 Py_INCREF(Py_None);
0c6c69b0d3e9 Added the example "thin ice" from the extensions manual.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
196 return Py_None;
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 {
ac1b261f1690 Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
204 PyObject *a;
ac1b261f1690 Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
205 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
206 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
207 return NULL;
ac1b261f1690 Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
208 Py_INCREF(Py_None);
ac1b261f1690 Add a test for a bad format character.
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
209 return Py_None;
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 = {
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
216 /* 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
217 * to be portable to Windows without using C++. */
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 36989
diff changeset
218 PyVarObject_HEAD_INIT(NULL, 0)
27823
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
219 "xxmodule.Str", /*tp_name*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
220 0, /*tp_basicsize*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
221 0, /*tp_itemsize*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
222 /* methods */
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
223 0, /*tp_dealloc*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
224 0, /*tp_print*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
225 0, /*tp_getattr*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
226 0, /*tp_setattr*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
227 0, /*tp_compare*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
228 0, /*tp_repr*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
229 0, /*tp_as_number*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
230 0, /*tp_as_sequence*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
231 0, /*tp_as_mapping*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
232 0, /*tp_hash*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
233 0, /*tp_call*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
234 0, /*tp_str*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
235 0, /*tp_getattro*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
236 0, /*tp_setattro*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
237 0, /*tp_as_buffer*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
238 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
239 0, /*tp_doc*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
240 0, /*tp_traverse*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
241 0, /*tp_clear*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
242 0, /*tp_richcompare*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
243 0, /*tp_weaklistoffset*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
244 0, /*tp_iter*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
245 0, /*tp_iternext*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
246 0, /*tp_methods*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
247 0, /*tp_members*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
248 0, /*tp_getset*/
44119
64582083cb9a I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
249 0, /* see initxx */ /*tp_base*/
27823
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
250 0, /*tp_dict*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
251 0, /*tp_descr_get*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
252 0, /*tp_descr_set*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
253 0, /*tp_dictoffset*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
254 0, /*tp_init*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
255 0, /*tp_alloc*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
256 0, /*tp_new*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
257 0, /*tp_free*/
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
258 0, /*tp_is_gc*/
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
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
261 /* ---------- */
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
262
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
263 static PyObject *
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
264 null_richcompare(PyObject *self, PyObject *other, int op)
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
265 {
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
266 Py_INCREF(Py_NotImplemented);
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
267 return Py_NotImplemented;
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
268 }
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
269
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
270 static PyTypeObject Null_Type = {
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
271 /* The ob_type field must be initialized in the module init function
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
272 * to be portable to Windows without using C++. */
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 36989
diff changeset
273 PyVarObject_HEAD_INIT(NULL, 0)
27873
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
274 "xxmodule.Null", /*tp_name*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
275 0, /*tp_basicsize*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
276 0, /*tp_itemsize*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
277 /* methods */
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
278 0, /*tp_dealloc*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
279 0, /*tp_print*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
280 0, /*tp_getattr*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
281 0, /*tp_setattr*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
282 0, /*tp_compare*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
283 0, /*tp_repr*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
284 0, /*tp_as_number*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
285 0, /*tp_as_sequence*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
286 0, /*tp_as_mapping*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
287 0, /*tp_hash*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
288 0, /*tp_call*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
289 0, /*tp_str*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
290 0, /*tp_getattro*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
291 0, /*tp_setattro*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
292 0, /*tp_as_buffer*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
293 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
294 0, /*tp_doc*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
295 0, /*tp_traverse*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
296 0, /*tp_clear*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
297 null_richcompare, /*tp_richcompare*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
298 0, /*tp_weaklistoffset*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
299 0, /*tp_iter*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
300 0, /*tp_iternext*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
301 0, /*tp_methods*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
302 0, /*tp_members*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
303 0, /*tp_getset*/
44119
64582083cb9a I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
304 0, /* see initxx */ /*tp_base*/
27873
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
305 0, /*tp_dict*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
306 0, /*tp_descr_get*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
307 0, /*tp_descr_set*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
308 0, /*tp_dictoffset*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
309 0, /*tp_init*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
310 0, /*tp_alloc*/
44119
64582083cb9a I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
311 0, /* see initxx */ /*tp_new*/
27873
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
312 0, /*tp_free*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
313 0, /*tp_is_gc*/
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
314 };
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
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[] = {
24804
30cff9c1bf69 add PyDoc_STR and PyDoc_STRVAR calls as examples for module authors
Skip Montanaro <skip@pobox.com>
parents: 24471
diff changeset
323 {"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
324 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
325 {"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
326 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
327 {"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
328 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
329 {"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
330 PyDoc_STR("bug(o) -> None")},
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 {NULL, NULL} /* sentinel */
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 {
22910
99001fd95e48 Fix an obvious bug.
Thomas Heller <theller@ctypes.org>
parents: 22257
diff changeset
342 PyObject *m;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343
44119
64582083cb9a I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
344 /* Due to cross platform compiler issues the slots must be filled
64582083cb9a I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
345 * here. It's required for portability to Windows without requiring
64582083cb9a I followed MA Lemberg's suggestion and added comments to the late initialization of the type slots.
Christian Heimes <christian@cheimes.de>
parents: 44117
diff changeset
346 * C++. */
44117
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
347 Null_Type.tp_base = &PyBaseObject_Type;
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
348 Null_Type.tp_new = PyType_GenericNew;
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
349 Str_Type.tp_base = &PyUnicode_Type;
ead0d47b012b Applied my patch #1455 with some extra fixes for VS 2005
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
350
26822
fea92e7ec67a Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents: 24804
diff changeset
351 /* Finalize the type object including setting type of the new type
44278
9929782f5cb4 Fixed a nasty problem in the xxmodule.c
Christian Heimes <christian@cheimes.de>
parents: 44119
diff changeset
352 * object; doing it here is required for portability, too. */
26822
fea92e7ec67a Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents: 24804
diff changeset
353 if (PyType_Ready(&Xxo_Type) < 0)
fea92e7ec67a Demonstrate use of PyType_Ready() in the example.
Raymond Hettinger <python@rcn.com>
parents: 24804
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
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 /* 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
357 m = Py_InitModule3("xx", xx_methods, module_doc);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27873
diff changeset
358 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27873
diff changeset
359 return;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
360
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 /* 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
362 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
363 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
364 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
365 return;
aa3bf525f482 Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents: 21313
diff changeset
366 }
aa3bf525f482 Change the example code to prefer PyModule_Add*() instead of using the
Fred Drake <fdrake@acm.org>
parents: 21313
diff changeset
367 Py_INCREF(ErrorObject);
22910
99001fd95e48 Fix an obvious bug.
Thomas Heller <theller@ctypes.org>
parents: 22257
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
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
370 /* Add Str */
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
371 if (PyType_Ready(&Str_Type) < 0)
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
372 return;
651d1123ed6e Add Str, a subclass of str.
Guido van Rossum <guido@python.org>
parents: 26822
diff changeset
373 PyModule_AddObject(m, "Str", (PyObject *)&Str_Type);
27873
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
374
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
375 /* Add Null */
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
376 if (PyType_Ready(&Null_Type) < 0)
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
diff changeset
377 return;
88a42a7c238a Another dummy type.
Guido van Rossum <guido@python.org>
parents: 27823
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 }