WXMSW: use HandleToLong/LongToHandle functions.

On Clang++, casting from a pointer to an integer of a smaller size is
considered an error.  In cases where Windows HANDLEs are converted
to/from longs, use the Windows-provided conversion functions
HandleToLong and LongToHandle.

In a couple of cases, a pointer is being cast to long in a __hash__
function.  These don't seem Windows-specific so it is not safe to assume
the Windows conversion functions are present.  In those cases, fall back
to the (ugly) double-casting that the Windows functions contain.
This commit is contained in:
Jeremy Drake
2021-06-14 11:43:29 -07:00
parent 64e5d863f7
commit 31e6c8ed34
6 changed files with 10 additions and 10 deletions

View File

@@ -106,7 +106,7 @@ def run():
doc='MSW-only method to fetch the windows handle for the bitmap.', doc='MSW-only method to fetch the windows handle for the bitmap.',
body="""\ body="""\
#ifdef __WXMSW__ #ifdef __WXMSW__
return (long)self->GetHandle(); return HandleToLong(self->GetHandle());
#else #else
return 0; return 0;
#endif #endif
@@ -116,7 +116,7 @@ def run():
doc='MSW-only method to set the windows handle for the bitmap.', doc='MSW-only method to set the windows handle for the bitmap.',
body="""\ body="""\
#ifdef __WXMSW__ #ifdef __WXMSW__
self->SetHandle((WXHANDLE)handle); self->SetHandle((WXHANDLE)LongToHandle(handle));
#endif #endif
""") """)

View File

@@ -51,7 +51,7 @@ def run():
c.addCppMethod('long', 'GetHandle', '()', """\ c.addCppMethod('long', 'GetHandle', '()', """\
#ifdef __WXMSW__ #ifdef __WXMSW__
return (long)self->GetHandle(); return HandleToLong(self->GetHandle());
#else #else
return 0; return 0;
#endif""", #endif""",
@@ -59,7 +59,7 @@ def run():
c.addCppMethod('void', 'SetHandle', '(long handle)', """\ c.addCppMethod('void', 'SetHandle', '(long handle)', """\
#ifdef __WXMSW__ #ifdef __WXMSW__
self->SetHandle((WXHANDLE)handle); self->SetHandle((WXHANDLE)LongToHandle(handle));
#endif""", #endif""",
briefDoc="Set the handle to use for this Cursor. Windows only.") briefDoc="Set the handle to use for this Cursor. Windows only.")

View File

@@ -82,7 +82,7 @@ def run():
c.addCppMethod('int', '__nonzero__', '()', "return self->IsOk();") c.addCppMethod('int', '__nonzero__', '()', "return self->IsOk();")
c.addCppMethod('int', '__bool__', '()', "return self->IsOk();") c.addCppMethod('int', '__bool__', '()', "return self->IsOk();")
c.addCppMethod('long', '__hash__', '()', "return (long)self->GetID();") c.addCppMethod('long', '__hash__', '()', "return (long)(intptr_t)self->GetID();")
c.addCppMethod('bool', '__eq__', '(wxDataViewItem* other)', c.addCppMethod('bool', '__eq__', '(wxDataViewItem* other)',
"return other ? (self->GetID() == other->GetID()) : false;") "return other ? (self->GetID() == other->GetID()) : false;")

View File

@@ -257,7 +257,7 @@ def run():
c.addCppMethod('long', 'GetHDC', '()', """\ c.addCppMethod('long', 'GetHDC', '()', """\
#ifdef __WXMSW__ #ifdef __WXMSW__
return (long)self->GetHandle(); return HandleToLong(self->GetHandle());
#else #else
wxPyRaiseNotImplemented(); wxPyRaiseNotImplemented();
return 0; return 0;

View File

@@ -56,7 +56,7 @@ def run():
c.addCppMethod('long', 'GetHandle', '()', """\ c.addCppMethod('long', 'GetHandle', '()', """\
#ifdef __WXMSW__ #ifdef __WXMSW__
return (long)self->GetHandle(); return HandleToLong(self->GetHandle());
#else #else
return 0; return 0;
#endif #endif
@@ -64,7 +64,7 @@ def run():
c.addCppMethod('void', 'SetHandle', '(long handle)', """\ c.addCppMethod('void', 'SetHandle', '(long handle)', """\
#ifdef __WXMSW__ #ifdef __WXMSW__
self->SetHandle((WXHANDLE)handle); self->SetHandle((WXHANDLE)LongToHandle(handle));
#endif #endif
""") """)
@@ -73,7 +73,7 @@ def run():
doc='MSW-only method to create a wx.Icon from a native icon handle.', doc='MSW-only method to create a wx.Icon from a native icon handle.',
body="""\ body="""\
#ifdef __WXMSW__ #ifdef __WXMSW__
return self->CreateFromHICON((WXHICON)hicon); return self->CreateFromHICON((WXHICON)LongToHandle(hicon));
#else #else
return false; return false;
#endif #endif

View File

@@ -47,7 +47,7 @@ def run():
c.addCppMethod('int', '__bool__', '()', "return self->IsOk();") c.addCppMethod('int', '__bool__', '()', "return self->IsOk();")
c.addCppMethod('long', '__hash__', '()', """\ c.addCppMethod('long', '__hash__', '()', """\
return (long)self->GetID(); return (long)(intptr_t)self->GetID();
""") """)
c.addCppMethod('bool', '__eq__', '(wxTreeListItem* other)', c.addCppMethod('bool', '__eq__', '(wxTreeListItem* other)',