Set up a new system for designated static const struct initializers on C++. Also added the missing noinitwrongthread tests on Haiku.
This commit is contained in:
parent
c07a7861d4
commit
1dd0372593
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -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);
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// 28 may 2019
|
||||
#include "test_haiku.hpp"
|
||||
#include "thread.h"
|
||||
|
||||
#define allcallsHeader "allcalls_haiku.hpp"
|
||||
#include "noinitwrongthreadimpl.h"
|
Loading…
Reference in New Issue