[PyKDE] SIP: size_t?

Gerard Vermeulen gerard.vermeulen at grenoble.cnrs.fr
Tue Mar 21 17:50:43 GMT 2006


On Tue, 21 Mar 2006 18:14:39 +0100
"Giovanni Bajo" <rasky at develer.com> wrote:

> Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> 
> >> what is the correct way of handling size_t? It's not a builtin type that
> >> SIP understands, and any typedef machinery is going to be wrong
> >> (portability-wise).
> >
> > You have to make the typedef dependent on the %Platform.
> 
> Wouldn't be better if SIP did this automatically? A proper definition of
> size_t across 32/64 bit systems (including Win64 vs Linux ABI differences)
> is somehow problematic. Compilers do supply "size_t" specifically so that
> people don't have to worry doing the ifdef-ery.
> -- 
My configure.py calculates the type of size_t, when needed (the function
compile_qt_program has been copied from PyQt's configure.py):

def check_compiler(configuration, options):
    """Check compiler specifics
    """
    print 'Do not get upset by error messages in the next 4 compiler checks:'
    
    makefile = sipconfig.Makefile(configuration)
    generator = makefile.optional_string('MAKEFILE_GENERATOR', 'UNIX')
    if generator in ['MSVC', 'MSVC.NET']:
        options.extra_cxxflags.extend(['-GR'])

    program = os.linesep.join([
        r'#include <stddef.h>',
        r'class a { public: void f(size_t); };',
        r'void a::f(%s) {};',
        r'int main() { return 0; }',
        r'',
        ])
    name = "size_t_check.cpp"
    new = [
        '// Automagically generated by configure.py',
        '',
        '// Uncomment one of the following four lines',
        ]

    for ctype in ('int', 'long', 'unsigned int', 'unsigned long'):
        open(name, "w").write(program % ctype)
        print "Check if 'size_t' and '%s' are the same type:" % ctype
        if compile_qt_program(name, configuration):
            comment = ''
            print "YES"
        else:
            print "NO"
            comment =  '//'
        new.append('%stypedef %s size_t;' % (comment, ctype))

    new.extend(['',
                '// Local Variables:',
                '// mode: C++',
                '// c-file-style: "stroustrup"',
                '// End:',
                '',
                ])

    # Warning: SIP-4.4 does not parse \r\n in SIP files, even on Windows.
    new = '\n'.join(new)
    types_sip = os.path.join(os.pardir, 'sip', options.qwt, 'QwtTypes.sip')
    if os.access(types_sip, os.R_OK):
        old = open(types_sip, 'r').read()
    else:
        old = ''
    if old != new:
        open(types_sip, 'w').write(new)    
    
    return options

# check_compiler()

Gerard




More information about the PyQt mailing list