summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1995-05-16 13:47:03 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1995-05-16 13:47:03 (GMT)
commitebed75116fcd1ebc4737c4ba77b9b74c8b032742 (patch)
treeee10da97ba30b2d0740ce01eef71aa8d74c1b19e /Tools
parent52e02998ef9d0c5643cf037f2db3cc5cf7c8c451 (diff)
downloadcpython-ebed75116fcd1ebc4737c4ba77b9b74c8b032742.zip
cpython-ebed75116fcd1ebc4737c4ba77b9b74c8b032742.tar.gz
cpython-ebed75116fcd1ebc4737c4ba77b9b74c8b032742.tar.bz2
Templates converted to new naming conventions (thanks to Chak Tan)
Diffstat (limited to 'Tools')
-rw-r--r--Tools/modulator/README8
-rw-r--r--Tools/modulator/Templates/module_head6
-rw-r--r--Tools/modulator/Templates/module_method12
-rw-r--r--Tools/modulator/Templates/module_tail21
-rw-r--r--Tools/modulator/Templates/object_head7
-rw-r--r--Tools/modulator/Templates/object_method11
-rw-r--r--Tools/modulator/Templates/object_mlist7
-rw-r--r--Tools/modulator/Templates/object_new3
-rw-r--r--Tools/modulator/Templates/object_structure19
-rw-r--r--Tools/modulator/Templates/object_tail5
-rw-r--r--Tools/modulator/Templates/object_tp_as_mapping9
-rw-r--r--Tools/modulator/Templates/object_tp_as_number93
-rw-r--r--Tools/modulator/Templates/object_tp_as_sequence18
-rw-r--r--Tools/modulator/Templates/object_tp_dealloc2
-rw-r--r--Tools/modulator/Templates/object_tp_getattr4
-rw-r--r--Tools/modulator/Templates/object_tp_repr4
-rw-r--r--Tools/modulator/Templates/object_tp_setattr2
17 files changed, 100 insertions, 131 deletions
diff --git a/Tools/modulator/README b/Tools/modulator/README
index 7ed09c8..def9cb5 100644
--- a/Tools/modulator/README
+++ b/Tools/modulator/README
@@ -1,7 +1,11 @@
-This is release 1.0 of modulator, a generator of boilerplate code for
+This is release 1.1 of modulator, a generator of boilerplate code for
modules to be written in C.
-Usage when you have tk is *reall* simple: start modulator, fill out
+There is only one difference with release 1.0, really: the templates
+now use "new-style" naming conventions. Many thanks to Chak Tan
+<tan@ee.rochester.edu> for supplying them.
+
+Usage when you have tk is *really* simple: start modulator, fill out
the forms specifying all the objects and methods, tell modulator
whether objects should also be accessible as sequences, etc and press
'generate code'. It will write a complete skeleton module for you.
diff --git a/Tools/modulator/Templates/module_head b/Tools/modulator/Templates/module_head
index d1fafdc..329b612 100644
--- a/Tools/modulator/Templates/module_head
+++ b/Tools/modulator/Templates/module_head
@@ -1,7 +1,7 @@
-#include "allobjects.h"
-#include "modsupport.h" /* For getargs() etc. */
+#include "Python.h"
+/* #include "modsupport.h" /* For getargs() etc. */
-static object *ErrorObject;
+static PyObject *ErrorObject;
/* ----------------------------------------------------- */
diff --git a/Tools/modulator/Templates/module_method b/Tools/modulator/Templates/module_method
index bf64e79..53cc1ac 100644
--- a/Tools/modulator/Templates/module_method
+++ b/Tools/modulator/Templates/module_method
@@ -1,12 +1,12 @@
-static object *
+static PyObject *
$abbrev$_$method$(self, args)
- object *self; /* Not used */
- object *args;
+ PyObject *self; /* Not used */
+ PyObject *args;
{
- if (!newgetargs(args, ""))
+ if (!PyArg_ParseTuple(args, ""))
return NULL;
- INCREF(None);
- return None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
diff --git a/Tools/modulator/Templates/module_tail b/Tools/modulator/Templates/module_tail
index 466c84a..8af75db 100644
--- a/Tools/modulator/Templates/module_tail
+++ b/Tools/modulator/Templates/module_tail
@@ -1,9 +1,9 @@
/* List of methods defined in the module */
-static struct methodlist $abbrev$_methods[] = {
- $methodlist$
- {NULL, NULL} /* sentinel */
+static struct PyMethodDef $abbrev$_methods[] = {
+ $methodlist$
+ {NULL, NULL} /* sentinel */
};
@@ -12,19 +12,20 @@ static struct methodlist $abbrev$_methods[] = {
void
init$name$()
{
- object *m, *d;
+ PyObject *m, *d;
/* Create the module and add the functions */
- m = initmodule("$name$", $abbrev$_methods);
+ m = Py_InitModule("$name$", $abbrev$_methods);
/* Add some symbolic constants to the module */
- d = getmoduledict(m);
- ErrorObject = newstringobject("$name$.error");
- dictinsert(d, "error", ErrorObject);
+ d = PyModule_GetDict(m);
+ ErrorObject = PyString_FromString("$name$.error");
+ PyDict_SetItemString(d, "error", ErrorObject);
/* XXXX Add constants here */
/* Check for errors */
- if (err_occurred())
- fatal("can't initialize module $name$");
+ if (PyErr_Occurred())
+ Py_FatalError("can't initialize module $name$");
}
+
diff --git a/Tools/modulator/Templates/object_head b/Tools/modulator/Templates/object_head
index bf69a51..9e6fa5e 100644
--- a/Tools/modulator/Templates/object_head
+++ b/Tools/modulator/Templates/object_head
@@ -1,12 +1,13 @@
+
/* Declarations for objects of type $name$ */
typedef struct {
- OB_HEAD
+ PyObject_HEAD
/* XXXX Add your own stuff here */
} $abbrev$object;
-staticforward typeobject $Abbrev$type;
+staticforward PyTypeObject $Abbrev$type;
+
-#define is_$abbrev$object(v) ((v)->ob_type == &$Abbrev$type)
/* ---------------------------------------------------------------- */
diff --git a/Tools/modulator/Templates/object_method b/Tools/modulator/Templates/object_method
index 20896de..7ff5cea 100644
--- a/Tools/modulator/Templates/object_method
+++ b/Tools/modulator/Templates/object_method
@@ -1,11 +1,12 @@
-static object *
+static PyObject *
$abbrev$_$method$(self, args)
$abbrev$object *self;
- object *args;
+ PyObject *args;
{
- if (!newgetargs(args, ""))
+ if (!PyArg_ParseTuple(args, ""))
return NULL;
- INCREF(None);
- return None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
+
diff --git a/Tools/modulator/Templates/object_mlist b/Tools/modulator/Templates/object_mlist
index 62d5894..a12a9e1 100644
--- a/Tools/modulator/Templates/object_mlist
+++ b/Tools/modulator/Templates/object_mlist
@@ -1,7 +1,8 @@
-static struct methodlist $abbrev$_methods[] = {
- $methodlist$
- {NULL, NULL} /* sentinel */
+static struct PyMethodDef $abbrev$_methods[] = {
+ $methodlist$
+ {NULL, NULL} /* sentinel */
};
/* ---------- */
+
diff --git a/Tools/modulator/Templates/object_new b/Tools/modulator/Templates/object_new
index 1817a55..30c5e36 100644
--- a/Tools/modulator/Templates/object_new
+++ b/Tools/modulator/Templates/object_new
@@ -4,9 +4,10 @@ new$abbrev$object()
{
$abbrev$object *self;
- self = NEWOBJ($abbrev$object, &$Abbrev$type);
+ self = PyObject_NEW($abbrev$object, &$Abbrev$type);
if (self == NULL)
return NULL;
/* XXXX Add your own initializers here */
return self;
}
+
diff --git a/Tools/modulator/Templates/object_structure b/Tools/modulator/Templates/object_structure
index 6a54518..4bb92ef 100644
--- a/Tools/modulator/Templates/object_structure
+++ b/Tools/modulator/Templates/object_structure
@@ -1,3 +1,4 @@
+
/* Code to access structure members by accessing attributes */
#include "structmember.h"
@@ -6,22 +7,23 @@
static struct memberlist $abbrev$_memberlist[] = {
/* XXXX Add lines like { "foo", T_INT, OFF(foo), RO } */
+
{NULL} /* Sentinel */
};
-static object *
+static PyObject *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
{
- object *rv;
+ PyObject *rv;
/* XXXX Add your own getattr code here */
- rv = getmember((char *)/*XXXX*/0, $abbrev$_memberlist, name);
+ rv = PyMember_Get((char *)/*XXXX*/0, $abbrev$_memberlist, name);
if (rv)
return rv;
- err_clear();
- return findmethod($abbrev$_methods, (object *)self, name);
+ PyErr_Clear();
+ return Py_FindMethod($abbrev$_methods, (PyObject *)self, name);
}
@@ -29,13 +31,12 @@ static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
- object *v;
+ PyObject *v;
{
/* XXXX Add your own setattr code here */
if ( v == NULL ) {
- err_setstr(AttributeError, "Cannot delete attribute");
+ PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
return -1;
}
- return setmember((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
+ return PyMember_Set((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
}
-
diff --git a/Tools/modulator/Templates/object_tail b/Tools/modulator/Templates/object_tail
index 9bc78ca..4803ea5 100644
--- a/Tools/modulator/Templates/object_tail
+++ b/Tools/modulator/Templates/object_tail
@@ -1,6 +1,6 @@
-static typeobject $Abbrev$type = {
- OB_HEAD_INIT(&Typetype)
+static PyTypeObject $Abbrev$type = {
+ PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"$name$", /*tp_name*/
sizeof($abbrev$object), /*tp_basicsize*/
@@ -20,3 +20,4 @@ static typeobject $Abbrev$type = {
/* End of code for $name$ objects */
/* -------------------------------------------------------- */
+
diff --git a/Tools/modulator/Templates/object_tp_as_mapping b/Tools/modulator/Templates/object_tp_as_mapping
index c5edf3e..440904f 100644
--- a/Tools/modulator/Templates/object_tp_as_mapping
+++ b/Tools/modulator/Templates/object_tp_as_mapping
@@ -1,3 +1,4 @@
+
/* Code to access $name$ objects as mappings */
static int
@@ -7,10 +8,10 @@ $abbrev$_length(self)
/* XXXX Return the size of the mapping */
}
-static object *
+static PyObject *
$abbrev$_subscript(self, key)
$abbrev$object *self;
- object *key;
+ PyObject *key;
{
/* XXXX Return the item of self indexed by key */
}
@@ -18,13 +19,13 @@ $abbrev$_subscript(self, key)
static int
$abbrev$_ass_sub(self, v, w)
$abbrev$object *self;
- object *v, *w;
+ PyObject *v, *w;
{
/* XXXX Put w in self under key v */
return 0;
}
-static mapping_methods $abbrev$_as_mapping = {
+static PyMappingMethods $abbrev$_as_mapping = {
(inquiry)$abbrev$_length, /*mp_length*/
(binaryfunc)$abbrev$_subscript, /*mp_subscript*/
(objobjargproc)$abbrev$_ass_sub, /*mp_ass_subscript*/
diff --git a/Tools/modulator/Templates/object_tp_as_number b/Tools/modulator/Templates/object_tp_as_number
index b97d473..2f90edc 100644
--- a/Tools/modulator/Templates/object_tp_as_number
+++ b/Tools/modulator/Templates/object_tp_as_number
@@ -1,101 +1,82 @@
+
/* Code to access $name$ objects as numbers */
-static object *
+static PyObject *
$abbrev$_add(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Add them */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_sub(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Subtract them */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_mul(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Multiply them */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_div(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Divide them */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_mod(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Modulo them */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_divmod(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Return 2-tuple with div and mod */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_pow(v, w, z)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$object *z;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_neg(v)
$abbrev$object *v;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_pos(v)
$abbrev$object *v;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_abs(v)
$abbrev$object *v;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
static int
@@ -103,124 +84,100 @@ $abbrev$_nonzero(v)
$abbrev$object *v;
{
/* XXXX Return 1 if non-zero */
- err_setstr(SystemError, "not implemented");
- return -1;
}
-static object *
+static PyObject *
$abbrev$_invert(v)
$abbrev$object *v;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_lshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_rshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_and(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_xor(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_or(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
static int
$abbrev$_coerce(pv, pw)
- object **pv;
- object **pw;
+ PyObject **pv;
+ PyObject **pw;
{
/* XXXX I haven't a clue... */
return 1;
}
-static object *
+static PyObject *
$abbrev$_int(v)
$abbrev$object *v;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_long(v)
$abbrev$object *v;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_float(v)
$abbrev$object *v;
{
/* XXXX */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_oct(v)
$abbrev$object *v;
{
/* XXXX Return object as octal stringobject */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static object *
+static PyObject *
$abbrev$_hex(v)
$abbrev$object *v;
{
/* XXXX Return object as hex stringobject */
- err_setstr(SystemError, "not implemented");
- return NULL;
}
-static number_methods $abbrev$_as_number = {
+static PyNumberMethods $abbrev$_as_number = {
(binaryfunc)$abbrev$_add, /*nb_add*/
(binaryfunc)$abbrev$_sub, /*nb_subtract*/
(binaryfunc)$abbrev$_mul, /*nb_multiply*/
diff --git a/Tools/modulator/Templates/object_tp_as_sequence b/Tools/modulator/Templates/object_tp_as_sequence
index 50f2f91..bc0f470 100644
--- a/Tools/modulator/Templates/object_tp_as_sequence
+++ b/Tools/modulator/Templates/object_tp_as_sequence
@@ -8,15 +8,15 @@ $abbrev$_length(self)
/* XXXX Return the size of the object */
}
-static object *
+static PyObject *
$abbrev$_concat(self, bb)
$abbrev$object *self;
- object *bb;
+ PyObject *bb;
{
/* XXXX Return the concatenation of self and bb */
}
-static object *
+static PyObject *
$abbrev$_repeat(self, n)
$abbrev$object *self;
int n;
@@ -24,7 +24,7 @@ $abbrev$_repeat(self, n)
/* XXXX Return a new object that is n times self */
}
-static object *
+static PyObject *
$abbrev$_item(self, i)
$abbrev$object *self;
int i;
@@ -32,7 +32,7 @@ $abbrev$_item(self, i)
/* XXXX Return the i-th object of self */
}
-static object *
+static PyObject *
$abbrev$_slice(self, ilow, ihigh)
$abbrev$object *self;
int ilow, ihigh;
@@ -44,7 +44,7 @@ static int
$abbrev$_ass_item(self, i, v)
$abbrev$object *self;
int i;
- object *v;
+ PyObject *v;
{
/* XXXX Assign to the i-th element of self */
return 0;
@@ -52,15 +52,15 @@ $abbrev$_ass_item(self, i, v)
static int
$abbrev$_ass_slice(self, ilow, ihigh, v)
- listobject *self;
+ PyListObject *self;
int ilow, ihigh;
- object *v;
+ PyObject *v;
{
/* XXXX Replace ilow..ihigh slice of self with v */
return 0;
}
-static sequence_methods $abbrev$_as_sequence = {
+static PySequenceMethods $abbrev$_as_sequence = {
(inquiry)$abbrev$_length, /*sq_length*/
(binaryfunc)$abbrev$_concat, /*sq_concat*/
(intargfunc)$abbrev$_repeat, /*sq_repeat*/
diff --git a/Tools/modulator/Templates/object_tp_dealloc b/Tools/modulator/Templates/object_tp_dealloc
index b4d573e..ca15c03 100644
--- a/Tools/modulator/Templates/object_tp_dealloc
+++ b/Tools/modulator/Templates/object_tp_dealloc
@@ -4,5 +4,5 @@ $abbrev$_dealloc(self)
$abbrev$object *self;
{
/* XXXX Add your own cleanup code here */
- DEL(self);
+ PyMem_DEL(self);
}
diff --git a/Tools/modulator/Templates/object_tp_getattr b/Tools/modulator/Templates/object_tp_getattr
index 3e5542f..8e42aea 100644
--- a/Tools/modulator/Templates/object_tp_getattr
+++ b/Tools/modulator/Templates/object_tp_getattr
@@ -1,9 +1,9 @@
-static object *
+static PyObject *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
{
/* XXXX Add your own getattr code here */
- return findmethod($abbrev$_methods, (object *)self, name);
+ return Py_FindMethod($abbrev$_methods, (PyObject *)self, name);
}
diff --git a/Tools/modulator/Templates/object_tp_repr b/Tools/modulator/Templates/object_tp_repr
index 45c78df..16aebc7 100644
--- a/Tools/modulator/Templates/object_tp_repr
+++ b/Tools/modulator/Templates/object_tp_repr
@@ -1,9 +1,9 @@
-static object *
+static PyObject *
$abbrev$_repr(self)
$abbrev$object *self;
{
- object *s;
+ PyObject *s;
/* XXXX Add code here to put self into s */
return s;
diff --git a/Tools/modulator/Templates/object_tp_setattr b/Tools/modulator/Templates/object_tp_setattr
index d4da0ce..2e47f5f 100644
--- a/Tools/modulator/Templates/object_tp_setattr
+++ b/Tools/modulator/Templates/object_tp_setattr
@@ -3,7 +3,7 @@ static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
- object *v;
+ PyObject *v;
{
/* XXXX Add your own setattr code here */
return -1;