summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2006-09-17 18:00:33 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2006-09-17 18:00:33 +0000
commitab485b5413da403ae2d7d4c55982eb7dbe49344a (patch)
tree0d99d6c13b773838f21c9cf697d512c0193dd7aa
parent292d5d9446588fc2c9493a7640d4fd9a07bbf195 (diff)
downloadnumpy-ab485b5413da403ae2d7d4c55982eb7dbe49344a.tar.gz
Fixed typos, started impl. derived type support.
-rw-r--r--numpy/f2py/lib/base_classes.py4
-rw-r--r--numpy/f2py/lib/python_wrapper.py20
-rw-r--r--numpy/f2py/lib/typedecl_statements.py4
3 files changed, 20 insertions, 8 deletions
diff --git a/numpy/f2py/lib/base_classes.py b/numpy/f2py/lib/base_classes.py
index d1835edfa..203cafd63 100644
--- a/numpy/f2py/lib/base_classes.py
+++ b/numpy/f2py/lib/base_classes.py
@@ -112,7 +112,7 @@ class Variable:
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 @@ class Variable:
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
diff --git a/numpy/f2py/lib/python_wrapper.py b/numpy/f2py/lib/python_wrapper.py
index f31e6293b..9b4e4634e 100644
--- a/numpy/f2py/lib/python_wrapper.py
+++ b/numpy/f2py/lib/python_wrapper.py
@@ -127,6 +127,7 @@ PyMODINIT_FUNC init%(modulename)s(void) {
'''
main_fortran_template = '''\
+! -*- f90 -*-
%(fortran_code_list)s
'''
def __init__(self, modulename):
@@ -305,7 +306,16 @@ static int pyobj_to_%(ctype)s(PyObject *obj, %(ctype)s* value) {
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 @@ initialize_%(typename)s_interface(initialize_%(typename)s_interface_c);\
'''
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 @@ initialize_%(typename)s_interface(initialize_%(typename)s_interface_c);\
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 @@ initialize_%(typename)s_interface(initialize_%(typename)s_interface_c);\
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 @@ if __name__ == '__main__':
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
diff --git a/numpy/f2py/lib/typedecl_statements.py b/numpy/f2py/lib/typedecl_statements.py
index 6850cbb97..5f3a6bc42 100644
--- a/numpy/f2py/lib/typedecl_statements.py
+++ b/numpy/f2py/lib/typedecl_statements.py
@@ -456,9 +456,7 @@ class Type(TypeDeclarationStatement):
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 = []