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

Skip to content

Commit ebed751

Browse files
committed
Templates converted to new naming conventions (thanks to Chak Tan)
1 parent 52e0299 commit ebed751

17 files changed

Lines changed: 100 additions & 131 deletions

Tools/modulator/README

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
This is release 1.0 of modulator, a generator of boilerplate code for
1+
This is release 1.1 of modulator, a generator of boilerplate code for
22
modules to be written in C.
33

4-
Usage when you have tk is *reall* simple: start modulator, fill out
4+
There is only one difference with release 1.0, really: the templates
5+
now use "new-style" naming conventions. Many thanks to Chak Tan
6+
<[email protected]> for supplying them.
7+
8+
Usage when you have tk is *really* simple: start modulator, fill out
59
the forms specifying all the objects and methods, tell modulator
610
whether objects should also be accessible as sequences, etc and press
711
'generate code'. It will write a complete skeleton module for you.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
#include "allobjects.h"
3-
#include "modsupport.h" /* For getargs() etc. */
2+
#include "Python.h"
3+
/* #include "modsupport.h" /* For getargs() etc. */
44

5-
static object *ErrorObject;
5+
static PyObject *ErrorObject;
66

77
/* ----------------------------------------------------- */
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
static object *
2+
static PyObject *
33
$abbrev$_$method$(self, args)
4-
object *self; /* Not used */
5-
object *args;
4+
PyObject *self; /* Not used */
5+
PyObject *args;
66
{
77

8-
if (!newgetargs(args, ""))
8+
if (!PyArg_ParseTuple(args, ""))
99
return NULL;
10-
INCREF(None);
11-
return None;
10+
Py_INCREF(Py_None);
11+
return Py_None;
1212
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
/* List of methods defined in the module */
33

4-
static struct methodlist $abbrev$_methods[] = {
5-
$methodlist$
6-
{NULL, NULL} /* sentinel */
4+
static struct PyMethodDef $abbrev$_methods[] = {
5+
$methodlist$
6+
{NULL, NULL} /* sentinel */
77
};
88

99

@@ -12,19 +12,20 @@ static struct methodlist $abbrev$_methods[] = {
1212
void
1313
init$name$()
1414
{
15-
object *m, *d;
15+
PyObject *m, *d;
1616

1717
/* Create the module and add the functions */
18-
m = initmodule("$name$", $abbrev$_methods);
18+
m = Py_InitModule("$name$", $abbrev$_methods);
1919

2020
/* Add some symbolic constants to the module */
21-
d = getmoduledict(m);
22-
ErrorObject = newstringobject("$name$.error");
23-
dictinsert(d, "error", ErrorObject);
21+
d = PyModule_GetDict(m);
22+
ErrorObject = PyString_FromString("$name$.error");
23+
PyDict_SetItemString(d, "error", ErrorObject);
2424

2525
/* XXXX Add constants here */
2626

2727
/* Check for errors */
28-
if (err_occurred())
29-
fatal("can't initialize module $name$");
28+
if (PyErr_Occurred())
29+
Py_FatalError("can't initialize module $name$");
3030
}
31+
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
12
/* Declarations for objects of type $name$ */
23

34
typedef struct {
4-
OB_HEAD
5+
PyObject_HEAD
56
/* XXXX Add your own stuff here */
67
} $abbrev$object;
78

8-
staticforward typeobject $Abbrev$type;
9+
staticforward PyTypeObject $Abbrev$type;
10+
911

10-
#define is_$abbrev$object(v) ((v)->ob_type == &$Abbrev$type)
1112

1213
/* ---------------------------------------------------------------- */
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11

2-
static object *
2+
static PyObject *
33
$abbrev$_$method$(self, args)
44
$abbrev$object *self;
5-
object *args;
5+
PyObject *args;
66
{
7-
if (!newgetargs(args, ""))
7+
if (!PyArg_ParseTuple(args, ""))
88
return NULL;
9-
INCREF(None);
10-
return None;
9+
Py_INCREF(Py_None);
10+
return Py_None;
1111
}
12+
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
static struct methodlist $abbrev$_methods[] = {
3-
$methodlist$
4-
{NULL, NULL} /* sentinel */
2+
static struct PyMethodDef $abbrev$_methods[] = {
3+
$methodlist$
4+
{NULL, NULL} /* sentinel */
55
};
66

77
/* ---------- */
8+

Tools/modulator/Templates/object_new

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ new$abbrev$object()
44
{
55
$abbrev$object *self;
66

7-
self = NEWOBJ($abbrev$object, &$Abbrev$type);
7+
self = PyObject_NEW($abbrev$object, &$Abbrev$type);
88
if (self == NULL)
99
return NULL;
1010
/* XXXX Add your own initializers here */
1111
return self;
1212
}
13+

Tools/modulator/Templates/object_structure

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/* Code to access structure members by accessing attributes */
23

34
#include "structmember.h"
@@ -6,36 +7,36 @@
67

78
static struct memberlist $abbrev$_memberlist[] = {
89
/* XXXX Add lines like { "foo", T_INT, OFF(foo), RO } */
10+
911
{NULL} /* Sentinel */
1012
};
1113

12-
static object *
14+
static PyObject *
1315
$abbrev$_getattr(self, name)
1416
$abbrev$object *self;
1517
char *name;
1618
{
17-
object *rv;
19+
PyObject *rv;
1820

1921
/* XXXX Add your own getattr code here */
20-
rv = getmember((char *)/*XXXX*/0, $abbrev$_memberlist, name);
22+
rv = PyMember_Get((char *)/*XXXX*/0, $abbrev$_memberlist, name);
2123
if (rv)
2224
return rv;
23-
err_clear();
24-
return findmethod($abbrev$_methods, (object *)self, name);
25+
PyErr_Clear();
26+
return Py_FindMethod($abbrev$_methods, (PyObject *)self, name);
2527
}
2628

2729

2830
static int
2931
$abbrev$_setattr(self, name, v)
3032
$abbrev$object *self;
3133
char *name;
32-
object *v;
34+
PyObject *v;
3335
{
3436
/* XXXX Add your own setattr code here */
3537
if ( v == NULL ) {
36-
err_setstr(AttributeError, "Cannot delete attribute");
38+
PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
3739
return -1;
3840
}
39-
return setmember((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
41+
return PyMember_Set((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
4042
}
41-

Tools/modulator/Templates/object_tail

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
static typeobject $Abbrev$type = {
3-
OB_HEAD_INIT(&Typetype)
2+
static PyTypeObject $Abbrev$type = {
3+
PyObject_HEAD_INIT(&PyType_Type)
44
0, /*ob_size*/
55
"$name$", /*tp_name*/
66
sizeof($abbrev$object), /*tp_basicsize*/
@@ -20,3 +20,4 @@ static typeobject $Abbrev$type = {
2020

2121
/* End of code for $name$ objects */
2222
/* -------------------------------------------------------- */
23+

0 commit comments

Comments
 (0)