Graphviz 12.1.0~dev.20240716.0947
Loading...
Searching...
No Matches
tclhandle.h
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <stdint.h>
12#include <tcl.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/*
19 * Macro to rounded up a size to be a multiple of (void *). This is required
20 * for systems that have alignment restrictions on pointers and data.
21 */
22#define ROUND_ENTRY_SIZE(size) \
23 ((((size) + tclhandleEntryAlignment - 1) / tclhandleEntryAlignment) * \
24 tclhandleEntryAlignment)
25
26#define NULL_IDX UINT64_MAX
27#define ALLOCATED_IDX (UINT64_MAX - 1)
28
29typedef unsigned char ubyte_t;
31
32/*
33 * This is the table header. It is separately allocated from the table body,
34 * since it must keep track of a table body that might move. Each entry in the
35 * table is preceded with a header which has the free list link, which is a
36 * entry index of the next free entry. Special values keep track of allocated
37 * table is preceded with a header which has the free list link, which is a
38 * entry index of the next free entry. Special values keep track of allocated
39 * entries.
40 */
41
42typedef struct {
43 uint64_t entrySize; /* Entry size in bytes, including overhead */
44 uint64_t tableSize; /* Current number of entries in the table */
45 uint64_t freeHeadIdx; /* Index of first free entry in the table */
46 char *handleFormat; /* Malloc'ed copy of prefix string + "%lu" */
47 ubyte_pt bodyPtr; /* Pointer to table body */
50
51typedef struct {
52 uint64_t freeLink;
55
56#define ENTRY_HEADER_SIZE (ROUND_ENTRY_SIZE(sizeof(entryHeader_t)))
57
58/*
59 * This macro is used to return a pointer to an entry, given its index.
60 */
61#define TBL_INDEX(hdrPtr, idx) \
62 ((entryHeader_pt)(hdrPtr->bodyPtr + (hdrPtr->entrySize * idx)))
63
64/*
65 * This macros to convert between pointers to the user and header area of
66 * an table entry.
67 */
68#define USER_AREA(entryPtr) (void *)(((ubyte_pt)entryPtr) + ENTRY_HEADER_SIZE);
69#define HEADER_AREA(entryPtr) \
70 (entryHeader_pt)(((ubyte_pt)entryPtr) - ENTRY_HEADER_SIZE);
71
72void *tclhandleFreeIndex(tblHeader_pt headerPtr, uint64_t entryIdx);
73void *tclhandleFree(tblHeader_pt headerPtr, char *handle);
74tblHeader_pt tclhandleInit(char *prefix, uint64_t entrySize,
75 uint64_t initEntries);
76void *tclhandleXlateIndex(tblHeader_pt headerPtr, uint64_t entryIdx);
77void *tclhandleXlate(tblHeader_pt headerPtr, char *handle);
78entryHeader_pt tclhandleAlloc(tblHeader_pt tblHdrPtr, char **handle,
79 uint64_t *entryIdxPtr);
80int tclhandleIndex(tblHeader_pt tblHdrPtr, char *handle, uint64_t *entryIdxPtr);
81
82#ifdef __cplusplus
83}
84#endif
require define api prefix
Definition gmlparse.y:17
uint64_t freeLink
Definition tclhandle.h:52
uint64_t tableSize
Definition tclhandle.h:44
ubyte_pt bodyPtr
Definition tclhandle.h:47
uint64_t freeHeadIdx
Definition tclhandle.h:45
uint64_t entrySize
Definition tclhandle.h:43
char * handleFormat
Definition tclhandle.h:46
void * tclhandleXlateIndex(tblHeader_pt headerPtr, uint64_t entryIdx)
Definition tclhandle.c:217
tblHeader_t * tblHeader_pt
Definition tclhandle.h:49
void * tclhandleFreeIndex(tblHeader_pt headerPtr, uint64_t entryIdx)
Definition tclhandle.c:261
ubyte_t * ubyte_pt
Definition tclhandle.h:30
void * tclhandleXlate(tblHeader_pt headerPtr, char *handle)
Definition tclhandle.c:241
entryHeader_pt tclhandleAlloc(tblHeader_pt tblHdrPtr, char **handle, uint64_t *entryIdxPtr)
Definition tclhandle.c:123
void * tclhandleFree(tblHeader_pt headerPtr, char *handle)
Definition tclhandle.c:293
int tclhandleIndex(tblHeader_pt tblHdrPtr, char *handle, uint64_t *entryIdxPtr)
Definition tclhandle.c:195
entryHeader_t * entryHeader_pt
Definition tclhandle.h:54
tblHeader_pt tclhandleInit(char *prefix, uint64_t entrySize, uint64_t initEntries)
Definition tclhandle.c:158
unsigned char ubyte_t
Definition tclhandle.h:29