diff --git a/haiku/window.cpp b/haiku/window.cpp index b62318c0..947c9dfc 100644 --- a/haiku/window.cpp +++ b/haiku/window.cpp @@ -48,33 +48,34 @@ static void *windowHandle(uiControl *c, void *implData) } // gotta do this because of lack of C99-style initializers in C++11 -static void windowVtable(uiControlVtable *vt) -{ - vt->Size = sizeof (uiControlVtable); - vt->Init = windowInit; - vt->Free = windowFree; - vt->ParentChanging = windowParentChanging; - vt->ParentChanged = windowParentChanged; -} +// see also https://stackoverflow.com/questions/11516657/c-structure-initialization +static const uiControlVtable windowVtable = [](void) { + uiControlVtable vt; -static void windowOSVtable(uiControlOSVtable *osvt) -{ - osvt->Size = sizeof (uiControlOSVtable); - osvt->Handle = windowHandle; -} + memset(&vt, 0, sizeof (uiControlVtable)); + vt.Size = sizeof (uiControlVtable); + vt.Init = windowInit; + vt.Free = windowFree; + vt.ParentChanging = windowParentChanging; + vt.ParentChanged = windowParentChanged; + return vt; +}(); + +static const uiControlOSVtable windowOSVtable = [](void) { + uiControlOSVtable vt; + + memset(&vt, 0, sizeof (uiControlOSVtable)); + vt.Size = sizeof (uiControlOSVtable); + vt.Handle = windowHandle; + return vt; +}(); static uint32_t windowType = 0; uint32_t uiprivSysWindowType(void) { - if (windowType == 0) { - uiControlVtable vt; - uiControlOSVtable osvt; - - windowVtable(&vt); - windowOSVtable(&osvt); - windowType = uiRegisterControlType("uiWindow", &vt, &osvt, sizeof (struct windowImplData)); - } + if (windowType == 0) + windowType = uiRegisterControlType("uiWindow", &windowVtable, &windowOSVtable, sizeof (struct windowImplData)); return windowType; } diff --git a/test/allcalls_haiku.hpp b/test/allcalls_haiku.hpp new file mode 100644 index 00000000..14f3d85b --- /dev/null +++ b/test/allcalls_haiku.hpp @@ -0,0 +1,5 @@ +// 28 may 2019 + +// This file should NOT have include guards as it is intended to be included more than once; see noinitwrongthread_haiku.cpp for details. + +allcallsCase(uiHaikuControlHandle, NULL) diff --git a/test/controls_haiku.cpp b/test/controls_haiku.cpp index afbe89ef..53f65023 100644 --- a/test/controls_haiku.cpp +++ b/test/controls_haiku.cpp @@ -6,17 +6,17 @@ static void *osVtableNopHandle(uiControl *c, void *implData) return NULL; } -static uiControlOSVtable osVtable; -// gotta do this and not have osVtable be const because C++11 -bool osVtableInitialized = false; +static const uiControlOSVtable osVtable = [](void) { + uiControlOSVtable vt; + + memset(&vt, 0, sizeof (uiControlOSVtable)); + vt.Size = sizeof (uiControlOSVtable); + vt.Handle = osVtableNopHandle; + return vt; +}(); const uiControlOSVtable *testOSVtable(void) { - if (!osVtableInitialized) { - osVtableInitialized = false; - osVtable.Size = sizeof (uiControlOSVtable); - osVtable.Handle = osVtableNopHandle; - } return &osVtable; } @@ -42,7 +42,6 @@ Test(ControlOSVtableWithMissingHandleMethodIsProgrammerError) testControlLoadNopVtable(&vtable); ctx = beginCheckProgrammerError("uiRegisterControlType(): required uiControlOSVtable method Handle() missing for uiControl type name"); - testOSVtable(); // TODO clean this up; it has to do with C++ initialization above osvt = osVtable; osvt.Handle = NULL; uiRegisterControlType("name", &vtable, &osvt, 0); diff --git a/test/meson.build b/test/meson.build index d60c593c..cd900ca6 100644 --- a/test/meson.build +++ b/test/meson.build @@ -26,8 +26,12 @@ elif libui_OS == 'darwin' elif libui_OS == 'haiku' libui_test_sources += files([ 'controls_haiku.cpp', + 'noinitwrongthread_haiku.cpp', 'window_haiku.cpp', ]) + libui_allcalls_headers += files([ + 'allcalls_haiku.hpp', + ]) else libui_test_sources += files([ 'controls_unix.c', diff --git a/test/noinitwrongthread_haiku.cpp b/test/noinitwrongthread_haiku.cpp new file mode 100644 index 00000000..7e60f2b4 --- /dev/null +++ b/test/noinitwrongthread_haiku.cpp @@ -0,0 +1,6 @@ +// 28 may 2019 +#include "test_haiku.hpp" +#include "thread.h" + +#define allcallsHeader "allcalls_haiku.hpp" +#include "noinitwrongthreadimpl.h"