summaryrefslogtreecommitdiff
path: root/numpy/f2py/lib/python_wrapper.py
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 /numpy/f2py/lib/python_wrapper.py
parent292d5d9446588fc2c9493a7640d4fd9a07bbf195 (diff)
downloadnumpy-ab485b5413da403ae2d7d4c55982eb7dbe49344a.tar.gz
Fixed typos, started impl. derived type support.
Diffstat (limited to 'numpy/f2py/lib/python_wrapper.py')
-rw-r--r--numpy/f2py/lib/python_wrapper.py20
1 files changed, 17 insertions, 3 deletions
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