def dump_def_public(self): # Init dump string. dumped = '' # Write function definition to receive Python objects. dumped += 'PyObject *%s' % self.name dumped += '(PyObject *self, PyObject *args)\n{\n' # Init variables. for i, itype in enumerate(self.itypes): typename = types.full_name(itype) arg = self.args[i] if itype == 'P': arg += '_' dumped += '\t%s %s;\n' % (typename, arg) # Convert input matrix to Python spec. pytypes = [types.python_char(x) for x in self.itypes] pytypes = ''.join(pytypes) # Create a comma-separated list of variable addresses. addresses = [] for i, itype in enumerate(self.itypes): arg = self.args[i] if itype == 'P': arg += '_' addresses.append('&%s' % arg) addresses = ', '.join(addresses) # Write the ParseTuple function. formatter = pytypes, addresses dumped += '\tPyArg_ParseTuple(args, "%s", %s);\n' % formatter # Redirect pixel buffer address with given pointer. for i, itype in enumerate(self.itypes): if itype == 'P': arg = self.args[i] bits, linkage = platform.architecture() if bits == '32bit': cast = '(unsigned char*)(long int)' if bits == '64bit': cast = '(unsigned char*)' dumped += '\tunsigned char *%s = %s%s_;\n' % (arg, cast, arg) # Return dump string for this function. return dumped
def perform_returns(self): if self.function.private: return returnvars = re.search('return (.+)', self.cline) if not returnvars: return returnvars = returnvars.group(1) if returnvars == '0': self.cline = re.sub( 'return 0', 'return Py_BuildValue("")', self.cline) else: otypes = self.function.otypes pytypes = [types.python_char(x) for x in otypes] pytypes = ''.join(pytypes) returnvars = '"%s", %s' % (pytypes, returnvars) self.cline = re.sub( 'return (.+)', 'return Py_BuildValue(%s)' % returnvars, self.cline)