[Numpy-svn] r3297 - in trunk/numpy/f2py/lib: . parser

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Oct 9 15:31:25 CDT 2006


Author: pearu
Date: 2006-10-09 15:31:16 -0500 (Mon, 09 Oct 2006)
New Revision: 3297

Modified:
   trunk/numpy/f2py/lib/parser/block_statements.py
   trunk/numpy/f2py/lib/parser/typedecl_statements.py
   trunk/numpy/f2py/lib/py_wrap_subprogram.py
   trunk/numpy/f2py/lib/py_wrap_type.py
   trunk/numpy/f2py/lib/test_derived_scalar.py
Log:
F2PY G3: refactored Python specific wrapper code from parser.

Modified: trunk/numpy/f2py/lib/parser/block_statements.py
===================================================================
--- trunk/numpy/f2py/lib/parser/block_statements.py	2006-10-09 20:22:34 UTC (rev 3296)
+++ trunk/numpy/f2py/lib/parser/block_statements.py	2006-10-09 20:31:16 UTC (rev 3297)
@@ -1070,25 +1070,6 @@
             _cache[id(self)] = s
         return s
 
-    def get_f_type(self):
-        return 'TYPE(%s)' % (self.name)
-
-    def get_c_type(self):
-        return 'f2py_type_%s_%s' % (self.name, self.get_bit_size())
-    
-    def get_c_name(self):
-        return 'f2py_type_%s' % (self.name)
-
-    def get_c_struct_name(self):
-        return self.get_c_name() + '_struct'
-
-    def get_c_struct(self):
-        l = []
-        for name, var in self.a.components.items():
-            t = var.get_typedecl()
-            l.append('  %s %s;' % (t.get_c_type(), name))
-        return 'typedef struct {\n%s\n} %s;' % ('\n'.join(l), self.get_c_struct_name())
-
 TypeDecl = Type
 
 # Enum

Modified: trunk/numpy/f2py/lib/parser/typedecl_statements.py
===================================================================
--- trunk/numpy/f2py/lib/parser/typedecl_statements.py	2006-10-09 20:22:34 UTC (rev 3296)
+++ trunk/numpy/f2py/lib/parser/typedecl_statements.py	2006-10-09 20:31:16 UTC (rev 3297)
@@ -364,9 +364,6 @@
     match = re.compile(r'integer\b',re.I).match
     default_kind = 4
 
-    def get_c_type(self):
-        return 'npy_int%s' % (self.get_bit_size())
-
     def get_zero_value(self):
         kind = self.get_kind()
         if kind==self.default_kind: return '0'
@@ -376,9 +373,6 @@
     match = re.compile(r'real\b',re.I).match
     default_kind = 4
 
-    def get_c_type(self):
-        return 'npy_float%s' % (self.get_bit_size())
-
     def get_zero_value(self):
         kind = self.get_kind()
         if kind==self.default_kind: return '0.0'
@@ -394,9 +388,6 @@
     def get_zero_value(self):
         return '0.0D0'
 
-    def get_c_type(self):
-        return 'npy_float%s' % (self.get_bit_size())
-
 class Complex(TypeDeclarationStatement):
     match = re.compile(r'complex\b',re.I).match
     default_kind = 4
@@ -412,9 +403,6 @@
         if kind==self.default_kind: return '(0.0, 0.0)'
         return '(0.0_%s, 0.0_%s)' % (kind, kind)
 
-    def get_c_type(self):
-        return 'npy_complex%s' % (self.get_bit_size())
-
     def get_part_typedecl(self):
         bz = self.get_byte_size()/2
         return Real(self.parent, self.item.copy('REAL*%s' % (bz)))
@@ -430,9 +418,6 @@
     def get_zero_value(self):
         return '(0.0D0,0.0D0)'
 
-    def get_c_type(self):
-        return 'npy_complex%s' % (self.get_bit_size())
-
 class Logical(TypeDeclarationStatement):
     match = re.compile(r'logical\b',re.I).match
     default_kind = 4
@@ -440,9 +425,6 @@
     def get_zero_value(self):
         return ".FALSE."
 
