-
Notifications
You must be signed in to change notification settings - Fork 1
/
tip445.h
108 lines (94 loc) · 2.47 KB
/
tip445.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef _TIP445_H
#define _TIP445_H
#if TIP445_SHIM
#include <string.h>
#include <assert.h>
#include <limits.h>
/* Just enough of TIP445 to build on Tcl 8.6 */
#ifndef Tcl_ObjInternalRep
# ifdef Tcl_ObjIntRep
typedef Tcl_ObjIntRep Tcl_ObjInternalRep
# else
typedef union Tcl_ObjInternalRep {
struct {
void* ptr1;
void* ptr2;
} twoPtrValue;
struct {
void* ptr;
unsigned long value;
} ptrAndLongRep;
} Tcl_ObjInternalRep;
# endif
#endif
#ifndef Tcl_FetchInternalRep
# ifdef Tcl_FetchIntRep
# define Tcl_FetchInternalRep(obj, type) (Tcl_ObjInternalRep*)Tcl_FetchIntRep(obj, type)
# else
# define Tcl_FetchInternalRep(obj, type) (Tcl_ObjInternalRep*)(((obj)->typePtr == (type)) ? &(obj)->internalRep : NULL)
# endif
#endif
#ifndef Tcl_FreeInternalRep
# ifdef Tcl_FreeIntRep
# define Tcl_FreeInternalRep Tcl_FreeIntRep
# else
static inline void Tcl_FreeInternalRep(Tcl_Obj* obj)
{
if (obj->typePtr) {
if (obj->typePtr && obj->typePtr->freeIntRepProc)
obj->typePtr->freeIntRepProc(obj);
obj->typePtr = NULL;
}
}
# endif
#endif
#ifndef Tcl_StoreInternalRep
# ifdef Tcl_StoreIntRep
# define Tcl_StoreInternalRep(obj, type, ir) Tcl_StoreIntRep(obj, type, (Tcl_ObjIntRep*)ir)
# else
static inline void Tcl_StoreInternalRep(Tcl_Obj* objPtr, const Tcl_ObjType* typePtr, const Tcl_ObjInternalRep* irPtr)
{
Tcl_FreeInternalRep(objPtr);
objPtr->typePtr = typePtr;
memcpy(&objPtr->internalRep, irPtr, sizeof(Tcl_ObjInternalRep));
}
# endif
#endif
#ifndef Tcl_HasStringRep
# define Tcl_HasStringRep(obj) ((obj)->bytes != NULL)
#endif
#ifndef Tcl_InitStringRep
static char* Tcl_InitStringRep(Tcl_Obj* objPtr, const char* bytes, unsigned numBytes)
{
assert(objPtr->bytes == NULL || bytes == NULL);
if (numBytes > INT_MAX) {
Tcl_Panic("max size of a Tcl value (%d bytes) exceeded", INT_MAX);
}
/* Allocate */
if (objPtr->bytes == NULL) {
/* Allocate only as empty - extend later if bytes copied */
objPtr->length = 0;
if (numBytes) {
objPtr->bytes = (char*)attemptckalloc(numBytes + 1);
if (objPtr->bytes == NULL) return NULL;
if (bytes) {
/* Copy */
memcpy(objPtr->bytes, bytes, numBytes);
objPtr->length = (int)numBytes;
}
} else {
//TclInitStringRep(objPtr, NULL, 0);
objPtr->bytes = "";
objPtr->length = 0;
}
} else {
objPtr->bytes = (char*)ckrealloc(objPtr->bytes, numBytes + 1);
objPtr->length = (int)numBytes;
}
/* Terminate */
objPtr->bytes[objPtr->length] = '\0';
return objPtr->bytes;
}
#endif
#endif // TIP445_SHIM
#endif // _TI445_H