[C++-sig] Pyste suggestion for handling returns of void *

Niall Douglas s_sourceforge at nedprod.com
Sat Oct 4 04:51:45 CEST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Boost.Python won't process a method returning void * nor will it 
permit you to set a typedef void *voidptrtype; to an opaque type :( 
Unfortunately some methods in my code return void *'s where you don't 
actually need the return value at all (it's just useful)! This makes 
things difficult for automated wraps.

I suggest getting pyste to cast any methods returning a void * to 
return void instead. I figure most architectures return their value 
in a register so theroretically casting a function pointer to not 
return anything shouldn't cause stack frame corruption.

To do this, patch class Method in declarations.py as follows:

    def PointerDeclaration(self, forceúlse):
        '''Returns a declaration of a pointer to this member 
function.
        @param force: If True, returns a complete pointer declaration 
regardless
        if this function is unique or not. 
        '''
        # Boost.Python won't accept void * returns
        result = self.result.FullName()
        if result=="void*":
            result="void"
            force=True
        if self.static:
            # static methods are like normal functions
            return Function.PointerDeclaration(self, force)
        if self.is_unique and not force:
            return '&%s' % self.FullName()
        else:
            params = ', '.join([x.FullName() for x in 
self.parameters]) 
            const = ''
            if self.const:
                const = 'const'
            return '(%s (%s::*)(%s) %s%s)&%s' %\
                (result, self.class_, params, const, 
self.Exceptions(), self.FullName())  

This probably leaves out virtual functions and may cause problems 
with getting the address of overloaded methods. Still some support 
for void * returns is better than none.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBP341xMEcvDLFGKbPEQKRrwCg0x7lPp3q1KcKqy4jtzcgznLlrMQAn1Dj
onpaowqaSwOo3OEKIiLv3RWX
=Gv+8
-----END PGP SIGNATURE-----




More information about the Cplusplus-sig mailing list