-    def get_c_type(self):
-        return 'f2py_bool%s' % (self.get_bit_size())
-
 class Character(TypeDeclarationStatement):
     match = re.compile(r'character\b',re.I).match
     default_kind = 1
@@ -453,9 +435,6 @@
             return 0  # model for character*(*)
         return CHAR_BIT * int(length) * int(self.get_kind())
 
-    def get_c_type(self):
-        return 'f2py_string%s' % (self.get_bit_size())
-
     def get_zero_value(self):
         return "''"
 
@@ -467,9 +446,6 @@
     def get_zero_value(self):
         return '0'
 
-    def get_c_type(self):
-        return 'npy_int%s' % (self.get_bit_size())
-
 class Type(TypeDeclarationStatement):
     match = re.compile(r'type\s*\(', re.I).match
 
@@ -489,9 +465,6 @@
 
     def get_bit_size(self):
         return self.get_type_decl(self.name).get_bit_size()
-
-    def get_c_type(self):
-        return self.get_type_decl(self.name).get_c_type()
     
 TypeStmt = Type
 

Modified: trunk/numpy/f2py/lib/py_wrap_subprogram.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-09 20:22:34 UTC (rev 3296)
+++ trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-09 20:31:16 UTC (rev 3297)
@@ -3,6 +3,7 @@
 
 import sys
 
+from parser.api import TypeDecl, TypeStmt
 from wrapper_base import *
 from py_wrap_type import *
 
@@ -80,32 +81,40 @@
 
         args_f = []
         extra_args_f = []
+        argindex = -1
         for argname in block.args:
+            argindex += 1
             var = block.a.variables[argname]
             typedecl = var.get_typedecl()
             PythonCAPIType(parent, typedecl)
-            ctype = typedecl.get_c_type()
-            if ctype=='f2py_string0':
-                self.decl_list.append('%s %s = {NULL,0};' % (ctype, argname))
+            ti = PyTypeInterface(typedecl)
+            self.kw_list.append('"%s"' % (argname))
+
+            if isinstance(typedecl, TypeStmt):
+                self.pyarg_format_list.append('O&')
+                self.decl_list.append('%s* %s = NULL;' % (ti.otype, argname))
+                self.pyarg_obj_list.append('\npyobj_to_%s_inplace, &%s' % (ti.ctype, argname))
+                args_f.append('%s->data' % (argname)) # is_scalar
             else:
-                self.decl_list.append('%s %s;' % (ctype, argname))
-            self.kw_list.append('"%s"' % (argname))
-            self.pyarg_format_list.append('O&')
-            self.pyarg_obj_list.append('\npyobj_to_%s, &%s' % (ctype, argname))
-            if 1: # is_scalar
-                if ctype=='f2py_string0':
-                    args_f.append('%s.data' % argname)
+                self.pyarg_format_list.append('O&')
+                assert not isinstance(typedecl, TypeDecl)
+                if ti.ctype=='f2py_string0':
+                    self.decl_list.append('%s %s = {NULL,0};' % (ti.ctype, argname))
+                    args_f.append('%s.data' % argname)  # is_scalar
                     extra_args_f.append('%s.len' % argname)
                     self.clean_frompyobj_list.append(\
                         'if (%s.len) free(%s.data);' % (argname,argname))
                 else:
-                    args_f.append('&'+argname)
-                
-            else:
-                args_f.append(argname)
+                    self.decl_list.append('%s %s;' % (ti.ctype, argname))
+                    args_f.append('&'+argname) # is_scalar
+                self.pyarg_obj_list.append('\npyobj_to_%s, &%s' % (ti.ctype, argname))
             if var.is_intent_out(): # and is_scalar
-                self.return_format_list.append('O&')
-                self.return_obj_list.append('\npyobj_from_%s, &%s' % (ctype, argname))
+                if isinstance(typedecl, TypeStmt):
+                    self.return_format_list.append('N')
+                    self.return_obj_list.append('\n%s' % (argname))
+                else:
+                    self.return_format_list.append('O&')
+                    self.return_obj_list.append('\npyobj_from_%s, &%s' % (ti.ctype, argname))
 
         WrapperCPPMacro(parent, 'F_FUNC')
         self.call_list.append('%s_f(%s);' % (name,', '.join(args_f+extra_args_f)))

