From 2c0ba843963eac41fab3b677f8d186e9210f0fad Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 4 Mar 2016 14:51:59 -0800 Subject: [PATCH] size_t experiments --- etg/_core.py | 1 + etg/defs.py | 4 +-- src/size_t.sip | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/size_t.sip diff --git a/etg/_core.py b/etg/_core.py index 14385949..908a2a3d 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -31,6 +31,7 @@ ITEMS = [ ] # promoted script to be the same as its NAME. INCLUDES = [ # base and core stuff + 'size_t', 'defs', 'debug', 'object', diff --git a/etg/defs.py b/etg/defs.py index dffb8dfc..f311cab7 100644 --- a/etg/defs.py +++ b/etg/defs.py @@ -49,11 +49,11 @@ def run(): if sys.maxsize > 2**32: module.find('wxIntPtr').type = 'long long' module.find('wxUIntPtr').type = 'unsigned long long' - module.insertItemAfter(td, etgtools.TypedefDef(type='unsigned long long', name='size_t')) + #module.insertItemAfter(td, etgtools.TypedefDef(type='unsigned long long', name='size_t')) else: module.find('wxIntPtr').type = 'long' module.find('wxUIntPtr').type = 'unsigned long' - module.insertItemAfter(td, etgtools.TypedefDef(type='unsigned long', name='size_t')) + #module.insertItemAfter(td, etgtools.TypedefDef(type='unsigned long', name='size_t')) # Correct the types for these as their values are outside the range of int diff --git a/src/size_t.sip b/src/size_t.sip new file mode 100644 index 00000000..0f64d162 --- /dev/null +++ b/src/size_t.sip @@ -0,0 +1,85 @@ +//-------------------------------------------------------------------------- +// Name: size_t.sip + +// Purpose: Implements a %MappedType for size_t in order to +// deal with different sizeof's on different platforms. It's 32bit +// on some, 64bit on others. +// +// Author: Robin Dunn +// +// Created: 4-March-2016 +// Copyright: (c) 2016 by Total Control Software +// Licence: wxWindows license +//-------------------------------------------------------------------------- + + +// These types can have difference sizes based on the platform and +// architecture. Have SIP always treat them as long longs. + +typedef unsigned long long size_t; + + +//%MappedType size_t { + + //%TypeHeaderCode + //#include + //typedef size_t foosize_t; + //%End + + //%ConvertToTypeCode + //// Code to test an incoming PyObject for compatibility + //if (!sipIsErr) { + //if (PyNumber_Check(sipPy)) + //return TRUE; + //return FALSE; + //} + + //// Code to convert from a compatible PyObject + //#if wxSIZE_T_IS_ULONG + //*sipCppPtr = new size_t(PyLong_AsUnsignedLong(sipPy)); + //#else + //*sipCppPtr = new size_t(PyLong_AsUnsignedLongLong(sipPy)); + //#endif + //return sipGetState(sipTransferObj); + //%End + + //%ConvertFromTypeCode + //#if wxSIZE_T_IS_ULONG + //return PyLong_FromUnsignedLong(*sipCpp); + //#else + //return PyLong_FromUnsignedLongLong(*sipCpp); + //#endif + //%End +//}; + + +// Used just for testing the MappedType code, it can be removed later +%ModuleCode +size_t test_size_t(size_t value) +{ + size_t local = value; + return local; +} + +void printIntSizes() +{ + printf("**** sizeof(int): %d\n", sizeof(int)); + printf("**** sizeof(long): %d\n", sizeof(long)); + printf("**** sizeof(long long): %d\n", sizeof(long long)); + + printf("**** sizeof(size_t): %d\n", sizeof(size_t)); + printf("**** sizeof(time_t): %d\n", sizeof(time_t)); + + printf("**** sizeof(wxIntPtr): %d\n", sizeof(wxIntPtr)); + printf("**** sizeof(wxUIntPtr): %d\n", sizeof(wxUIntPtr)); + printf("**** sizeof(wxFileOffset): %d\n", sizeof(wxFileOffset)); + +} +%End + +size_t test_size_t(size_t value); +void printIntSizes(); + + + +