[Pyrex] pointer to function

Stefano Esposito stefano.esposito87 at gmail.com
Sun Sep 9 12:38:39 CEST 2007


On Sun, 09 Sep 2007 13:31:42 +1200
Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Stefano Esposito wrote:
> > 		alpm_set_dlcb (dl_cb) <-- failing here
> 
> How did you declare alpm_set_dlcb? It needs to
> be declared as taking a function pointer with
> appropriate signature.

i looked in the Demos/ of the source distribution of pyrex and found an appropriate example now i declare:
	
	ctypedef void (*alpm_cb_download) (char *filename, int xferred, int total)
	void alpm_option_set_dlcb (alpm_cb_download cb)

were the .h files declares

	typedef void (*alpm_cb_download) (const char *filename, int xfered, int total);
	void alpm_option_set_dlcb (alpm_cb_download cb)

and all goes fine for pyrexc. However gcc spit out a warning of incompatible pointer type when passing a C function defined in pyrex, even when casting it to alpm_cb_download:

	cdef void dl_cb(char *filename, int trans, int tot):
        	pydl_cb (filename, trans, tot)

	...

	def init (...):
		alpm_option_set_dlcb (<alpm_cb_download>dl_cb)            <-- this gives a warning
	...

I think the warning is about the char * instead of const char *... if it's so, this could be a problem on runtime?

-- 
Stefano Esposito <stefano.esposito87 at gmail.com>



More information about the Pyrex mailing list