]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Templates converted to new naming conventions (thanks to Chak Tan)
authorJack Jansen <jack.jansen@cwi.nl>
Tue, 16 May 1995 13:47:03 +0000 (13:47 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Tue, 16 May 1995 13:47:03 +0000 (13:47 +0000)
17 files changed:
Tools/modulator/README
Tools/modulator/Templates/module_head
Tools/modulator/Templates/module_method
Tools/modulator/Templates/module_tail
Tools/modulator/Templates/object_head
Tools/modulator/Templates/object_method
Tools/modulator/Templates/object_mlist
Tools/modulator/Templates/object_new
Tools/modulator/Templates/object_structure
Tools/modulator/Templates/object_tail
Tools/modulator/Templates/object_tp_as_mapping
Tools/modulator/Templates/object_tp_as_number
Tools/modulator/Templates/object_tp_as_sequence
Tools/modulator/Templates/object_tp_dealloc
Tools/modulator/Templates/object_tp_getattr
Tools/modulator/Templates/object_tp_repr
Tools/modulator/Templates/object_tp_setattr

index 7ed09c8ea54dfd7f61ac0b0e6092b2345ec070ce..def9cb5e2e81cef3ec98e1c53c48cc37b3ca02a0 100644 (file)
@@ -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.
index d1fafdc37b2d46412e15e8a9137192edba50db15..329b6125886ff29f38ae24ef212946fecb821143 100644 (file)
@@ -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;
 
 /* ----------------------------------------------------- */
index bf64e79f8aae9cbbfedbfabbcd664f45a49d9047..53cc1ac605b187bf28a55d5d9b4fbc76c6b627b2 100644 (file)
@@ -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;
 }
index 466c84a3767dfbfbb7be5782251e20b75af82036..8af75db9d65ac0c053aacdf17822feb7df0a75cb 100644 (file)
@@ -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$");
 }
+
index bf69a516c58e872f6c13e2b5acf5a89e97f68013..9e6fa5eeac039e5b556849a118b483b87e3d21dd 100644 (file)
@@ -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)
 
 /* ---------------------------------------------------------------- */
index 20896de7119a30864c2d61f9896a02cdf55613dc..7ff5cea4efd5be26ff3d93f7d9c3ec2246a7b74b 100644 (file)
@@ -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;
 }
+
index 62d5894c8a6285552f40123b6c870e8cfa183709..a12a9e1be18726c567a78cd4b242f03758f0329b 100644 (file)
@@ -1,7 +1,8 @@
 
-static struct methodlist $abbrev$_methods[] = {
- $methodlist$
{NULL,                NULL}           /* sentinel */
+static struct PyMethodDef $abbrev$_methods[] = {
      $methodlist$
      {NULL,          NULL}           /* sentinel */
 };
 
 /* ---------- */
+
index 1817a5516adf5ce9d166aa072d0bec5669c80c5d..30c5e363e61c61f8570a1a14b3fda01fd1b6885b 100644 (file)
@@ -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;
 }
+
index 6a54518643bae80a3e794abd6ac1d150eb601e93..4bb92ef7f19723705e3aa7fdec12ebd172bf9c06 100644 (file)
@@ -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);
 }
-
index 9bc78ca281da8dabcf90f325f2994ef816cf1711..4803ea5542a22e350b6de05c3dbf9a2cd6a3eda4 100644 (file)
@@ -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 */
 /* -------------------------------------------------------- */
+
index c5edf3ea0a1e525d5a905dfacf7b9a0a0631ea32..440904f56adf31aeddf216a4cccf52a924d52c60 100644 (file)
@@ -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*/
index b97d473520677ef7890335391e4f225361ffe267..2f90edc2f5020d1bf83b815f47f3644e437047c8 100644 (file)
+
 /* 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*/
index 50f2f9173f0e429ff27453a5a65164cae3771dc2..bc0f470262d9b2e1d7cc7797b25c8e4d2af00a5b 100644 (file)
@@ -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*/
index b4d573ef3257a0042bff7be45c4fe74f875f10ff..ca15c0359dfc48bea3bd59ad1987c421f32d98c5 100644 (file)
@@ -4,5 +4,5 @@ $abbrev$_dealloc(self)
        $abbrev$object *self;
 {
        /* XXXX Add your own cleanup code here */
-       DEL(self);
+       PyMem_DEL(self);
 }
index 3e5542ffd90d429b2913fddd465dea3d976cb4b3..8e42aea964d27131401c83cd89acb7262d312724 100644 (file)
@@ -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);
 }
index 45c78dfd5603dbef3d715969077a81bd3c945bf4..16aebc74277dca413b8c36d2d0f171755b6fc3b5 100644 (file)
@@ -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;
index d4da0ce61aca2fd5dbabf461c1dfcf7d423eec39..2e47f5f8b7c7ad445d2f5fb50f45805723492711 100644 (file)
@@ -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;