]> granicus.if.org Git - python/commitdiff
Patches by Jens B. Jorgensen with small mods by me:
authorJack Jansen <jack.jansen@cwi.nl>
Thu, 27 Dec 2001 23:35:43 +0000 (23:35 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Thu, 27 Dec 2001 23:35:43 +0000 (23:35 +0000)
- Converted the templates to use ANSI C prototypes (finally!)
- Use re in stead of deprecated regex

17 files changed:
Tools/modulator/Templates/module_method
Tools/modulator/Templates/object_method
Tools/modulator/Templates/object_structure
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_call
Tools/modulator/Templates/object_tp_compare
Tools/modulator/Templates/object_tp_dealloc
Tools/modulator/Templates/object_tp_getattr
Tools/modulator/Templates/object_tp_hash
Tools/modulator/Templates/object_tp_print
Tools/modulator/Templates/object_tp_repr
Tools/modulator/Templates/object_tp_setattr
Tools/modulator/Templates/object_tp_str
Tools/modulator/modulator.py
Tools/modulator/varsubst.py

index 9e6c0d2c12fcf3b84fd11c39a455c2e655d5a00d..3048b1fc48d34189c533eb2f34e9432bc385f031 100644 (file)
@@ -4,9 +4,7 @@ static char $abbrev$_$method$__doc__[] =
 ;
 
 static PyObject *
-$abbrev$_$method$(self, args)
-       PyObject *self; /* Not used */
-       PyObject *args;
+$abbrev$_$method$(PyObject *self /* Not used */, PyObject *args)
 {
 
        if (!PyArg_ParseTuple(args, ""))
index 95414947c4032ab149024e489ba0e69f67145efa..b15162c317f3a390378795b9a3e5cb9908afa929 100644 (file)
@@ -4,9 +4,7 @@ static char $abbrev$_$method$__doc__[] =
 ;
 
 static PyObject *
-$abbrev$_$method$(self, args)
-       $abbrev$object *self;
-       PyObject *args;
+$abbrev$_$method$($abbrev$object *self, PyObject *args)
 {
        if (!PyArg_ParseTuple(args, ""))
                return NULL;
index 4bb92ef7f19723705e3aa7fdec12ebd172bf9c06..573ac8db9dca48c73eae4fde0562dbe0fb13a611 100644 (file)
@@ -12,9 +12,7 @@ static struct memberlist $abbrev$_memberlist[] = {
 };
 
 static PyObject *
-$abbrev$_getattr(self, name)
-       $abbrev$object *self;
-       char *name;
+$abbrev$_getattr($abbrev$object *self, char *name)
 {
        PyObject *rv;
        
@@ -28,10 +26,7 @@ $abbrev$_getattr(self, name)
 
 
 static int
-$abbrev$_setattr(self, name, v)
-       $abbrev$object *self;
-       char *name;
-       PyObject *v;
+$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v)
 {
        /* XXXX Add your own setattr code here */
        if ( v == NULL ) {
index 440904f56adf31aeddf216a4cccf52a924d52c60..f9213b70ef449ef0499d75432a945b5912ab016e 100644 (file)
@@ -2,24 +2,19 @@
 /* Code to access $name$ objects as mappings */
 
 static int
-$abbrev$_length(self)
-       $abbrev$object *self;
+$abbrev$_length($abbrev$object *self)
 {
        /* XXXX Return the size of the mapping */
 }
 
 static PyObject *
-$abbrev$_subscript(self, key)
-       $abbrev$object *self;
-       PyObject *key;
+$abbrev$_subscript($abbrev$object *self, PyObject *key)
 {
        /* XXXX Return the item of self indexed by key */
 }
 
 static int
-$abbrev$_ass_sub(self, v, w)
-       $abbrev$object *self;
-       PyObject *v, *w;
+$abbrev$_ass_sub($abbrev$object *self, PyObject *v, PyObject *w)
 {
        /* XXXX Put w in self under key v */
        return 0;
index 2f90edc2f5020d1bf83b815f47f3644e437047c8..e69aa9a556bc018b6837c09d5e3ac6d21431c522 100644 (file)
 /* Code to access $name$ objects as numbers */
 
 static PyObject *
-$abbrev$_add(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_add($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX Add them */
 }
 
 static PyObject *
-$abbrev$_sub(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_sub($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX Subtract them */
 }
 
 static PyObject *
-$abbrev$_mul(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_mul($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX Multiply them */
 }
 
 static PyObject *
-$abbrev$_div(x, y)
-       $abbrev$object *x;
-       $abbrev$object *y;
+$abbrev$_div($abbrev$object *x, $abbrev$object *y)
 {
        /* XXXX Divide them */
 }
 
 static PyObject *
-$abbrev$_mod(x, y)
-       $abbrev$object *x;
-       $abbrev$object *y;
+$abbrev$_mod($abbrev$object *x, $abbrev$object *y)
 {
        /* XXXX Modulo them */
 }
 
 static PyObject *
-$abbrev$_divmod(x, y)
-       $abbrev$object *x;
-       $abbrev$object *y;
+$abbrev$_divmod($abbrev$object *x, $abbrev$object *y)
 {
        /* XXXX Return 2-tuple with div and mod */
 }
 
 static PyObject *
-$abbrev$_pow(v, w, z)
-       $abbrev$object *v;
-       $abbrev$object *w;
-       $abbrev$object *z;
+$abbrev$_pow($abbrev$object *v, $abbrev$object *w, $abbrev$object *z)
 {
        /* XXXX */
 }                              
 
 static PyObject *
-$abbrev$_neg(v)
-       $abbrev$object *v;
+$abbrev$_neg($abbrev$object *v)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_pos(v)
-       $abbrev$object *v;
+$abbrev$_pos($abbrev$object *v)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_abs(v)
-       $abbrev$object *v;
+$abbrev$_abs($abbrev$object *v)
 {
        /* XXXX */
 }
 
 static int
-$abbrev$_nonzero(v)
-       $abbrev$object *v;
+$abbrev$_nonzero($abbrev$object *v)
 {
        /* XXXX Return 1 if non-zero */
 }
 
 static PyObject *
-$abbrev$_invert(v)
-       $abbrev$object *v;
+$abbrev$_invert($abbrev$object *v)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_lshift(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_lshift($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_rshift(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_rshift($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_and(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_and($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_xor(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_xor($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_or(v, w)
-       $abbrev$object *v;
-       $abbrev$object *w;
+$abbrev$_or($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX */
 }
 
 static int
-$abbrev$_coerce(pv, pw)
-       PyObject **pv;
-       PyObject **pw;
+$abbrev$_coerce(PyObject **pv, PyObject **pw)
 {
        /* XXXX I haven't a clue... */
        return 1;
 }
 
 static PyObject *
-$abbrev$_int(v)
-       $abbrev$object *v;
+$abbrev$_int($abbrev$object *v)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_long(v)
-       $abbrev$object *v;
+$abbrev$_long($abbrev$object *v)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_float(v)
-       $abbrev$object *v;
+$abbrev$_float($abbrev$object *v)
 {
        /* XXXX */
 }
 
 static PyObject *
-$abbrev$_oct(v)
-       $abbrev$object *v;
+$abbrev$_oct($abbrev$object *v)
 {
        /* XXXX Return object as octal stringobject */
 }
 
 static PyObject *
-$abbrev$_hex(v)
-       $abbrev$object *v;
+$abbrev$_hex($abbrev$object *v)
 {
        /* XXXX Return object as hex stringobject */
 }
index bc0f470262d9b2e1d7cc7797b25c8e4d2af00a5b..54c0b92901810bec09fc849c762a7fd3615e4107 100644 (file)
@@ -2,59 +2,44 @@
 /* Code to handle accessing $name$ objects as sequence objects */
 
 static int
-$abbrev$_length(self)
-       $abbrev$object *self;
+$abbrev$_length($abbrev$object *self)
 {
        /* XXXX Return the size of the object */
 }
 
 static PyObject *
-$abbrev$_concat(self, bb)
-       $abbrev$object *self;
-       PyObject *bb;
+$abbrev$_concat($abbrev$object *self, PyObject *bb)
 {
        /* XXXX Return the concatenation of self and bb */
 }
 
 static PyObject *
-$abbrev$_repeat(self, n)
-       $abbrev$object *self;
-       int n;
+$abbrev$_repeat($abbrev$object *self, int n)
 {
        /* XXXX Return a new object that is n times self */
 }
 
 static PyObject *
-$abbrev$_item(self, i)
-       $abbrev$object *self;
-       int i;
+$abbrev$_item($abbrev$object *self, int i)
 {
        /* XXXX Return the i-th object of self */
 }
 
 static PyObject *
-$abbrev$_slice(self, ilow, ihigh)
-       $abbrev$object *self;
-       int ilow, ihigh;
+$abbrev$_slice($abbrev$object *self, int ilow, int ihigh)
 {
        /* XXXX Return the ilow..ihigh slice of self in a new object */
 }
 
 static int
-$abbrev$_ass_item(self, i, v)
-       $abbrev$object *self;
-       int i;
-       PyObject *v;
+$abbrev$_ass_item($abbrev$object *self, int i, PyObject *v)
 {
        /* XXXX Assign to the i-th element of self */
        return 0;
 }
 
 static int
-$abbrev$_ass_slice(self, ilow, ihigh, v)
-       PyListObject *self;
-       int ilow, ihigh;
-       PyObject *v;
+$abbrev$_ass_slice(PyListObject *self, int ilow, int ihigh, PyObject *v)
 {
        /* XXXX Replace ilow..ihigh slice of self with v */
        return 0;
index be4cc4bfa35025998a1dac37eaf2bccde9822923..a93f17fd6135682a776d2fbbf0909a5dfa85c5ed 100644 (file)
@@ -1,9 +1,6 @@
 
 static PyObject *
-$abbrev$_call(self, args, kwargs)
-       $abbrev$object *self;
-       PyObject *args;
-       PyObject *kwargs;
+$abbrev$_call($abbrev$object *self, PyObject *args, PyObject *kwargs)
 {
        /* XXXX Return the result of calling self with argument args */
 }
index a2e2e9de746a8943058073b9a4bd923029889811..153bae0bd42a6ebf0f116cee0fa52a8570b5c8da 100644 (file)
@@ -1,7 +1,6 @@
 
 static int
-$abbrev$_compare(v, w)
-       $abbrev$object *v, *w;
+$abbrev$_compare($abbrev$object *v, $abbrev$object *w)
 {
        /* XXXX Compare objects and return -1, 0 or 1 */
 }
index ca15c0359dfc48bea3bd59ad1987c421f32d98c5..440419a524c23ddfb65d2c990acd6515285382ef 100644 (file)
@@ -1,7 +1,6 @@
 
 static void
-$abbrev$_dealloc(self)
-       $abbrev$object *self;
+$abbrev$_dealloc($abbrev$object *self)
 {
        /* XXXX Add your own cleanup code here */
        PyMem_DEL(self);
index 8e42aea964d27131401c83cd89acb7262d312724..6a1b2e866094ffef8db30ed8d559acd26c195c47 100644 (file)
@@ -1,8 +1,6 @@
 
 static PyObject *
-$abbrev$_getattr(self, name)
-       $abbrev$object *self;
-       char *name;
+$abbrev$_getattr($abbrev$object *self, char *name)
 {
        /* XXXX Add your own getattr code here */
        return Py_FindMethod($abbrev$_methods, (PyObject *)self, name);
index 1681b4a3846da7698f8613ac0205281d8102ad5f..2d63f6a8abc4ebd6ee81a51442744e5be5660fcb 100644 (file)
@@ -1,7 +1,6 @@
 
 static long
-$abbrev$_hash(self)
-       $abbrev$object *self;
+$abbrev$_hash($abbrev$object *self)
 {
        /* XXXX Return a hash of self (or -1) */
 }
index 017712e3b863e5a40188d0bf3700aca057870925..76408d234f48c0734323a90cebe3196f9bfbe3a4 100644 (file)
@@ -1,9 +1,6 @@
 
 static int
-$abbrev$_print(self, fp, flags)
-       $abbrev$object *self;
-       FILE *fp;
-       int flags;
+$abbrev$_print($abbrev$object *self, FILE *fp, int flags)
 {
        /* XXXX Add code here to print self to fp */
        return 0;
index 16aebc74277dca413b8c36d2d0f171755b6fc3b5..f12222508729c8b15b1237e45d2c984d0990b719 100644 (file)
@@ -1,7 +1,6 @@
 
 static PyObject *
-$abbrev$_repr(self)
-       $abbrev$object *self;
+$abbrev$_repr($abbrev$object *self)
 {
        PyObject *s;
 
index 15701b622670ed72b8ed124fbda9fd55cdb38449..dfe4bc8c772e48b38f13190d03c1611a3984fafa 100644 (file)
@@ -1,9 +1,6 @@
 
 static int
-$abbrev$_setattr(self, name, v)
-       $abbrev$object *self;
-       char *name;
-       PyObject *v;
+$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v)
 {
        /* Set attribute 'name' to value 'v'. v==NULL means delete */
        
index bed15dfdf70a235c6f5274c2afe0d4e38376e256..2e3648e8381fa930aaefe4d68aa1f73e05e01757 100644 (file)
@@ -1,7 +1,6 @@
 
 static PyObject *
-$abbrev$_str(self)
-       $abbrev$object *self;
+$abbrev$_str($abbrev$object *self)
 {
        PyObject *s;
 
index add8b6a3898f1bdd5224ffdd24e6e79693802234..cdf6afe5e3bc6c76fdb13e66f3546bb8e9fa75fe 100755 (executable)
@@ -30,8 +30,8 @@ import string
 
 oops = 'oops'
 
-IDENTSTARTCHARS = string.ascii_letters + '_'
-IDENTCHARS = string.ascii_letters + string.digits + '_'
+IDENTSTARTCHARS = string.letters + '_'
+IDENTCHARS = string.letters + string.digits + '_'
 
 # Check that string is a legal C identifier
 def checkid(str):
index 06e9683a4785360edc4bee57255292157494a8b3..71a2b264409b85f06f934625fb6d1ffff22df267 100644 (file)
@@ -2,37 +2,33 @@
 # Variable substitution. Variables are $delimited$
 #
 import string
-import regex
-import regsub
+import re
 
 error = 'varsubst.error'
 
 class Varsubst:
     def __init__(self, dict):
         self.dict = dict
-        self.prog = regex.compile('\$[a-zA-Z0-9_]*\$')
+        self.prog = re.compile('\$([a-zA-Z0-9_]*)\$')
         self.do_useindent = 0
 
     def useindent(self, onoff):
         self.do_useindent = onoff
         
-    def subst(self, str):
+    def subst(self, s):
         rv = ''
         while 1:
-            pos = self.prog.search(str)
-            if pos < 0:
-                return rv + str
-            if pos:
-                rv = rv + str[:pos]
-                str = str[pos:]
-            len = self.prog.match(str)
-            if len == 2:
+            m = self.prog.search(s)
+            if not m:
+                return rv + s
+            rv = rv + s[:m.start()]
+            s = s[m.end():]
+            if m.end() - m.start() == 2:
                 # Escaped dollar
                 rv = rv + '$'
-                str = str[2:]
+                s = s[2:]
                 continue
-            name = str[1:len-1]
-            str = str[len:]
+            name = m.group(1)
             if not self.dict.has_key(name):
                 raise error, 'No such variable: '+name
             value = self.dict[name]
@@ -44,7 +40,7 @@ class Varsubst:
         lastnl = string.rfind(old, '\n', 0) + 1
         lastnl = len(old) - lastnl
         sub = '\n' + (' '*lastnl)
-        return regsub.gsub('\n', sub, value)
+        return re.sub('\n', sub, value)
 
 def _test():
     import sys