Kaydet (Commit) ebed7511 authored tarafından Jack Jansen's avatar Jack Jansen

Templates converted to new naming conventions (thanks to Chak Tan)

üst 52e02998
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.
......
#include "allobjects.h"
#include "modsupport.h" /* For getargs() etc. */
#include "Python.h"
/* #include "modsupport.h" /* For getargs() etc. */
static object *ErrorObject;
static PyObject *ErrorObject;
/* ----------------------------------------------------- */
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;
}
/* 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$");
}
/* 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)
/* ---------------------------------------------------------------- */
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;
}
static struct methodlist $abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
static struct PyMethodDef $abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
};
/* ---------- */
......@@ -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;
}
/* 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);
}
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 */
/* -------------------------------------------------------- */
/* 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*/
......
/* 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*/
......
......@@ -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*/
......
......@@ -4,5 +4,5 @@ $abbrev$_dealloc(self)
$abbrev$object *self;
{
/* XXXX Add your own cleanup code here */
DEL(self);
PyMem_DEL(self);
}
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);
}
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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment