b0VIM 6.4 nE8 kent-andkent-and-laptop~kent-and/Instant/Instant-0.8/src/Instant.py3210#"! Utpw]xqVlV3adwDC6 x o m K F 2  x a E .  y l k K  m I  ` 7  a3jA}EDC}H1XFkjiA5s`J - A Python string containing C or C++ function, class, .... - B{code}: ========== Arguments: an ordinary Python module. SWIG is used to generate code that can be compiled and used as Call this function to instantly create an extension module. """ def create_extension(self, **args): return 0 # all ok return 1 # Parsing of argurments detected errors print 'This is not the case for',file print 'Source files must have \'.c\' or \'.cpp\' suffix!' else: self.srcs.append(file) elif file.endswith('.c'): self.cppsrcs.append(file) if file.endswith('.cpp'): for file in self.sources: self.cppsrcs = [] self.srcs = [] # depending on the file-suffix (.c or .cpp). # sources has to be put in different variables, self.ifile_name = self.module+".i" self.logfile_name = self.module+".log" self.makefile_name = self.module+".mak" self.additional_definitions = dict[key] elif key == 'additional_definitions': self.arrays = dict[key] elif key == 'arrays': self.object_files = dict[key] elif key == 'object_files': self.cppargs = dict[key] elif key == 'cppargs': self.library_dirs = dict[key] elif key == 'library_dirs': self.libraries = dict[key] elif key == 'libraries': self.include_dirs = dict[key] elif key == 'include_dirs': self.wrap_headers = dict[key] elif key == 'wrap_headers': self.local_headers = dict[key] elif key == 'local_headers': self.headers = dict[key] elif key == 'headers': self.sources = dict[key] elif key == 'sources': self.init_code = dict[key] elif key == 'init_code': self.swigopts = dict[key] elif key == 'swigopts': self.module = dict[key] elif key == 'module': self.code = dict[key] if key == 'code': for key in dict.keys(): """ A method for parsing arguments. """ def parse_args(self, dict): pass """ For now, empty! """ def __init__(self): additional_definitions = "" arrays = [] object_files = [] cppargs = '' library_dirs = [] libraries = [] include_dirs = ['-I.'] sources = [] wrap_headers = [] local_headers = [] headers = [] init_code = ' //Code for initialisation here' swigopts = '-I.' module = 'instant_swig_module' gen_setup = 1 }""" printf("No code supplied!\\n");{void f() code = """ # Default values:class Instant:VERBOSE = 0import stringimport commands import os, sys,re""">>> print "The sum of 3 and 4.5 is ", add_func(3, 4.5)>>> add_func = inline(\"double add(double a, double b){ return a+b; }\")>>> from Instant import inlineA simple example: (see test1.py)it has to be inside a function or a similar C/C++ construct.The code can be either C or C++, but like when programming C or C++,an inline module, except you have to import the module manually.be created at runtime. For the user, it behaves somewhat likeBy using the class Instant a Python extension module can"""adVf  xp? u E D 5 4   ` 4  q 3    r / L  9&fl:N 654  return (includes,flags,libs, libdirs) raise OSError, "The pkg-config file %s does not exist" % pack else: for i in tmp: libdirs.append(i[2:]) tmp = string.split(commands.getoutput("pkg-config --libs-only-L %s " % pack )) for i in tmp: libs.append(i[2:]) tmp = string.split(commands.getoutput("pkg-config --libs-only-l %s " % pack )) for i in tmp: flags.append(i) tmp = string.split(commands.getoutput("pkg-config --cflags-only-other %s " % pack )) for i in tmp: includes.append(i[2:]) tmp = string.split(commands.getoutput("pkg-config --cflags-only-I %s " % pack )) if commands.getstatusoutput("pkg-config --exists %s " % pack)[0] == 0: # print commands.getstatusoutput("pkg-config --exists %s " % pack) for pack in packages: libdirs = [] libs = [] flags = [] includes = [] """ (includes, flags, libraries, libdirs) = header_and_libs_from_pkgconfig(list_of_packages) The usage is: This function returns list of include files, flags, libraries and library directories obtain from a pkgconfig file. """def header_and_libs_from_pkgconfig(*packages): return func_name exec("from inline_ext_numarray import %s as func_name"% func_name) init_code='import_array();', arrays = args_dict["arrays"]) + sys.version[:3] + "/numarray"], include_dirs= [sys.prefix + "/include/python" headers=["arrayobject.h"], cppargs='-O3', ext.create_extension(code=c_code, module="inline_ext_numarray", ret, func_name = func.split() func = c_code[:c_code.index('(')] ext = Instant() """ >>> sum_func(a) >>> a = numarray.arange(10000000); a = numarray.sin(a) >>> sum_func = inline_with_numarray(c_code, arrays = [['n1', 'array1']]) \"\"\" } return tmp; } tmp += array1[i]; for (int i=0; i>> c_code = \"\"\" >>> from Instant import inline_with_numarray >>> import time >>> import numarray Usage: The following example illustrates that. this function and the inline function is that C-arrays can be used. to inline one C function each time. The difference between the input is a valid C function. It is only possible It creates an extension module given that in Instant. This is a short wrapper around the create_extention function """def inline_with_numarray(c_code, **args_dict): return func_name exec("from inline_ext_numeric import %s as func_name"% func_name) init_code='import_array();', arrays = args_dict["arrays"]) + sys.version[:3] + "/Numeric"],