summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2007-08-10 15:30:24 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2007-08-10 15:30:24 +0000
commit9fc1daf9ac0fe6f7f8c1ab593b3d75c85e438e75 (patch)
tree2d67ef04efc3415ec66b48cb0aa555a7b9865ae8 /numpy/f2py
parenta6148b252cc8922255832bd2bed1de7d364b47d4 (diff)
downloadnumpy-9fc1daf9ac0fe6f7f8c1ab593b3d75c85e438e75.tar.gz
extgen: removing old files
Diffstat (limited to 'numpy/f2py')
-rw-r--r--numpy/f2py/lib/extgen/c_code.py33
-rw-r--r--numpy/f2py/lib/extgen/c_type.py638
-rw-r--r--numpy/f2py/lib/extgen/converters.py22
-rw-r--r--numpy/f2py/lib/extgen/extension_module.py195
-rw-r--r--numpy/f2py/lib/extgen/predefined_components.py23
-rw-r--r--numpy/f2py/lib/extgen/pyc_argument.py130
-rw-r--r--numpy/f2py/lib/extgen/pyc_function.py237
7 files changed, 0 insertions, 1278 deletions
diff --git a/numpy/f2py/lib/extgen/c_code.py b/numpy/f2py/lib/extgen/c_code.py
deleted file mode 100644
index cbb95e760..000000000
--- a/numpy/f2py/lib/extgen/c_code.py
+++ /dev/null
@@ -1,33 +0,0 @@
-
-from base import Component
-
-class CCode(Component):
-
- """
- CCode(*lines, provides=..)
- """
-
- container_options = dict(CCodeLines=dict())
-
- template = '%(CCodeLines)s'
-
- def initialize(self, *lines, **options):
- self.lines = []
- map(self.add, lines)
- return self
-
- def update_containers(self):
- CCodeLines = self.get_container('CCodeLines')
- CCodeLines.add('\n'.join(self.lines))
-
- def add(self, component, label=None):
- if isinstance(component, str):
- assert label is None,`label`
- self.lines.append(component)
- elif isinstance(component, CCode):
- assert label is None,`label`
- self.lines.extend(component.lines)
- else:
- Component.add(self, component. label)
-
-
diff --git a/numpy/f2py/lib/extgen/c_type.py b/numpy/f2py/lib/extgen/c_type.py
deleted file mode 100644
index 8c8515eb2..000000000
--- a/numpy/f2py/lib/extgen/c_type.py
+++ /dev/null
@@ -1,638 +0,0 @@
-"""
-C types.
-
-
-"""
-
-__all__ = ['CType', 'CTypeAlias', 'CTypeFuncAlias', 'CTypePtr', 'CTypeStruct', 'CDecl',
- 'CTypePython']
-
-from base import Component
-
-class CTypeBase(Component):
-
- template = '%(name)s'
- template_typedef = ''
- default_container_label = '<IGNORE>'
- default_component_class_name = 'CType'
-
- @property
- def provides(self):
- return '%s_%s' % (self.__class__.__name__, self.name)
-
- def initialize(self, name, *components):
- self.name = name
- map(self.add, components)
- return self
-
- def __repr__(self):
- return '%s(%s)' % (self.__class__.__name__, ', '.join([repr(self.name)]+[repr(c) for (c,l) in self.components]))
-
- def update_containers(self):
- self.container_TypeDef += self.evaluate(self.template_typedef)
-
- def __str__(self):
- return self.name
-
- def get_pyarg_fmt(self, arg):
- raise NotImplementedError('%s.get_pyarg_fmt()' % (self.__class__.__name__))
-
- def get_pyarg_obj(self, arg):
- raise NotImplementedError('%s.get_pyarg_obj()' % (self.__class__.__name__))
-
- def get_pyret_fmt(self, arg):
- raise NotImplementedError('%s.get_pyret_fmt()' % (self.__class__.__name__))
-
- def get_pyret_obj(self, arg):
- raise NotImplementedError('%s.get_pyret_obj()' % (self.__class__.__name__))
-
- def get_init_value(self, arg):
- return
-
- def set_Decl(self, arg):
- init_value = self.get_init_value(arg)
- if init_value:
- init = ' = %s' % (init_value)
- else:
- init = ''
- if arg.pycvar and arg.pycvar==arg.retpycvar:
- arg += CDecl(self, '%s%s' % (arg.pycvar, init))
- else:
- if arg.input_intent!='hide':
- arg += CDecl(self, '%s%s' % (arg.pycvar, init))
- if arg.output_intent!='hide':
- arg += CDecl(self, '%s%s' % (arg.retpycvar, init))
-
- def set_converters(self, arg):
- """
- Notes for user:
- if arg is intent(optional, in, out) and not specified
- as function argument then function may created but
- it must then have *new reference* (ie use Py_INCREF
- unless it is a new reference already).
- """
- # this method is called from PyCFunction.update_containers(),
- # note that self.parent is None put arg.parent is PyCFunction
- # instance.
- eval_a = arg.evaluate
- FromPyObj = arg.container_FromPyObj
- PyObjFrom = arg.container_PyObjFrom
-
- argfmt = self.get_pyarg_fmt(arg)
- retfmt = self.get_pyret_fmt(arg)
-
- if arg.output_intent=='return':
- if arg.input_intent in ['optional', 'extra']:
- if retfmt in 'SON':
- FromPyObj += eval_a('''\
-if (!(%(pycvar)s==NULL)) {
- /* make %(pycvar)r a new reference */
- %(retpycvar)s = %(pycvar)s;
- Py_INCREF((PyObject*)%(retpycvar)s);
-}
-''')
- PyObjFrom += eval_a('''\
-if (%(retpycvar)s==NULL) {
- /* %(pycvar)r was not specified */
- if (%(pycvar)s==NULL) {
- %(retpycvar)s = Py_None;
- Py_INCREF((PyObject*)%(retpycvar)s);
- } else {
- %(retpycvar)s = %(pycvar)s;
- /* %(pycvar)r must be a new reference or expect a core dump. */
- }
-} elif (!(%(retpycvar)s == %(pycvar)s)) {
- /* a new %(retpycvar)r was created, undoing %(pycvar)s new reference */
- Py_DECREF((PyObject*)%(pycvar)s);
-}
-''')
- elif arg.input_intent=='hide':
- if retfmt in 'SON':
- PyObjFrom += eval_a('''\
-if (%(retpycvar)s==NULL) {
- %(retpycvar)s = Py_None;
- Py_INCREF((PyObject*)%(retpycvar)s);
-} /* else %(retpycvar)r must be a new reference or expect a core dump. */
-''')
- elif arg.input_intent=='required':
- if retfmt in 'SON':
- FromPyObj += eval_a('''\
-/* make %(pycvar)r a new reference */
-%(retpycvar)s = %(pycvar)s;
-Py_INCREF((PyObject*)%(retpycvar)s);
-''')
- PyObjFrom += eval_a('''\
-if (!(%(retpycvar)s==%(pycvar)s)) {
- /* a new %(retpycvar)r was created, undoing %(pycvar)r new reference */
- /* %(retpycvar)r must be a new reference or expect a core dump. */
- Py_DECREF((PyObject*)%(pycvar)s);
-}
-''')
- return
-
-class _CatchTypeDef(Component): # for doctest
- template = '%(TypeDef)s'
- default_container_label = '<IGNORE>'
- container_options = dict(TypeDef=dict(default=''))
- def initialize(self, ctype):
- self.add(ctype)
- return self
-
-class CType(CTypeBase):
-
- """ CType(<name>)
-
- Represents any predefined type in C.
-
- >>> cint = CType('int')
- >>> print cint
- int
- >>> _CatchTypeDef(cint).generate()
- ''
- """
-
- def initialize(self, name):
- if isinstance(name, CTypeBase):
- return name
- if isinstance(name, type):
- return CTypePython(name)
- try:
- return Component.get(name)
- except KeyError:
- pass
- self.name = name
- return self
- def update_containers(self):
- pass
-
- def set_pyarg_decl(self, arg):
- pass
- def set_titles(self, arg):
- pass
-
-class CTypeAlias(CTypeBase):
-
- """ CTypeAlias(<name>, <ctype>)
-
- >>> aint = CTypeAlias('aint', 'int')
- >>> print aint
- aint
- >>> print _CatchTypeDef(aint).generate()
- typedef int aint;
- """
-
- template_typedef = 'typedef %(ctype_name)s %(name)s;'
-
- def initialize(self, name, ctype):
- self.name = name
- if isinstance(ctype, str): ctype = CType(ctype)
- self.ctype_name = ctype.name
- self.add(ctype)
- return self
-
-class CTypeFuncAlias(CTypeBase):
-
- """
- CTypeFuncAlias(<name>, <return ctype>, *(<argument ctypes>))
-
- >>> ifunc = CTypeFuncAlias('ifunc', 'int')
- >>> print ifunc
- ifunc
- >>> print _CatchTypeDef(ifunc).generate()
- typedef int (*ifunc)(void);
- >>> ifunc += 'double'
- >>> print _CatchTypeDef(ifunc).generate()
- typedef int (*ifunc)(double);
- """
-
- template_typedef = 'typedef %(RCType)s (*%(name)s)(%(ACType)s);'
- container_options = dict(RCType = dict(default='void'),
- ACType = dict(default='void', separator=', '))
- component_container_map = dict(CType = 'ACType')
- default_component_class_name = 'CType'
-
- def initialize(self, name, *components):
- self.name = name
- if components:
- self.add(components[0], 'RCType')
- map(self.add, components[1:])
- return self
-
-class CTypePtr(CTypeBase):
-
- """
- CTypePtr(<ctype>)
-
- >>> int_ptr = CTypePtr('int')
- >>> print int_ptr
- int_ptr
- >>> print _CatchTypeDef(int_ptr).generate()
- typedef int* int_ptr;
- >>> int_ptr_ptr = CTypePtr(int_ptr)
- >>> print int_ptr_ptr
- int_ptr_ptr
- >>> print _CatchTypeDef(int_ptr_ptr).generate()
- typedef int* int_ptr;
- typedef int_ptr* int_ptr_ptr;
- """
-
- template_typedef = 'typedef %(ctype_name)s* %(name)s;'
-
- def initialize(self, ctype):
- if isinstance(ctype, str): ctype = CType(ctype)
- self.name = '%s_ptr' % (ctype)
- self.ctype_name = ctype.name
- self.add(ctype)
- return self
-
-class CTypeStruct(CTypeBase):
-
- """
- CTypeStruct(<name>, *(<declarations>))
-
- >>> s = CTypeStruct('s', CDecl('int','a'))
- >>> print s
- s
- >>> print _CatchTypeDef(s).generate()
- typedef struct {
- int a;
- } s;
- >>> s += CDecl(CTypeFuncAlias('ft'), 'f')
- >>> print _CatchTypeDef(s).generate()
- typedef void (*ft)(void);
- typedef struct {
- int a;
- ft f;
- } s;
-
- """
-
- container_options = dict(Decl = dict(default='<KILLLINE>', use_indent=True))
- default_component_class_name = None #'CDecl'
- component_container_map = dict(CDecl='Decl')
-
- template_typedef = '''\
-typedef struct {
- %(Decl)s
-} %(name)s;'''
-
- def initialize(self, name, *components):
- self.name = name
- map(self.add, components)
- return self
-
-class CDecl(Component):
-
- """
- CDecl(<ctype>, *(<names with or without initialization>))
-
- >>> ad = CDecl('int')
- >>> ad.generate()
- ''
- >>> ad += 'a'
- >>> print ad.generate()
- int a;
- >>> ad += 'b'
- >>> print ad.generate()
- int a, b;
- >>> ad += 'c = 1'
- >>> print ad.generate()
- int a, b, c = 1;
- """
-
- template = '%(CTypeName)s %(Names)s;'
- container_options = dict(Names=dict(default='<KILLLINE>', separator=', '),
- CTypeName=dict())
- default_component_class_name = 'str'
- component_container_map = dict(str = 'Names')
-
- def initialize(self, ctype, *names):
- if isinstance(ctype, str): ctype = CType(ctype)
- self.add(ctype, 'CTypeName')
- map(self.add, names)
- return self
-
-class CTypePython(CTypeBase):
-
- """ CTypePython(<python type object or 'cobject' or 'cell' or 'generator'>)
-
- >>> from __init__ import * #doctest: +ELLIPSIS
- Ignoring...
- >>> m = ExtensionModule('test_CTypePython')
- >>> f = PyCFunction('func')
- >>> f += PyCArgument('i', int, output_intent='return')
- >>> f += PyCArgument('l', long, output_intent='return')
- >>> f += PyCArgument('f', float, output_intent='return')
- >>> f += PyCArgument('c', complex, output_intent='return')
- >>> f += PyCArgument('s', str, output_intent='return')
- >>> f += PyCArgument('u', unicode, output_intent='return')
- >>> f += PyCArgument('t', tuple, output_intent='return')
- >>> f += PyCArgument('lst', list, output_intent='return')
- >>> f += PyCArgument('d', dict, output_intent='return')
- >>> f += PyCArgument('set', set, output_intent='return')
- >>> f += PyCArgument('o1', object, output_intent='return')
- >>> f += PyCArgument('o2', object, output_intent='return')
- >>> m += f
- >>> b = m.build() #doctest: +ELLIPSIS
- exec_command...
- >>> b.func(23, 23l, 1.2, 1+2j, 'hello', u'hei', (2,'a'), [-2], {3:4}, set([1,2]), 2, '15')
- (23, 23L, 1.2, (1+2j), 'hello', u'hei', (2, 'a'), [-2], {3: 4}, set([1, 2]), 2, '15')
-
- >>> print b.func.__doc__
- func(i, l, f, c, s, u, t, lst, d, set, o1, o2) -> (i, l, f, c, s, u, t, lst, d, set, o1, o2)
- <BLANKLINE>
- Required arguments:
- i - a python int object
- l - a python long object
- f - a python float object
- c - a python complex object
- s - a python str object
- u - a python unicode object
- t - a python tuple object
- lst - a python list object
- d - a python dict object
- set - a python set object
- o1 - a python object
- o2 - a python object
- <BLANKLINE>
- Return values:
- i - a python int object
- l - a python long object
- f - a python float object
- c - a python complex object
- s - a python str object
- u - a python unicode object
- t - a python tuple object
- lst - a python list object
- d - a python dict object
- set - a python set object
- o1 - a python object
- o2 - a python object
-
- >>> m = ExtensionModule('test_CTypePython_c')
- >>> f = PyCFunction('func_c_int')
- >>> f += PyCArgument('i1', 'c_char', output_intent='return')
- >>> f += PyCArgument('i2', 'c_short', output_intent='return')
- >>> f += PyCArgument('i3', 'c_int', output_intent='return')
- >>> f += PyCArgument('i4', 'c_long', output_intent='return')
- >>> f += PyCArgument('i5', 'c_long_long', output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_c_unsigned_int')
- >>> f += PyCArgument('i1', 'c_unsigned_char', output_intent='return')
- >>> f += PyCArgument('i2', 'c_unsigned_short', output_intent='return')
- >>> f += PyCArgument('i3', 'c_unsigned_int', output_intent='return')
- >>> f += PyCArgument('i4', 'c_unsigned_long', output_intent='return')
- >>> f += PyCArgument('i5', 'c_unsigned_long_long', output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_c_float')
- >>> f += PyCArgument('f1', 'c_float', output_intent='return')
- >>> f += PyCArgument('f2', 'c_double', output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_c_complex')
- >>> f += PyCArgument('c1', 'c_Py_complex', output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_c_string')
- >>> f += PyCArgument('s1', 'c_const_char_ptr', output_intent='return')
- >>> f += PyCArgument('s2', 'c_const_char_ptr', output_intent='return')
- >>> f += PyCArgument('s3', 'c_Py_UNICODE', output_intent='return')
- >>> f += PyCArgument('s4', 'c_char1', output_intent='return')
- >>> m += f
- >>> b = m.build() #doctest: +ELLIPSIS
- exec_command...
- >>> b.func_c_int(2,3,4,5,6)
- (2, 3, 4, 5, 6L)
- >>> b.func_c_unsigned_int(-1,-1,-1,-1,-1)
- (255, 65535, 4294967295, 18446744073709551615L, 18446744073709551615L)
- >>> b.func_c_float(1.2,1.2)
- (1.2000000476837158, 1.2)
- >>> b.func_c_complex(1+2j)
- (1+2j)
- >>> b.func_c_string('hei', None, u'tere', 'b')
- ('hei', None, u'tere', 'b')
-
- >>> import numpy
- >>> m = ExtensionModule('test_CTypePython_numpy')
- >>> f = PyCFunction('func_int')
- >>> f += PyCArgument('i1', numpy.int8, output_intent='return')
- >>> f += PyCArgument('i2', numpy.int16, output_intent='return')
- >>> f += PyCArgument('i3', numpy.int32, output_intent='return')
- >>> f += PyCArgument('i4', numpy.int64, output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_uint')
- >>> f += PyCArgument('i1', numpy.uint8, output_intent='return')
- >>> f += PyCArgument('i2', numpy.uint16, output_intent='return')
- >>> f += PyCArgument('i3', numpy.uint32, output_intent='return')
- >>> f += PyCArgument('i4', numpy.uint64, output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_float')
- >>> f += PyCArgument('f1', numpy.float32, output_intent='return')
- >>> f += PyCArgument('f2', numpy.float64, output_intent='return')
- >>> f += PyCArgument('f3', numpy.float128, output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_complex')
- >>> f += PyCArgument('c1', numpy.complex64, output_intent='return')
- >>> f += PyCArgument('c2', numpy.complex128, output_intent='return')
- >>> f += PyCArgument('c3', numpy.complex256, output_intent='return')
- >>> m += f
- >>> f = PyCFunction('func_array')
- >>> f += PyCArgument('a1', numpy.ndarray, output_intent='return')
- >>> m += f
- >>> b = m.build() #doctest: +ELLIPSIS
- exec_command...
- >>> b.func_int(numpy.int8(-2), numpy.int16(-3), numpy.int32(-4), numpy.int64(-5))
- (-2, -3, -4, -5)
- >>> b.func_uint(numpy.uint8(-1), numpy.uint16(-1), numpy.uint32(-1), numpy.uint64(-1))
- (255, 65535, 4294967295, 18446744073709551615)
- >>> b.func_float(numpy.float32(1.2),numpy.float64(1.2),numpy.float128(1.2))
- (1.20000004768, 1.2, 1.19999999999999995559)
- >>> b.func_complex(numpy.complex64(1+2j),numpy.complex128(1+2j),numpy.complex256(1+2j))
- ((1+2j), (1+2j), (1.0+2.0j))
- >>> b.func_array(numpy.array([1,2]))
- array([1, 2])
- >>> b.func_array(numpy.array(2))
- array(2)
- >>> b.func_array(2)
- Traceback (most recent call last):
- ...
- TypeError: argument 1 must be numpy.ndarray, not int
- >>> b.func_array(numpy.int8(2))
- Traceback (most recent call last):
- ...
- TypeError: argument 1 must be numpy.ndarray, not numpy.int8
- """
-
- typeinfo_map = dict(
- # <key>: (<type object in C>, <C type>, <ArgFmt>, <RetFmt>, <init value in C decl stmt>)
- int = ('PyInt_Type', 'PyIntObject*', 'O!', 'N', 'NULL'),
- long = ('PyLong_Type', 'PyLongObject*', 'O!', 'N', 'NULL'),
- float = ('PyFloat_Type', 'PyFloatObject*', 'O!', 'N', 'NULL'),
- complex = ('PyComplex_Type', 'PyComplexObject*', 'O!', 'N', 'NULL'),
- str = ('PyString_Type', 'PyStringObject*', 'S', 'N', 'NULL'),
- unicode = ('PyUnicode_Type', 'PyUnicodeObject*', 'U', 'N', 'NULL'),
- buffer = ('PyBuffer_Type', 'PyBufferObject*', 'O!', 'N', 'NULL'),
- tuple = ('PyTuple_Type', 'PyTupleObject*', 'O!', 'N', 'NULL'),
- list = ('PyList_Type', 'PyListObject*', 'O!', 'N', 'NULL'),
- dict = ('PyDict_Type', 'PyDictObject*', 'O!', 'N', 'NULL'),
- file = ('PyFile_Type', 'PyFileObject*', 'O!', 'N', 'NULL'),
- instance = ('PyInstance_Type', 'PyObject*', 'O!', 'N', 'NULL'),
- function = ('PyFunction_Type', 'PyFunctionObject*', 'O!', 'N', 'NULL'),
- method = ('PyMethod_Type', 'PyObject*', 'O!', 'N', 'NULL'),
- module = ('PyModule_Type', 'PyObject*', 'O!', 'N', 'NULL'),
- iter = ('PySeqIter_Type', 'PyObject*', 'O!', 'N', 'NULL'),
- property = ('PyProperty_Type', 'PyObject*', 'O!', 'N', 'NULL'),
- slice = ('PySlice_Type', 'PyObject*', 'O!', 'N', 'NULL'),
- cell = ('PyCell_Type', 'PyCellObject*', 'O!', 'N', 'NULL'),
- generator = ('PyGen_Type', 'PyGenObject*', 'O!', 'N', 'NULL'),
- set = ('PySet_Type', 'PySetObject*', 'O!', 'N', 'NULL'),
- frozenset = ('PyFrozenSet_Type', 'PySetObject*', 'O!', 'N', 'NULL'),
- cobject = (None, 'PyCObject*', 'O', 'N', 'NULL'),
- type = ('PyType_Type', 'PyTypeObject*', 'O!', 'N', 'NULL'),
- object = (None, 'PyObject*', 'O', 'N', 'NULL'),
- numpy_ndarray = ('PyArray_Type', 'PyArrayObject*', 'O!', 'N', 'NULL'),
- numpy_descr = ('PyArrayDescr_Type','PyArray_Descr', 'O!', 'N', 'NULL'),
- numpy_ufunc = ('PyUFunc_Type', 'PyUFuncObject*', 'O!', 'N', 'NULL'),
- numpy_iter = ('PyArrayIter_Type', 'PyArrayIterObject*', 'O!', 'N', 'NULL'),
- numpy_multiiter = ('PyArrayMultiIter_Type', 'PyArrayMultiIterObject*', 'O!', 'N', 'NULL'),
- numpy_int8 = ('PyInt8ArrType_Type', 'PyInt8ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_int16 = ('PyInt16ArrType_Type', 'PyInt16ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_int32 = ('PyInt32ArrType_Type', 'PyInt32ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_int64 = ('PyInt64ArrType_Type', 'PyInt64ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_int128 = ('PyInt128ArrType_Type', 'PyInt128ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_uint8 = ('PyUInt8ArrType_Type', 'PyUInt8ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_uint16 = ('PyUInt16ArrType_Type', 'PyUInt16ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_uint32 = ('PyUInt32ArrType_Type', 'PyUInt32ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_uint64 = ('PyUInt64ArrType_Type', 'PyUInt64ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_uint128 = ('PyUInt128ArrType_Type', 'PyUInt128ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_float16 = ('PyFloat16ArrType_Type', 'PyFloat16ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_float32 = ('PyFloat32ArrType_Type', 'PyFloat32ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_float64 = ('PyFloat64ArrType_Type', 'PyFloat64ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_float80 = ('PyFloat80ArrType_Type', 'PyFloat80ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_float96 = ('PyFloat96ArrType_Type', 'PyFloat96ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_float128 = ('PyFloat128ArrType_Type', 'PyFloat128ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_complex32 = ('PyComplex32ArrType_Type', 'PyComplex32ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_complex64 = ('PyComplex64ArrType_Type', 'PyComplex64ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_complex128 = ('PyComplex128ArrType_Type', 'PyComplex128ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_complex160 = ('PyComplex160ArrType_Type', 'PyComplex160ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_complex192 = ('PyComplex192ArrType_Type', 'PyComplex192ScalarObject*', 'O!', 'N', 'NULL'),
- numpy_complex256 = ('PyComplex256ArrType_Type', 'PyComplex256ScalarObject*', 'O!', 'N', 'NULL'),
- numeric_array = ('PyArray_Type', 'PyArrayObject*', 'O!', 'N', 'NULL'),
- c_char = (None, 'char', 'b', 'b', '0'),
- c_unsigned_char = (None, 'unsigned char', 'B', 'B', '0'),
- c_short = (None, 'short int', 'h', 'h', '0'),
- c_unsigned_short = (None, 'unsigned short int', 'H', 'H', '0'),
- c_int = (None,'int', 'i', 'i', '0'),
- c_unsigned_int = (None,'unsigned int', 'I', 'I', '0'),
- c_long = (None,'long', 'l', 'l', '0'),
- c_unsigned_long = (None,'unsigned long', 'k', 'k', '0'),
- c_long_long = (None,'PY_LONG_LONG', 'L', 'L', '0'),
- c_unsigned_long_long = (None,'unsigned PY_LONG_LONG', 'K', 'K', '0'),
- c_Py_ssize_t = (None,'Py_ssize_t', 'n', 'n', '0'),
- c_char1 = (None,'char', 'c', 'c', '"\\0"'),
- c_float = (None,'float', 'f', 'f', '0.0'),
- c_double = (None,'double', 'd', 'd', '0.0'),
- c_Py_complex = (None,'Py_complex', 'D', 'D', '{0.0, 0.0}'),
- c_const_char_ptr = (None,'const char *', 'z', 'z', 'NULL'),
- c_Py_UNICODE = (None,'Py_UNICODE*','u','u', 'NULL'),
- )
-
- def initialize(self, typeobj):
- m = self.typeinfo_map
-
- key = None
- if isinstance(typeobj, type):
- if typeobj.__module__=='__builtin__':
- key = typeobj.__name__
- if key=='array':
- key = 'numeric_array'
- elif typeobj.__module__=='numpy':
- key = 'numpy_' + typeobj.__name__
- elif isinstance(typeobj, str):
- key = typeobj
- if key.startswith('numpy_'):
- k = key[6:]
- named_scalars = ['byte','short','int','long','longlong',
- 'ubyte','ushort','uint','ulong','ulonglong',
- 'intp','uintp',
- 'float_','double',
- 'longfloat','longdouble',
- 'complex_',
- ]
- if k in named_scalars:
- import numpy
- key = 'numpy_' + getattr(numpy, k).__name__
-
- try: item = m[key]
- except KeyError:
- raise NotImplementedError('%s: need %s support' % (self.__class__.__name__, typeobj))
-
- self.typeobj_name = key
- self.ctypeobj = item[0]
- self.name = item[1]
- self.pyarg_fmt = item[2]
- self.pyret_fmt = item[3]
- self.cinit_value = item[4]
-
- if key.startswith('numpy_'):
- self.add(Component.get('arrayobject.h'), 'Header')
- self.add(Component.get('import_array'), 'ModuleInit')
-
- if key.startswith('numeric_'):
- raise NotImplementedError(self.__class__.__name__ + ': Numeric support')
- return self
-
- def set_titles(self, arg):
- if self.typeobj_name == 'object':
- tn = 'a python ' + self.typeobj_name
- else:
- if self.typeobj_name.startswith('numpy_'):
- tn = 'a numpy.' + self.typeobj_name[6:] + ' object'
- elif self.typeobj_name.startswith('c_'):
- n = self.typeobj_name[2:]
- if not n.startswith('Py_'):
- n = ' '.join(n.split('_'))
- tn = 'a to C ' + n + ' convertable object'
- else:
- tn = 'a python ' + self.typeobj_name + ' object'
- if arg.input_intent!='hide':
- r = ''
- if arg.input_title: r = ', ' + arg.input_title
- arg.input_title = tn + r
- if arg.output_intent!='hide':
- r = ''
- if arg.output_title: r = ', ' + arg.output_title
- arg.output_title = tn + r
-
- def get_pyarg_fmt(self, arg):
- if arg.input_intent=='hide': return None
- return self.pyarg_fmt
-
- def get_pyarg_obj(self, arg):
- if arg.input_intent=='hide': return None
- if self.pyarg_fmt=='O!':
- return '&%s, &%s' % (self.ctypeobj, arg.pycvar)
- return '&' + arg.pycvar
-
- def get_pyret_fmt(self, arg):
- if arg.output_intent=='hide': return None
- return self.pyret_fmt
-
- def get_pyret_obj(self, arg):
- if arg.output_intent=='return':
- if self.get_pyret_fmt(arg)=='D':
- return '&' + arg.retpycvar
- return arg.retpycvar
- return
-
- def get_init_value(self, arg):
- return self.cinit_value
-
-def register():
- Component.register(
- )
-
-def _test():
- import doctest
- doctest.testmod()
-
-if __name__ == "__main__":
- _test()
diff --git a/numpy/f2py/lib/extgen/converters.py b/numpy/f2py/lib/extgen/converters.py
deleted file mode 100644
index 182c95339..000000000
--- a/numpy/f2py/lib/extgen/converters.py
+++ /dev/null
@@ -1,22 +0,0 @@
-
-from base import Component
-from c_code import CCode
-
-Component.register(
- CCode('''
-static int pyobj_to_int(PyObject *obj, int* value) {
- int status = 1;
- if (PyInt_Check(obj)) {
- *value = PyInt_AS_LONG(obj);
- status = 0;
- }
- return status;
-}
-''', provides='pyobj_to_int'),
- CCode('''\
-static PyObject* pyobj_from_int(int* value) {
- return PyInt_FromLong(*value);
-}
-''', provides='pyobj_from_int'),
-
- )
diff --git a/numpy/f2py/lib/extgen/extension_module.py b/numpy/f2py/lib/extgen/extension_module.py
deleted file mode 100644
index 2336bc859..000000000
--- a/numpy/f2py/lib/extgen/extension_module.py
+++ /dev/null
@@ -1,195 +0,0 @@
-
-from base import Component
-
-class ExtensionModule(Component):
-
- """
- ExtensionModule(<modulename>, *components, numpy=False, provides=..)
-
- Hello example:
-
- >>> # in general use:
- >>> # from numpy.f2py.lib.extgen import *
- >>> # instead of the following import statement
- >>> from __init__ import * #doctest: +ELLIPSIS
- Ignoring...
- >>> f = PyCFunction('hello', title='Say Hello\\nand Bye.')
- >>> f += 'printf("Hello!\\\\n");'
- >>> f += 'printf("Bye!\\\\n");'
- >>> m = ExtensionModule('foo', f, title='Hello module', description='First line.\\nSecond line.')
- >>> foo = m.build() #doctest: +ELLIPSIS
- exec_command...
- >>> foo.hello()
- >>> # you should now see Hello! printed to stdout stream.
-
- We now add a new function to module and rebuild. But we need to change the
- module name as one cannot reload extension modules in Python.
-
- >>> m.modulename = 'foo2'
- >>> m += PyCFunction('hi', 'printf("Hi\\\\n");', title='Say just Hi.')
- >>> foo = m.build() #doctest: +ELLIPSIS
- exec_command...
- >>> print foo.__doc__ #doctest: +ELLIPSIS
- This module "foo2" is generated with ExtGen from NumPy version ...
- <BLANKLINE>
- Hello module
- <BLANKLINE>
- Description:
- First line.
- Second line.
- <BLANKLINE>
- Functions:
- hello() -> None
- Say Hello
- and Bye.
- hi() -> None
- Say just Hi.
- """
-
- container_options = dict(\
- Header=dict(default='<KILLLINE>'),
- TypeDef=dict(default='<KILLLINE>'),
- Extern=dict(default='<KILLLINE>'),
- CCode=dict(default='<KILLLINE>'),
- CAPICode=dict(default='<KILLLINE>'),
- ObjDecl=dict(default='<KILLLINE>'),
- ModuleMethod=dict(suffix=',', skip_suffix_when_empty=True,separator=',\n',
- default='<KILLLINE>', use_indent=True),
- ModuleInit=dict(default='<KILLLINE>', use_indent=True),
-
- ModuleTitle = dict(default='<KILLLINE>',prefix='"\\n\\n',suffix='"',separator='\\n"\n" ',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map = {'\n':'\\n'}),
- ModuleDescr = dict(default='<KILLLINE>',prefix='"\\n\\nDescription:\\n"\n" ',
- suffix='"',separator='\\n"\n" ',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
- ModuleFuncDoc = dict(default='<KILLLINE>', prefix='"\\n\\nFunctions:\\n"\n" ',
- separator='\\n"\n" ', suffix='"',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
- )
-
- component_container_map = dict(PyCFunction = 'CAPICode')
-
- template = '''\
-/* -*- c -*- */
-/* This Python C/API extension module "%(modulename)s" is generated
- using extgen tool. extgen is part of numpy.f2py.lib package
- developed by Pearu Peterson <pearu.peterson@gmail.com>.
-*/
-
-#ifdef __cplusplus
-extern \"C\" {
-#endif
-
-%(Header)s
-%(TypeDef)s
-%(Extern)s
-%(CCode)s
-%(CAPICode)s
-%(ObjDecl)s
-
-static PyObject* extgen_module;
-
-static PyMethodDef extgen_module_methods[] = {
- %(ModuleMethod)s
- {NULL,NULL,0,NULL}
-};
-
-static char %(modulename)s_doc[] =
-"This module \\"%(modulename)s\\" is generated with ExtGen from NumPy version %(numpy_version)s."
-%(ModuleTitle)s
-%(ModuleDescr)s
-%(ModuleFuncDoc)s
-;
-
-PyMODINIT_FUNC init%(modulename)s(void) {
- PyObject* extgen_module_dict = NULL;
- PyObject* extgen_str_obj = NULL;
-
- extgen_module = Py_InitModule("%(modulename)s", extgen_module_methods);
- if ((extgen_module_dict = PyModule_GetDict(extgen_module))==NULL) goto capi_error;
- if ((extgen_str_obj = PyString_FromString(%(modulename)s_doc))==NULL) goto capi_error;
- PyDict_SetItemString(extgen_module_dict, "__doc__", extgen_str_obj);
- Py_DECREF(extgen_str_obj);
-
- %(ModuleInit)s
-
- return;
-capi_error:
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_RuntimeError, "failed to initialize %(modulename)s module.");
- }
- return;
-}
-
-#ifdef __cplusplus
-}
-#endif
-'''
-
- def initialize(self, modulename, *components, **options):
- self.modulename = modulename
- self._provides = options.pop('provides',
- '%s_%s' % (self.__class__.__name__, modulename))
-
- self.title = options.pop('title', None)
- self.description = options.pop('description', None)
-
- if options: self.warning('%s unused options: %s\n' % (self.__class__.__name__, options))
-
- # all Python extension modules require Python.h
- self.add(Component.get('Python.h'), 'Header')
- if options.get('numpy'):
- self.add(Component.get('arrayobject.h'), 'Header')
- self.add(Component.get('import_array'), 'ModuleInit')
- map(self.add, components)
- return self
-
- def update_containers(self):
- if self.title is not None:
- self.container_ModuleTitle += self.title
- if self.description is not None:
- self.container_ModuleDescr += self.description
-
- def build(self):
- import os
- import sys
- extfile = self.generate()
- srcfile = os.path.abspath('%smodule.c' % (self.modulename))
- f = open(srcfile, 'w')
- f.write(extfile)
- f.close()
- modulename = self.modulename
- setup_py = """
-def configuration(parent_package='', top_path = ''):
- from numpy.distutils.misc_util import Configuration
- config = Configuration('',parent_package,top_path)
- config.add_extension('%(modulename)s',
- sources = ['%(srcfile)s'])
- return config
-if __name__ == '__main__':
- from numpy.distutils.core import setup
- setup(configuration=configuration)
-""" % (locals())
- setupfile = os.path.abspath('setup_extgen.py')
- f = open(setupfile, 'w')
- f.write(setup_py)
- f.close()
- setup_args = ['build_ext','--build-lib','.']
- setup_cmd = ' '.join([sys.executable,setupfile]+setup_args)
- build_dir = '.'
- from numpy.distutils.exec_command import exec_command
- status, output = exec_command(setup_cmd)
- if status:
- raise "Failed to build (status=%s)." % (`status`)
- exec 'import %s as m' % (modulename)
- return m
-
-def _test():
- import doctest
- doctest.testmod()
-
-if __name__ == "__main__":
- _test()
diff --git a/numpy/f2py/lib/extgen/predefined_components.py b/numpy/f2py/lib/extgen/predefined_components.py
deleted file mode 100644
index a24a9fec4..000000000
--- a/numpy/f2py/lib/extgen/predefined_components.py
+++ /dev/null
@@ -1,23 +0,0 @@
-
-from base import Component
-from c_code import CCode
-
-Component.register(
-
- CCode('#include "Python.h"', provides='Python.h'),
-
- CCode('''\
-#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
-#include "numpy/arrayobject.h"
-#include "numpy/arrayscalars.h"
-''', provides='arrayobject.h'),
-
- CCode('''\
-import_array();
-if (PyErr_Occurred()) {
- PyErr_SetString(PyExc_ImportError, "failed to load array module.");
- goto capi_error;
-}
-''', provides='import_array')
-
- )
diff --git a/numpy/f2py/lib/extgen/pyc_argument.py b/numpy/f2py/lib/extgen/pyc_argument.py
deleted file mode 100644
index 3af09932a..000000000
--- a/numpy/f2py/lib/extgen/pyc_argument.py
+++ /dev/null
@@ -1,130 +0,0 @@
-
-from base import Component
-
-class PyCArgument(Component):
-
- """
- PyCArgument(<name>, ctype, *components, provides=..,
- input_intent = 'required' | 'optional' | 'extra' | 'hide',
- output_intent = 'hide' | 'return',
- input_title = None,
- output_title = None,
- input_description = None,
- output_description = None,
- depends = []
- )
-
- """
-
- template = '%(name)s'
-
- component_container_map = dict(CDecl = 'Decl')
-
- def initialize(self, name, ctype=None, *components, **options):
- self.name = name
- self._provides = options.pop('provides',
- '%s_%s' % (self.__class__.__name__, name))
- self.input_intent = options.pop('input_intent','required') # 'optional', 'extra', 'hide'
- self.output_intent = options.pop('output_intent','hide') # 'return'
- self.input_title = options.pop('input_title', None)
- self.output_title = options.pop('output_title', None)
- self.input_description = options.pop('input_description', None)
- self.output_description = options.pop('output_description', None)
- self.depends = options.pop('depends', [])
-
- if options: self.warning('%s unused options: %s\n' % (self.__class__.__name__, options))
-
- map(self.add, components)
-
- self.cvar = name
- self.pycvar = None
- self.retpycvar = None
-
- if ctype is None:
- ctype = object
- if isinstance(ctype, Component.CTypeBase):
- pass
- elif isinstance(ctype, type) or Component.CTypePython.typeinfo_map.has_key(ctype):
- ctype = Component.CTypePython(ctype)
- else:
- ctype = Component.CType(ctype)
- self.ctype = ctype
-
- retfmt = ctype.get_pyret_fmt(self)
- if isinstance(ctype, Component.CTypePython):
- if retfmt and retfmt in 'SON':
- if self.output_intent == 'return':
- if self.input_intent=='hide':
- self.retpycvar = name
- else:
- self.pycvar = name
- self.retpycvar = name + '_return'
- elif self.input_intent!='hide':
- self.pycvar = name
- else:
- self.pycvar = name
- self.retpycvar = name
- else:
- self.pycvar = name + '_pyc'
- self.retpycvar = name + '_pyc_r'
-
- ctype.set_titles(self)
- ctype.set_Decl(self)
-
- return self
-
- def update_containers(self):
- evaluate = self.evaluate
- ctype = self.ctype
-
- # update PyCFunction containers
- input_doc_title = '%s - %s' % (self.name, self.input_title)
- output_doc_title = '%s - %s' % (self.name, self.output_title)
- if self.input_description is not None:
- input_doc_descr = ' %s' % (self.input_description)
- else:
- input_doc_descr = None
- if self.output_description is not None:
- output_doc_descr = ' %s' % (self.output_description)
- else:
- output_doc_descr = None
-
- if self.input_intent=='required':
- self.container_ReqArgs += self.name
- self.container_ReqKWList += '"' + self.name + '"'
- self.container_ReqArgFmt += ctype.get_pyarg_fmt(self)
- self.container_ReqArgObj += ctype.get_pyarg_obj(self)
- self.container_ReqArgsDoc += input_doc_title
- self.container_ReqArgsDoc += input_doc_descr
- elif self.input_intent=='optional':
- self.container_OptArgs += self.name
- self.container_OptKWList += '"' + self.name + '"'
- self.container_OptArgFmt += ctype.get_pyarg_fmt(self)
- self.container_OptArgObj += ctype.get_pyarg_obj(self)
- self.container_OptArgsDoc += input_doc_title
- self.container_OptArgsDoc += input_doc_descr
- elif self.input_intent=='extra':
- self.container_ExtArgs += self.name
- self.container_ExtKWList += '"' + self.name + '"'
- self.container_ExtArgFmt += ctype.get_pyarg_fmt(self)
- self.container_ExtArgObj += ctype.get_pyarg_obj(self)
- self.container_ExtArgsDoc += input_doc_title
- self.container_ExtArgsDoc += input_doc_descr
- elif self.input_intent=='hide':
- pass
- else:
- raise NotImplementedError('input_intent=%r' % (self.input_intent))
-
- if self.output_intent=='return':
- self.container_RetArgs += self.name
- self.container_RetFmt += ctype.get_pyret_fmt(self)
- self.container_RetObj += ctype.get_pyret_obj(self)
- self.container_RetDoc += output_doc_title
- self.container_RetDoc += output_doc_descr
- elif self.output_intent=='hide':
- pass
- else:
- raise NotImplementedError('output_intent=%r' % (self.output_intent))
-
- return
-
diff --git a/numpy/f2py/lib/extgen/pyc_function.py b/numpy/f2py/lib/extgen/pyc_function.py
deleted file mode 100644
index 1cd16c99b..000000000
--- a/numpy/f2py/lib/extgen/pyc_function.py
+++ /dev/null
@@ -1,237 +0,0 @@
-
-from base import Component
-
-class PyCFunction(Component):
-
- """
- PyCFunction(<name>, *components, provides=..,title=.., description=..)
-
- >>> from __init__ import * #doctest: +ELLIPSIS
- Ignoring...
- >>> f = PyCFunction('hello', title='A function.', description='\\nFirst line.\\n2nd line.')
- >>> a1_in_doc = '''First line.\\nSecond line.'''
- >>> a1_out_doc = '''Single line.'''
- >>> f += PyCArgument('a1',output_intent='return', input_title='anything',
- ... input_description=a1_in_doc, output_description=a1_out_doc)
- >>> f += PyCArgument('c1',input_intent='extra')
- >>> f += PyCArgument('b1',input_intent='optional')
- >>> f += PyCArgument('d2',input_intent='hide', output_intent='return')
- >>> f += PyCArgument('a2',input_intent='required')
- >>> f += PyCArgument('c2',input_intent='extra')
- >>> f += PyCArgument('b2',input_intent='optional')
- >>> m = ExtensionModule('test_PyCFunction', f)
- >>> foo = m.build() #doctest: +ELLIPSIS
- exec_command...
- >>> print foo.hello.__doc__
- hello(a1, a2 [, b1, b2, c1, c2]) -> (a1, d2)
- <BLANKLINE>
- A function.
- <BLANKLINE>
- Required arguments:
- a1 - a python object, anything
- First line.
- Second line.
- a2 - a python object
- <BLANKLINE>
- Optional arguments:
- b1 - a python object
- b2 - a python object
- <BLANKLINE>
- Extra optional arguments:
- c1 - a python object
- c2 - a python object
- <BLANKLINE>
- Return values:
- a1 - a python object
- Single line.
- d2 - a python object
- <BLANKLINE>
- Description:
- <BLANKLINE>
- First line.
- 2nd line.
- >>> print foo.hello(1, 2)
- (1, None)
- """
-
- container_options = dict(\
- Args = dict(separator=', '),
-
- ReqArgs = dict(separator=', '),
- OptArgs = dict(separator=', '),
- ExtArgs = dict(separator=', '),
- RetArgs = dict(separator=', ', prefix='(', suffix=')', default = 'None',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True),
-
- OptExtArgs = dict(separator=', ', prefix=' [, ', skip_prefix_when_empty=True,
- suffix=']', skip_suffix_when_empty=True),
-
- FuncTitle = dict(default='<KILLLINE>',prefix='"\\n\\n',suffix='"',separator='\\n"\n" ',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
- FuncDescr = dict(default='<KILLLINE>',prefix='"\\n\\nDescription:\\n"\n" ',
- suffix='"',separator='\\n"\n" ',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
- ReqArgsDoc = dict(default='<KILLLINE>', prefix='"\\n\\nRequired arguments:\\n"\n" ',
- separator='\\n"\n" ', suffix='"',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
- OptArgsDoc = dict(default='<KILLLINE>', prefix='"\\n\\nOptional arguments:\\n"\n" ',
- separator='\\n"\n" ', suffix='"',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
- ExtArgsDoc = dict(default='<KILLLINE>', prefix='"\\n\\nExtra optional arguments:\\n"\n" ',
- separator='\\n"\n" ', suffix='"',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
- RetDoc = dict(default='"Return value:\\n None\\n"', prefix='"\\n\\nReturn values:\\n"\n" ',
- separator='\\n"\n" ', suffix='"',
- skip_prefix_when_empty=True, skip_suffix_when_empty=True,
- use_firstline_indent=True, replace_map={'\n':'\\n'}),
-
- Decl = dict(default='<KILLLINE>', use_indent=True),
-
- ReqKWList = dict(separator=', ', suffix=', ', skip_suffix_when_empty=True),
- OptKWList = dict(separator=', ', suffix=', ', skip_suffix_when_empty=True),
- ExtKWList = dict(separator=', ', suffix=', ', skip_suffix_when_empty=True),
-
- ReqArgFmt = dict(separator=''),
- OptArgFmt = dict(separator=''),
- ExtArgFmt = dict(separator=''),
- OptExtArgFmt = dict(separator='', prefix='|', skip_prefix_when_empty=True),
-
- ReqArgObj = dict(separator=', ', prefix=', ', skip_prefix_when_empty=True),
- OptArgObj = dict(separator=', ', prefix=', ', skip_prefix_when_empty=True),
- ExtArgObj = dict(separator=', ', prefix=', ', skip_prefix_when_empty=True),
-
- FromPyObj = dict(default='<KILLLINE>', use_indent=True),
- Exec = dict(default='<KILLLINE>', use_indent=True),
- PyObjFrom = dict(default='<KILLLINE>', use_indent=True),
-
- RetFmt = dict(separator=''),
- RetObj = dict(separator=', ', prefix=', ', skip_prefix_when_empty=True),
-
- CleanPyObjFrom = dict(default='<KILLLINE>', reverse=True, use_indent=True),
- CleanExec = dict(default='<KILLLINE>', reverse=True, use_indent=True),
- CleanFromPyObj = dict(default='<KILLLINE>', reverse=True, use_indent=True),
- )
-
- component_container_map = dict(CCode = 'Exec',
- PyCArgument = 'Args',
- CDecl = 'Decl')
-
- template = '''
-static char %(pyc_name)s_doc[] =
-" %(name)s(%(ReqArgs)s%(OptExtArgs)s) -> %(RetArgs)s"
-%(FuncTitle)s
-%(ReqArgsDoc)s
-%(OptArgsDoc)s
-%(ExtArgsDoc)s
-%(RetDoc)s
-%(FuncDescr)s
-;
-
-static PyObject*
-%(pyc_name)s
-(PyObject *pyc_self, PyObject *pyc_args, PyObject *pyc_keywds) {
- PyObject * volatile pyc_buildvalue = NULL;
- volatile int capi_success = 1;
- %(Decl)s
- static char *capi_kwlist[] = {%(ReqKWList)s%(OptKWList)s%(ExtKWList)sNULL};
- if (PyArg_ParseTupleAndKeywords(pyc_args, pyc_keywds,"%(ReqArgFmt)s%(OptExtArgFmt)s",
- capi_kwlist%(ReqArgObj)s%(OptArgObj)s%(ExtArgObj)s)) {
- %(FromPyObj)s
- %(Exec)s
- capi_success = !PyErr_Occurred();
- if (capi_success) {
- %(PyObjFrom)s
- pyc_buildvalue = Py_BuildValue("%(RetFmt)s"%(RetObj)s);
- %(CleanPyObjFrom)s
- }
- %(CleanExec)s
- %(CleanFromPyObj)s
- }
- return pyc_buildvalue;
-}
-'''
-
- def initialize(self, name, *components, **options):
- self.name = name
- self.pyc_name = 'pyc_function_'+name
- self._provides = options.pop('provides',
- '%s_%s' % (self.__class__.__name__, name))
- self.title = options.pop('title', None)
- self.description = options.pop('description', None)
-
- if options: self.warning('%s unused options: %s\n' % (self.__class__.__name__, options))
-
- map(self.add, components)
- return self
-
- def init_containers(self):
- return
-
- def update_containers(self):
- evaluate = self.evaluate
-
- # update ExtensionModule containers:
- t = '{"%(name)s", (PyCFunction)%(pyc_name)s,\n METH_VARARGS | METH_KEYWORDS, %(pyc_name)s_doc}'
- self.container_ModuleMethod.add(evaluate(t), self.name)
-
- # update local containers:
- self.container_OptExtArgs += self.container_OptArgs + self.container_ExtArgs
- self.container_OptExtArgFmt += self.container_OptArgFmt + self.container_ExtArgFmt
- self.container_ModuleFuncDoc += evaluate('%(name)s(%(ReqArgs)s%(OptExtArgs)s) -> %(RetArgs)s')
- if self.title is not None:
- self.container_FuncTitle += self.title
- self.container_ModuleFuncDoc += ' ' + self.title
- if self.description is not None:
- self.container_FuncDescr += self.description
-
- # resolve dependencies
- sorted_arguments = []
- sorted_names = []
- comp_map = {}
- dep_map = {}
- for (c,l) in self.components:
- if not isinstance(c, Component.PyCArgument):
- continue
- d = [n for n in c.depends if n not in sorted_names]
- if not d:
- sorted_arguments.append((c,l))
- sorted_names.append(c.name)
- else:
- comp_map[c.name] = (c,l)
- dep_map[c.name] = d
-
- while dep_map:
- dep_map_copy = dep_map.copy()
- for name, deps in dep_map.items():
- d = [n for n in deps if dep_map.has_key(n)]
- if not d:
- sorted_arguments.append(comp_map[name])
- del dep_map[name]
- else:
- dep_map[name] = d
- if dep_map_copy==dep_map:
- self.warnign('%s: detected cyclic dependencies in %r, incorrect behavior is expected.\n'\
- % (self.provides, dep_map))
- sorted_arguments += dep_map.values()
- break
-
- for c, l in sorted_arguments:
- old_parent = c.parent
- c.parent = self
- c.ctype.set_converters(c)
- c.parent = old_parent
-
- return
-
-
-def _test():
- import doctest
- doctest.testmod()
-
-if __name__ == "__main__":
- _test()