Modified: trunk/numpy/f2py/lib/py_wrap_type.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap_type.py	2006-10-09 20:22:34 UTC (rev 3296)
+++ trunk/numpy/f2py/lib/py_wrap_type.py	2006-10-09 20:31:16 UTC (rev 3297)
@@ -1,10 +1,44 @@
 
-__all__ = ['PythonCAPIType']
+__all__ = ['PythonCAPIType', 'PyTypeInterface']
 
 from wrapper_base import *
 from parser.api import CHAR_BIT, Module, declaration_type_spec, \
-     TypeDecl, TypeStmt, Subroutine, Function
+     TypeDecl, TypeStmt, Subroutine, Function, Integer, Real,\
+     DoublePrecision, Complex, DoubleComplex, Logical, Character, \
+     Byte
 
+class PyTypeInterface:
+
+    def __init__(self, typedecl):
+        if isinstance(typedecl, TypeStmt):
+            typedecl = typedecl.get_type_decl(typedecl.name)
+        if isinstance(typedecl, TypeDecl):
+            self.name = name = typedecl.name
+            tname = 'f2py_type_%s_' % (name)
+        else:
+            if isinstance(typedecl,(Integer,Byte)):
+                tname = 'npy_int'
+            elif isinstance(typedecl,(Real, DoublePrecision)):
+                tname = 'npy_float'
+            elif isinstance(typedecl,(Complex, DoubleComplex)):
+                tname = 'npy_complex'
+            elif isinstance(typedecl,Logical):
+                tname = 'f2py_bool'
+            elif isinstance(typedecl,Character):
+                tname = 'f2py_string'
+            else:
+                raise NotImplementedError,`typedecl.__class__`
+        bitsize = typedecl.get_bit_size()
+        self.ctype = ctype = '%s%s' % (tname,bitsize)
+        self.bits = bitsize
+        self.bytes = bitsize / CHAR_BIT
+
+        if isinstance(typedecl, TypeDecl):
+            self.otype = '%sObject' % (ctype)
+            self.ftype = 'TYPE(%s)' % (name)
+        return
+    
+
 class PythonCAPIType(WrapperBase):
     """
     Fortran type hooks.
@@ -294,53 +328,45 @@
     def __init__(self, parent, typedecl):
         WrapperBase.__init__(self)
         self.name = name = typedecl.name
-        self.ctype = ctype = typedecl.get_c_type()
+        ti = PyTypeInterface(typedecl)
+        self.ctype = ctype = ti.ctype
         if ctype in self._defined:
             return
         self._defined.append(ctype)
         self.info('Generating interface for %s: %s' % (typedecl.__class__, ctype))
 
-        if ctype.startswith('npy_'):
-            self.Cls = ctype[4].upper() + ctype[5:] 
-            if ctype.startswith('npy_int') or ctype.startswith('npy_float'):
-                self.capi_code_template = self.capi_code_template_scalar
-            elif ctype.startswith('npy_complex'):
-                PythonCAPIIntrinsicType(parent, typedecl.get_part_typedecl())
-                bits = int(ctype[11:])
-                self.fctype = 'npy_float%s' % (bits/2)
-                self.capi_code_template = self.capi_code_template_complex_scalar
+        if isinstance(typedecl, (Integer,Byte,Real,DoublePrecision)):
+            self.Cls = ctype[4].upper() + ctype[5:]
+            self.capi_code_template = self.capi_code_template_scalar
+        elif isinstance(typedecl, (Complex,DoubleComplex)):
+            self.Cls = ctype[4].upper() + ctype[5:]
+            PythonCAPIIntrinsicType(parent, typedecl.get_part_typedecl())
+            ti1 = PyTypeInterface(typedecl.get_part_typedecl())
+            self.fctype = ti1.ctype
+            self.capi_code_template = self.capi_code_template_complex_scalar
+        elif isinstance(typedecl, Logical):
+            self.ictype = 'npy_int%s' % (typedecl.get_bit_size())
+            self.header_template = '#define %(ctype)s %(ictype)s'
+            self.capi_code_template = self.capi_code_template_logical_scalar
+        elif isinstance(typedecl, Character):
+            self.bits = bits = typedecl.get_bit_size()
+            if bits:
+                self.bytes = bits/CHAR_BIT
+                self.header_template = '''
+#include <string.h>
+typedef struct { char data[%(bytes)s]; } %(ctype)s;
+'''
+                self.capi_code_template = self.capi_code_template_string_scalar
             else:
-                raise NotImplementedError,`name,ctype`
-            parent.apply_templates(self)
-            return
-        if ctype.startswith('f2py_'):
-            if ctype.startswith('f2py_bool'):
-                bits = int(ctype[9:])
-                self.ictype = 'npy_int%s' % (bits)
-                self.header_template = '#define %(ctype)s %(ictype)s'
-                self.capi_code_template = self.capi_code_template_logical_scalar
-                parent.apply_templates(self)
-                return
-            if ctype == 'f2py_string0':
                 self.header_template = '''
 #include <string.h>
 typedef struct { char* data; size_t len; } %(ctype)s;
 '''
                 self.capi_code_template = self.capi_code_template_string0_scalar
-                parent.apply_templates(self)
-                return
-                raise NotImplementedError,`name,ctype`
-            if ctype.startswith('f2py_string'):
-                self.bits = bits = int(ctype[11:])
-                self.bytes = bits/CHAR_BIT
-                self.header_template = '''
-#include <string.h>
-typedef struct { char data[%(bytes)s]; } %(ctype)s;
-'''
-                self.capi_code_template = self.capi_code_template_string_scalar
-                parent.apply_templates(self)
-                return
-        raise NotImplementedError,`name,ctype`
+        else:
+            raise NotImplementedError,`name,ctype`
+        parent.apply_templates(self)
+        return
 
 class PythonCAPIDerivedType(WrapperBase):
     """
