[Pythonmac-SIG] issue on making python extension from C code

farshid farshid.ghods at gmail.com
Fri Aug 17 08:50:03 CEST 2007


Hi ,

I am hitting this very strange issue that i am providing a wrapper  
for some hash method that is 192 bit or ( unsigned long long int  in  
c) .
when i invoke this function from other C code and i run the code it  
returns correct hash value , but when i compile it and install it  
with setup,py ,  the result is something totally different.
Is it that when python convert c code into ".so" file it changes data  
types of variables???  maybe a bug?

Thanks,
Farshid

here is the code
the method is wrapper for tiger method;
typedef unsigned long long int word64;
typedef unsigned long word32;
typedef unsigned char byte;

void tiger(byte*, word64, word64*);
PyObject *wrap_function(PyObject *self, PyObject *args)
{
	word64 result[3];
	char *command;
//	if (!PyArg_ParseTuple(args, "s",&command))
	//	return NULL;
		//printf("command is %s\n",command);
	command = "abc";
	tiger((byte*)command,strlen(command),result);
	char new_str [48];
	 sprintf(new_str,"%08X%08X%08X%08X%08X%08X",(word32)(result[0]>>32), 
(word32)(result[0]),(word32)(result[1]>>32),(word32)(result[1]), 
(word32)(result[2]>>32),(word32)(result[2]));
	 printf("inside wrap_function %s\n",new_str);
	return Py_BuildValue("s",new_str,strlen(new_str));
}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonmac-sig/attachments/20070816/b2aac408/attachment.html 


More information about the Pythonmac-SIG mailing list