[Numpy-svn] r3175 - trunk/numpy/f2py/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Sep 17 13:00:38 CDT 2006


Author: pearu
Date: 2006-09-17 13:00:33 -0500 (Sun, 17 Sep 2006)
New Revision: 3175

Modified:
   trunk/numpy/f2py/lib/base_classes.py
   trunk/numpy/f2py/lib/python_wrapper.py
   trunk/numpy/f2py/lib/typedecl_statements.py
Log:
Fixed typos, started impl. derived type support.

Modified: trunk/numpy/f2py/lib/base_classes.py
===================================================================
--- trunk/numpy/f2py/lib/base_classes.py	2006-09-17 06:34:16 UTC (rev 3174)
+++ trunk/numpy/f2py/lib/base_classes.py	2006-09-17 18:00:33 UTC (rev 3175)
@@ -112,7 +112,7 @@
         return
 
     def get_bit_size(self):
-        typesize = self.typedecl.get_bit_size(self)
+        typesize = self.typedecl.get_bit_size()
         if self.is_pointer():
             # The size of pointer descriptor is compiler version dependent. Read:
             #   http://www.nersc.gov/vendor_docs/intel/f_ug1/pgwarray.htm
@@ -227,7 +227,7 @@
     def is_required(self): return 'REQUIRED' in self.attributes
     def is_pointer(self): return 'POINTER' in self.attributes
 
-    def is_array(self): return not not (self.bounds or self.dimensions)
+    def is_array(self): return not not (self.bounds or self.dimension)
 
     def update(self, *attrs):
         attributes = self.attributes

Modified: trunk/numpy/f2py/lib/python_wrapper.py
===================================================================
--- trunk/numpy/f2py/lib/python_wrapper.py	2006-09-17 06:34:16 UTC (rev 3174)
+++ trunk/numpy/f2py/lib/python_wrapper.py	2006-09-17 18:00:33 UTC (rev 3175)
@@ -127,6 +127,7 @@
 '''
 
     main_fortran_template = '''\
+! -*- f90 -*-
 %(fortran_code_list)s
 '''
     def __init__(self, modulename):
@@ -305,7 +306,16 @@
   return pyobj_to_string_len(obj, (f2py_string*)value, %(ctype_bytes)s);
 }
 ''' % (locals())
-
+        elif ctype.startswith('f2py_type_'):
+            ctype_bits = int(ctype.split('_')[-1])
+            ctype_bytes = ctype_bits / CHAR_BIT
+            self.add_typedef(ctype,'typedef struct { char data[%s]; } %s;' % (ctype_bytes,ctype))
+            return '''
+static int pyobj_to_%(ctype)s(PyObject *obj, %(ctype)s* value) {
+  return pyobj_to_string_len(obj, (f2py_string*)value, %(ctype_bytes)s);
+}
+''' % (locals())
+        
 class PythonCAPIFunction(WrapperBase):
     capi_function_template = '''
 static char f2py_doc_%(function_name)s[] = "%(function_doc)s";
@@ -430,8 +440,9 @@
 '''
     fortran_code_template = '''\
        function create_%(typename)s_object_f() result (obj)
+         %(typedecl_list)s
          %(typedecl)s obj
-!         %(initexpr)s
+!        %(initexpr)s
        end
        subroutine initialize_%(typename)s_interface_f(init_c)
          external create_%(typename)s_object_f
@@ -443,6 +454,7 @@
         WrapperBase.__init__(self)
         self.parent = parent
         self.typedecl = typedecl.astypedecl()
+        self.typedecl_list = []
         self.ctype = self.typedecl.get_c_type()
         self.byte_size = self.typedecl.get_byte_size()
         self.typename = self.typedecl.name.lower()
@@ -456,6 +468,8 @@
             pass
         elif ctype.startswith('f2py_string'):
             pass
+        elif ctype.startswith('f2py_type'):
+            pass
         else:
             self.parent.typedef_list.append(self.apply_attributes(self.typedef_template))
             self.parent.objdecl_list.append(self.apply_attributes(self.objdecl_template))
@@ -498,7 +512,7 @@
           integer d,n
         end type rational
       end module rat
-      subroutine foo(a,b)
+      subroutine foo(a,b,c)
         use rat
         integer a
         character*5 b

Modified: trunk/numpy/f2py/lib/typedecl_statements.py
===================================================================
--- trunk/numpy/f2py/lib/typedecl_statements.py	2006-09-17 06:34:16 UTC (rev 3174)
+++ trunk/numpy/f2py/lib/typedecl_statements.py	2006-09-17 18:00:33 UTC (rev 3175)
@@ -456,9 +456,7 @@
     match = re.compile(r'type\s*\(', re.I).match
 
     def get_zero_value(self):
-        kind = self.selector
-        assert is_name(kind),`kind`
-        type_decl = self.get_type_decl(kind)
+        type_decl = self.get_type_decl(self.name)
         component_names = type_decl.a.component_names
         components = type_decl.a.components
         l = []



More information about the Numpy-svn mailing list