@@ -348,8 +374,8 @@
     """
 
     header_template = '''\
-#define %(oname)sObject_Check(obj) \\
-    PyObject_TypeCheck((PyObject*)obj, &%(oname)sType)
+#define %(otype)s_Check(obj) \\
+    PyObject_TypeCheck((PyObject*)obj, &%(otype)sType)
 #define %(init_func)s_f \\
     F_FUNC(%(init_func)s,%(INIT_FUNC)s)
 '''
@@ -360,36 +386,36 @@
   PyObject_HEAD
   %(ptrstruct_list)s
   %(ctype)s data;
-} %(oname)sObject;
+} %(otype)s;
 '''
 
     extern_template = '''\
-static PyTypeObject %(oname)sType;
+static PyTypeObject %(otype)sType;
 '''
 
     objdecl_template = '''\
-static PyMethodDef %(oname)s_methods[] = {
+static PyMethodDef %(otype)s_methods[] = {
     %(type_method_list)s
     {NULL}  /* Sentinel */
 };
 
-static PyGetSetDef %(oname)s_getseters[] = {
+static PyGetSetDef %(otype)s_getseters[] = {
     %(type_getseters_list)s
     {NULL}  /* Sentinel */
 };
 
-static PyTypeObject %(oname)sType = {
+static PyTypeObject %(otype)sType = {
     PyObject_HEAD_INIT(NULL)
     0,                         /*ob_size*/
     "%(name)s",                /*tp_name*/
-    sizeof(%(oname)sObject),    /*tp_basicsize*/
+    sizeof(%(otype)s),    /*tp_basicsize*/
     0,                         /*tp_itemsize*/
-    (destructor)%(oname)s_dealloc, /*tp_dealloc*/
+    (destructor)%(otype)s_dealloc, /*tp_dealloc*/
     0,                         /*tp_print*/
     0,                         /*tp_getattr*/
     0,                         /*tp_setattr*/
     0,                         /*tp_compare*/
-    %(oname)s_repr,            /*tp_repr*/
+    %(otype)s_repr,            /*tp_repr*/
     0,                         /*tp_as_number*/
     0,                         /*tp_as_sequence*/
     0,                         /*tp_as_mapping*/
@@ -407,25 +433,25 @@
     0,		               /* tp_weaklistoffset */
     0,		               /* tp_iter */
     0,		               /* tp_iternext */
-    %(oname)s_methods,          /* tp_methods */
-    0 /*%(oname)s_members*/,    /* tp_members */
-    %(oname)s_getseters,       /* tp_getset */
+    %(otype)s_methods,          /* tp_methods */
+    0 /*%(otype)s_members*/,    /* tp_members */
+    %(otype)s_getseters,       /* tp_getset */
     0,                         /* tp_base */
     0,                         /* tp_dict */
     0,                         /* tp_descr_get */
     0,                         /* tp_descr_set */
     0,                         /* tp_dictoffset */
-    (initproc)%(oname)s_init,      /* tp_init */
+    (initproc)%(otype)s_init,      /* tp_init */
     0,                         /* tp_alloc */
-    %(oname)s_new,                 /* tp_new */
+    %(otype)s_new,                 /* tp_new */
 };
 '''
 
     module_init_template = '''\
-if (PyType_Ready(&%(oname)sType) < 0)
+if (PyType_Ready(&%(otype)sType) < 0)
   return;
 PyModule_AddObject(f2py_module, "%(name)s",
-                                (PyObject *)&%(oname)sType);
+                                (PyObject *)&%(otype)sType);
 '''
 
     c_code_template = '''\
@@ -436,20 +462,36 @@
 '''
 
     capi_code_template = '''\
-static void %(oname)s_dealloc(%(oname)sObject* self) {
+static void %(otype)s_dealloc(%(otype)s* self) {
   if (self->data)
     PyMem_Free(self->data);
   self->ob_type->tp_free((PyObject*)self);
 }
 
+static int pyobj_to_%(ctype)s_inplace(PyObject *obj,
+                                      %(otype)s** value_ptr) {
+  int return_value = 0;
+#if defined(F2PY_DEBUG_PYOBJ_TOFROM)
+  fprintf(stderr,"pyobj_to_%(ctype)s(type=%%s)\\n",PyString_AS_STRING(PyObject_Repr(PyObject_Type(obj))));
+#endif
+  if (%(otype)s_Check(obj)) {
+    *value_ptr = (%(otype)s*)obj;
+    return_value = 1;
+  }
+#if defined(F2PY_DEBUG_PYOBJ_TOFROM)
+  fprintf(stderr,"pyobj_to_%(ctype)s: return_value=%%d, PyErr_Occurred()=%%p\\n", return_value, PyErr_Occurred());
+#endif
+  return return_value;
+}
+
 static int pyobj_to_%(ctype)s(PyObject *obj,
-                              %(ctype)s* value_ptr) {
+                                   %(ctype)s* value_ptr) {
   int return_value = 0;
 #if defined(F2PY_DEBUG_PYOBJ_TOFROM)
   fprintf(stderr,"pyobj_to_%(ctype)s(type=%%s)\\n",PyString_AS_STRING(PyObject_Repr(PyObject_Type(obj))));
 #endif
-  if (%(oname)sObject_Check(obj)) {
-    if (!memcpy(value_ptr,((%(oname)sObject *)obj)->data, %(byte_size)s)) {
+  if (%(otype)s_Check(obj)) {
+    if (!memcpy(value_ptr,((%(otype)s *)obj)->data, %(bytes)s)) {
       PyErr_SetString(PyExc_MemoryError,
          "failed to copy %(name)s instance memory to %(ctype)s object.");
     } else {
@@ -463,16 +505,16 @@
 }
 
 static PyObject* pyobj_from_%(ctype)s(%(ctype)s* value_ptr) {
-  %(oname)sObject* obj = (%(oname)sObject*)(%(oname)sType.tp_alloc(&%(oname)sType, 0));
+  %(otype)s* obj = (%(otype)s*)(%(otype)sType.tp_alloc(&%(otype)sType, 0));
   if (obj == NULL)
     return NULL;
-  obj->data = PyMem_Malloc(%(byte_size)s);
+  obj->data = PyMem_Malloc(%(bytes)s);
   if (obj->data == NULL) {
     Py_DECREF(obj);
     return PyErr_NoMemory();
   }
   if (value_ptr) {
-    if (!memcpy(obj->data, value_ptr, %(byte_size)s)) {
+    if (!memcpy(obj->data, value_ptr, %(bytes)s)) {
       PyErr_SetString(PyExc_MemoryError,
          "failed to copy %(ctype)s object memory to %(name)s instance.");
     }
@@ -481,36 +523,37 @@
   return (PyObject*)obj;
 }
 
-static PyObject * %(oname)s_new(PyTypeObject *type,
+static PyObject * %(otype)s_new(PyTypeObject *type,
                                 PyObject *args, PyObject *kwds)
 {
   return pyobj_from_%(ctype)s(NULL);
 }
 
-static int %(oname)s_init(%(oname)sObject *self,
+static int %(otype)s_init(%(otype)s *self,
                           PyObject *capi_args, PyObject *capi_kwds)
 {
    int return_value = 0;
 #if defined(F2PY_DEBUG_PYOBJ_TOFROM)
-  fprintf(stderr,"%(oname)s_init()\\n");
+  fprintf(stderr,"%(otype)s_init()\\n");
 #endif
    if (!PyArg_ParseTuple(capi_args,"%(attr_format_elist)s"
                                    %(attr_init_clist)s))
-      return_value = -1;                             
+      return_value = -1;
+   
 #if defined(F2PY_DEBUG_PYOBJ_TOFROM)
-  fprintf(stderr,"%(oname)s_init: return_value=%%d, PyErr_Occurred()=%%p\\n", return_value, PyErr_Occurred());
+  fprintf(stderr,"%(otype)s_init: return_value=%%d, PyErr_Occurred()=%%p\\n", return_value, PyErr_Occurred());
 #endif
    return return_value;
 }
 
-static PyObject * %(oname)s_as_tuple(%(oname)sObject * self) {
+static PyObject * %(otype)s_as_tuple(%(otype)s * self) {
   return Py_BuildValue("%(as_tuple_format_elist)s"
                         %(as_tuple_arg_clist)s);
 }
 
-static PyObject * %(oname)s_repr(PyObject * self) {
+static PyObject * %(otype)s_repr(PyObject * self) {
   PyObject* r = PyString_FromString("%(name)s(");
-  PyString_ConcatAndDel(&r, PyObject_Repr(%(oname)s_as_tuple((%(oname)sObject*)self)));
+  PyString_ConcatAndDel(&r, PyObject_Repr(%(otype)s_as_tuple((%(otype)s*)self)));
   PyString_ConcatAndDel(&r, PyString_FromString(")"));
   return r;
 }
@@ -523,7 +566,7 @@
       %(use_stmt_list)s
       %(type_decl_list)s
       external init_func_c
-!     self is %(oname)sObject
+!     self is %(otype)s
       external self
       %(ftype)s obj
       call init_func_c(%(init_func_f_arg_clist)s)
@@ -535,6 +578,7 @@
     _defined = []
     def __init__(self, parent, typedecl):
         WrapperBase.__init__(self)
+        ti = PyTypeInterface(typedecl)
         name = typedecl.name
         if name in self._defined:
             return
@@ -542,15 +586,15 @@
         self.info('Generating interface for %s: %s' % (typedecl.__class__, name))
 
         self.name = name
-        self.oname = oname = 'f2py_' + name
-        self.ctype = typedecl.get_c_type()
+        self.otype = otype = ti.otype
+        self.ctype = ctype = ti.ctype
         self.ctype_ptrs = self.ctype + '_ptrs'
-        self.ftype = typedecl.get_f_type()
-        self.byte_size = byte_size = typedecl.get_bit_size() / CHAR_BIT
+        self.ftype = ti.ftype
+        self.bytes = bytes = ti.bytes
         WrapperCPPMacro(parent, 'F_FUNC')
 
         self.init_func_f_arg_list = ['self']
-        self.init_func_c_arg_list = ['%sObject *self' % (self.oname)]
+        self.init_func_c_arg_list = ['%s *self' % (otype)]
         self.init_func_c_body_list = []
         self.ptrstruct_list = []
         self.attr_decl_list = []
@@ -563,19 +607,19 @@
         for n in typedecl.a.component_names:
             v = typedecl.a.components[n]
             t = v.get_typedecl()
+            ti1 = PyTypeInterface(t)
             PythonCAPIType(parent, t)
-            ct = t.get_c_type()
-            on = 'f2py_' + t.name
+            ct = ti1.ctype
             parent.add(t)
             self.ptrstruct_list.append('%s* %s_ptr;' % (ct, n))
             self.init_func_f_arg_list.append('obj %% %s' % (n))
             self.init_func_c_arg_list.append('\n%s * %s_ptr' % (ct, n))
             self.init_func_c_body_list.append('''\
 if (!((void*)%(n)s_ptr >= self->data
-      && (void*)%(n)s_ptr < self->data + %(byte_size)s ))
+      && (void*)%(n)s_ptr < self->data + %(bytes)s ))
   fprintf(stderr,"INCONSISTENCY IN %(name)s WRAPPER: "
-                 "self->data=%%p <= %(n)s_ptr=%%p < self->data+%(byte_size)s=%%p\\n",
-                 self->data, %(n)s_ptr, self->data + %(byte_size)s);
+                 "self->data=%%p <= %(n)s_ptr=%%p < self->data+%(bytes)s=%%p\\n",
+                 self->data, %(n)s_ptr, self->data + %(bytes)s);
 self->%(n)s_ptr = %(n)s_ptr;
 ''' % (locals()))
             self.attr_format_list.append('O&')
@@ -583,11 +627,11 @@
             self.as_tuple_format_list.append('O&')
             self.as_tuple_arg_list.append('\npyobj_from_%s, self->%s_ptr' % (ct, n))
             self.getset_func_list.append('''\
-static PyObject * %(oname)s_get_%(n)s(%(oname)sObject *self,
+static PyObject * %(otype)s_get_%(n)s(%(otype)s *self,
                                       void *closure) {
   return pyobj_from_%(ct)s(self->%(n)s_ptr);
 }
-static int %(oname)s_set_%(n)s(%(oname)sObject *self,
+static int %(otype)s_set_%(n)s(%(otype)s *self,
                                PyObject *value, void *closure)
 {
   if (value == NULL) {
@@ -600,15 +644,13 @@
   return -1;
 }
 ''' % (locals()))
-            self.type_getseters_list.append('{"%(n)s",(getter)%(oname)s_get_%(n)s, (setter)%(oname)s_set_%(n)s,\n "component %(n)s",NULL},' % (locals()))
+            self.type_getseters_list.append('{"%(n)s",(getter)%(otype)s_get_%(n)s, (setter)%(otype)s_set_%(n)s,\n "component %(n)s",NULL},' % (locals()))
         if self.attr_init_list: self.attr_init_list.insert(0,'')
         if self.as_tuple_arg_list: self.as_tuple_arg_list.insert(0,'')
         self.init_func = self.ctype + '_init'
-        self.INIT_FUNC = self.init_func.upper()
 
         self.type_method_list = []
-        self.type_method_list.append('{"as_tuple",(PyCFunction)%(oname)s_as_tuple,METH_NOARGS,\n "Return %(name)s components as tuple."},' % (self.__dict__))
-        self.cname = typedecl.get_c_name()
+        self.type_method_list.append('{"as_tuple",(PyCFunction)%(otype)s_as_tuple,METH_NOARGS,\n "Return %(name)s components as tuple."},' % (self.__dict__))
 
         self.use_stmt_list = []
         self.type_decl_list = []

Modified: trunk/numpy/f2py/lib/test_derived_scalar.py
===================================================================
--- trunk/numpy/f2py/lib/test_derived_scalar.py	2006-10-09 20:22:34 UTC (rev 3296)
+++ trunk/numpy/f2py/lib/test_derived_scalar.py	2006-10-09 20:31:16 UTC (rev 3297)
@@ -66,8 +66,9 @@
         assert isinstance(a,m.myt),`a`
         r = m.foo(a)
         assert isinstance(r,m.myt),`r`
+        assert r is a
         assert_equal(r.flag,3)
-        assert_equal(a.flag,2)
+        assert_equal(a.flag,3)
         
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list