From e2842bae3554b67705445be55332fb03f0a889b6 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 8 Jun 2019 09:58:25 -0400 Subject: [PATCH] Oops, forgot to put Size in uiControlVtable. Let's go! --- doc/controls.md | 5 ++++- ui.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/controls.md b/doc/controls.md index 9a06e953..6435aea0 100644 --- a/doc/controls.md +++ b/doc/controls.md @@ -25,6 +25,7 @@ uint32_t uiControlType(void); ```c typedef struct uiControlVtable uiControlVtable; struct uiControlVtable { + size_t Size; bool (*Init)(uiControl *c, void *implData, void *initData); void (*Free)(uiControl *c, void *implData); }; @@ -32,6 +33,8 @@ struct uiControlVtable { `uiControlVtable` describes the set of functions that control implementations need to implement. When registering your control type, you pass this in as a parameter to `uiRegisterControlType()`. Each method here is required. +You are responsible for allocating and initializing this struct. To do so, you simply zero the memory for this struct and set its `Size` field to `sizeof (uiControlVtable)`. (TODO put this in a common place) + Each method takes at least two parameters. The first, `c`, is the `uiControl` itself. The second, `implData`, is the implementation data pointer; it is the same as the pointer returned by `uiControlImplData(c)`, and is provided here as a convenience. Each method is named for the `uiControl` function that it implements. As such, details on how to implement these methods are documented alongside those functions. For instance, instructions on implementing `Free()` are given under the documentation for `uiControlFree()`. The only exception is `Init()`, which is discussed under `uiNewControl()` below. @@ -46,7 +49,7 @@ uint32_t uiRegisterControlType(uiControlVtable *vtable, uiControlOSVtable *osVta `uiControlVtable` describes the functions of a `uiControl` common between platforms, and is discussed on this page. `uiControlOSVtable` describes functionst hat vary from OS to OS, and are described in the respective OS-specific uiControl implementation pages. -It is a programmer error to specify `NULL` for either vtable. An `implDataSize` of 0 is legal; the implementation data pointer will be `NULL`. This is not particularly useful, however. It is also a programmer error to specify `NULL` for any of the methods in either vtable — that is, all methods are required. +It is a programmer error to specify `NULL` for either vtable. An `implDataSize` of 0 is legal; the implementation data pointer will be `NULL`. This is not particularly useful, however. It is also a programmer error to specify `NULL` for any of the methods in either vtable — that is, all methods are required. It is also a programmer error to pass the wrong value to the `Size` field of either vtable. ### `uiCheckControlType()` diff --git a/ui.h b/ui.h index 467c64d5..bbef596e 100644 --- a/ui.h +++ b/ui.h @@ -70,6 +70,7 @@ uiprivExtern uint32_t uiControlType(void); #define uiControl(obj) ((uiControl *) uiCheckControlType((obj), uiControlType())) struct uiControlVtable { + size_t Size; bool (*Init)(uiControl *c, void *implData, void *initData); void (*Free)(uiControl *c, void *implData); };