Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2eadc6

Browse files
author
Jim Fulton
committed
Updated simple example. This should have been checked in the other
day, but I missfired in CVS.
1 parent 7af9f4d commit d2eadc6

1 file changed

Lines changed: 45 additions & 45 deletions

File tree

Doc/ext/noddy.c

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
#include <Python.h>
22

3-
static PyTypeObject noddy_NoddyType;
4-
53
typedef struct {
64
PyObject_HEAD
75
/* Type-specific fields go here. */
86
} noddy_NoddyObject;
97

10-
static PyObject*
11-
noddy_new_noddy(PyObject* self, PyObject* args)
12-
{
13-
noddy_NoddyObject* noddy;
14-
15-
noddy = PyObject_New(noddy_NoddyObject, &noddy_NoddyType);
16-
17-
/* Initialize type-specific fields here. */
18-
19-
return (PyObject*)noddy;
20-
}
21-
22-
static void
23-
noddy_noddy_dealloc(PyObject* self)
24-
{
25-
/* Free any external resources here;
26-
* if the instance owns references to any Python
27-
* objects, call Py_DECREF() on them here.
28-
*/
29-
PyObject_Del(self);
30-
}
31-
328
static PyTypeObject noddy_NoddyType = {
339
PyObject_HEAD_INIT(NULL)
34-
0,
35-
"Noddy",
36-
sizeof(noddy_NoddyObject),
37-
0,
38-
noddy_noddy_dealloc, /*tp_dealloc*/
39-
0, /*tp_print*/
40-
0, /*tp_getattr*/
41-
0, /*tp_setattr*/
42-
0, /*tp_compare*/
43-
0, /*tp_repr*/
44-
0, /*tp_as_number*/
45-
0, /*tp_as_sequence*/
46-
0, /*tp_as_mapping*/
47-
0, /*tp_hash */
10+
0, /*ob_size*/
11+
"noddy.Noddy", /*tp_name*/
12+
sizeof(noddy_NoddyObject), /*tp_basicsize*/
13+
0, /*tp_itemsize*/
14+
0, /*tp_dealloc*/
15+
0, /*tp_print*/
16+
0, /*tp_getattr*/
17+
0, /*tp_setattr*/
18+
0, /*tp_compare*/
19+
0, /*tp_repr*/
20+
0, /*tp_as_number*/
21+
0, /*tp_as_sequence*/
22+
0, /*tp_as_mapping*/
23+
0, /*tp_hash */
24+
0, /*tp_call*/
25+
0, /*tp_str*/
26+
0, /*tp_getattro*/
27+
0, /*tp_setattro*/
28+
0, /*tp_as_buffer*/
29+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
30+
"Noddy objects", /* tp_doc */
31+
0, /* tp_traverse */
32+
0, /* tp_clear */
33+
0, /* tp_richcompare */
34+
0, /* tp_weaklistoffset */
35+
0, /* tp_iter */
36+
0, /* tp_iternext */
37+
0, /* tp_methods */
38+
0, /* tp_members */
39+
0, /* tp_getset */
40+
0, /* tp_base */
41+
0, /* tp_dict */
42+
0, /* tp_descr_get */
43+
0, /* tp_descr_set */
44+
0, /* tp_dictoffset */
45+
0, /* tp_init */
46+
0, /* tp_alloc */
47+
PyType_GenericNew, /* tp_new */
4848
};
4949

5050
static PyMethodDef noddy_methods[] = {
51-
{"new_noddy", noddy_new_noddy, METH_NOARGS,
52-
"Create a new Noddy object."},
53-
5451
{NULL} /* Sentinel */
5552
};
5653

5754
PyMODINIT_FUNC
5855
initnoddy(void)
5956
{
60-
noddy_NoddyType.ob_type = &PyType_Type;
61-
if (PyType_Ready(&noddy_NoddyType))
57+
PyObject* m;
58+
59+
if (PyType_Ready(&noddy_NoddyType) < 0)
6260
return;
6361

64-
Py_InitModule3("noddy", noddy_methods
65-
"Example module that creates an extension type.");
62+
m = Py_InitModule3("noddy", noddy_methods,
63+
"Example module that creates an extension type.");
64+
65+
PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType);
6666
}

0 commit comments

Comments
 (0)