some type system updates

This commit is contained in:
timerix 2022-09-06 15:53:13 +06:00
parent 21b20e5e14
commit e63056d244
11 changed files with 119 additions and 96 deletions

View File

@ -98,9 +98,9 @@ Maybe __ReadName(DeserializeSharedData* shared){
case '}': case '}':
if(!calledRecursively || nameStr.length!=0) if(!calledRecursively || nameStr.length!=0)
safethrow_wrongchar(c,;); safethrow_wrongchar(c,;);
return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,NULL)); return SUCCESS(UniHeap(kerepTypeId_CharPtr,NULL));
case ':': case ':':
return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,string_extract(nameStr))); return SUCCESS(UniHeap(kerepTypeId_CharPtr,string_extract(nameStr)));
case '$': case '$':
if(nameStr.length!=0) if(nameStr.length!=0)
safethrow_wrongchar(c,;); safethrow_wrongchar(c,;);
@ -113,7 +113,7 @@ Maybe __ReadName(DeserializeSharedData* shared){
} }
if(nameStr.length>0) safethrow(ERR_ENDOFSTR,;); if(nameStr.length>0) safethrow(ERR_ENDOFSTR,;);
return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,NULL)); return SUCCESS(UniHeap(kerepTypeId_CharPtr,NULL));
} }
#define ReadName() __ReadName(shared) #define ReadName() __ReadName(shared)
@ -137,7 +137,7 @@ Maybe __ReadString(DeserializeSharedData* shared){
} }
else { else {
char* str=StringBuilder_build(b).ptr; char* str=StringBuilder_build(b).ptr;
return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,str)); return SUCCESS(UniHeap(kerepTypeId_CharPtr,str));
} }
} }
else { else {
@ -163,7 +163,7 @@ Maybe __ReadList(DeserializeSharedData* shared){
} }
} }
return SUCCESS(UniPtrHeap(kerepTypeId_AutoarrUnitypePtr,list)); return SUCCESS(UniHeap(kerepTypeId_AutoarrUnitypePtr,list));
}; };
#define ReadList() __ReadList(shared) #define ReadList() __ReadList(shared)
@ -321,7 +321,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
} }
else{ else{
list=Autoarr_create(Unitype,ARR_BC,ARR_BL); list=Autoarr_create(Unitype,ARR_BC,ARR_BL);
Hashtable_add(dict,nameCPtr,UniPtrHeap(kerepTypeId_AutoarrUnitypePtr,list)); Hashtable_add(dict,nameCPtr,UniHeap(kerepTypeId_AutoarrUnitypePtr,list));
} }
Autoarr_add(list,val.value); Autoarr_add(list,val.value);
} }
@ -331,7 +331,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
END: END:
*_text=text; *_text=text;
return SUCCESS(UniPtrHeap(kerepTypeId_HashtablePtr,dict)); return SUCCESS(UniHeap(kerepTypeId_HashtablePtr,dict));
} }
Maybe DtsodV24_deserialize(char* _text) { Maybe DtsodV24_deserialize(char* _text) {

View File

@ -126,5 +126,5 @@ Maybe DtsodV24_serialize(Hashtable* dtsod){
StringBuilder* sb=StringBuilder_create(); StringBuilder* sb=StringBuilder_create();
try(__serialize(sb,0,dtsod),__, StringBuilder_free(sb)); try(__serialize(sb,0,dtsod),__, StringBuilder_free(sb));
char* str=StringBuilder_build(sb).ptr; char* str=StringBuilder_build(sb).ptr;
return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr, str)); return SUCCESS(UniHeap(kerepTypeId_CharPtr, str));
} }

View File

@ -1,5 +1,8 @@
#include "string.h" #include "string.h"
kerepTypeId_define(kerepTypeId_string);
kerepTypeId_define(kerepTypeId_stringPtr);
// copies str content to new char pointer value (adding '\0' at the end) // copies str content to new char pointer value (adding '\0' at the end)
char* string_extract(string str){ char* string_extract(string str){
if(str.length==0) return NULL; if(str.length==0) return NULL;

View File

@ -12,6 +12,8 @@ typedef struct string{
char* ptr; // char pointer char* ptr; // char pointer
uint32 length; // amount of chars in ptr value uint32 length; // amount of chars in ptr value
} string; } string;
kerepTypeId_declare(kerepTypeId_string);
kerepTypeId_declare(kerepTypeId_stringPtr);
static const string stringNull={NULL,0}; static const string stringNull={NULL,0};

View File

@ -6,92 +6,98 @@
void kerepTypeDescriptors_initKerepTypes(){ void kerepTypeDescriptors_initKerepTypes(){
// null // null
kerepType_register(NULL, kerepTypeId_Null, NULL); kerepType_register(NULL, kerepTypeId_Null, NULL, NULL);
// base types // base types
kerepType_register(char, kerepTypeId_Char, NULL); kerepType_register(char, kerepTypeId_Char, NULL, NULL);
kerepType_register(bool, kerepTypeId_Bool, NULL); kerepType_register(bool, kerepTypeId_Bool, NULL, NULL);
kerepType_register(float32, kerepTypeId_Float32, NULL); kerepType_register(float32, kerepTypeId_Float32, NULL, NULL);
kerepType_register(float64, kerepTypeId_Float64, NULL); kerepType_register(float64, kerepTypeId_Float64, NULL, NULL);
kerepType_register(int8, kerepTypeId_Int8, NULL); kerepType_register(int8, kerepTypeId_Int8, NULL, NULL);
kerepType_register(uint8, kerepTypeId_UInt8, NULL); kerepType_register(uint8, kerepTypeId_UInt8, NULL, NULL);
kerepType_register(int16, kerepTypeId_Int16, NULL); kerepType_register(int16, kerepTypeId_Int16, NULL, NULL);
kerepType_register(uint16, kerepTypeId_UInt16, NULL); kerepType_register(uint16, kerepTypeId_UInt16, NULL, NULL);
kerepType_register(int32, kerepTypeId_Int32, NULL); kerepType_register(int32, kerepTypeId_Int32, NULL, NULL);
kerepType_register(uint32, kerepTypeId_UInt32, NULL); kerepType_register(uint32, kerepTypeId_UInt32, NULL, NULL);
kerepType_register(int64, kerepTypeId_Int64, NULL); kerepType_register(int64, kerepTypeId_Int64, NULL, NULL);
kerepType_register(uint64, kerepTypeId_UInt64, NULL); kerepType_register(uint64, kerepTypeId_UInt64, NULL, NULL);
// base type pointers // base type pointers
kerepType_register(char*, kerepTypeId_CharPtr, NULL); kerepType_register(char*, kerepTypeId_CharPtr, NULL, NULL);
kerepType_register(bool*, kerepTypeId_BoolPtr, NULL); kerepType_register(bool*, kerepTypeId_BoolPtr, NULL, NULL);
kerepType_register(float32*, kerepTypeId_Float32Ptr, NULL); kerepType_register(float32*, kerepTypeId_Float32Ptr, NULL, NULL);
kerepType_register(float64*, kerepTypeId_Float64Ptr, NULL); kerepType_register(float64*, kerepTypeId_Float64Ptr, NULL, NULL);
kerepType_register(int8*, kerepTypeId_Int8Ptr, NULL); kerepType_register(int8*, kerepTypeId_Int8Ptr, NULL, NULL);
kerepType_register(uint8*, kerepTypeId_UInt8Ptr, NULL); kerepType_register(uint8*, kerepTypeId_UInt8Ptr, NULL, NULL);
kerepType_register(int16*, kerepTypeId_Int16Ptr, NULL); kerepType_register(int16*, kerepTypeId_Int16Ptr, NULL, NULL);
kerepType_register(uint16*, kerepTypeId_UInt16Ptr, NULL); kerepType_register(uint16*, kerepTypeId_UInt16Ptr, NULL, NULL);
kerepType_register(int32*, kerepTypeId_Int32Ptr, NULL); kerepType_register(int32*, kerepTypeId_Int32Ptr, NULL, NULL);
kerepType_register(uint32*, kerepTypeId_UInt32Ptr, NULL); kerepType_register(uint32*, kerepTypeId_UInt32Ptr, NULL, NULL);
kerepType_register(int64*, kerepTypeId_Int64Ptr, NULL); kerepType_register(int64*, kerepTypeId_Int64Ptr, NULL, NULL);
kerepType_register(uint64*, kerepTypeId_UInt64Ptr, NULL); kerepType_register(uint64*, kerepTypeId_UInt64Ptr, NULL, NULL);
// kerepTypeDescriptor
kerepType_register(kerepTypeDescriptor, kerepTypeId_kerepTypeDescriptor, NULL, NULL);
kerepType_register(kerepTypeDescriptor*, kerepTypeId_kerepTypeDescriptorPtr, NULL, NULL);
// base type autoarrs // base type autoarrs
kerepType_register(Autoarr_char, kerepTypeId_AutoarrChar, ____Autoarr_free_char); kerepType_register(Autoarr_char, kerepTypeId_AutoarrChar, ____Autoarr_free_char, NULL);
kerepType_register(Autoarr_bool, kerepTypeId_AutoarrBool, ____Autoarr_free_bool); kerepType_register(Autoarr_bool, kerepTypeId_AutoarrBool, ____Autoarr_free_bool, NULL);
kerepType_register(Autoarr_float32, kerepTypeId_AutoarrFloat32, ____Autoarr_free_float32); kerepType_register(Autoarr_float32, kerepTypeId_AutoarrFloat32, ____Autoarr_free_float32, NULL);
kerepType_register(Autoarr_float64, kerepTypeId_AutoarrFloat64, ____Autoarr_free_float64); kerepType_register(Autoarr_float64, kerepTypeId_AutoarrFloat64, ____Autoarr_free_float64, NULL);
kerepType_register(Autoarr_int8, kerepTypeId_AutoarrInt8, ____Autoarr_free_int8); kerepType_register(Autoarr_int8, kerepTypeId_AutoarrInt8, ____Autoarr_free_int8, NULL);
kerepType_register(Autoarr_uint8, kerepTypeId_AutoarrUInt8, ____Autoarr_free_uint8); kerepType_register(Autoarr_uint8, kerepTypeId_AutoarrUInt8, ____Autoarr_free_uint8, NULL);
kerepType_register(Autoarr_int16, kerepTypeId_AutoarrInt16, ____Autoarr_free_int16); kerepType_register(Autoarr_int16, kerepTypeId_AutoarrInt16, ____Autoarr_free_int16, NULL);
kerepType_register(Autoarr_uint16, kerepTypeId_AutoarrUInt16, ____Autoarr_free_uint16); kerepType_register(Autoarr_uint16, kerepTypeId_AutoarrUInt16, ____Autoarr_free_uint16, NULL);
kerepType_register(Autoarr_int32, kerepTypeId_AutoarrInt32, ____Autoarr_free_int32); kerepType_register(Autoarr_int32, kerepTypeId_AutoarrInt32, ____Autoarr_free_int32, NULL);
kerepType_register(Autoarr_uint32, kerepTypeId_AutoarrUInt32, ____Autoarr_free_uint32); kerepType_register(Autoarr_uint32, kerepTypeId_AutoarrUInt32, ____Autoarr_free_uint32, NULL);
kerepType_register(Autoarr_int64, kerepTypeId_AutoarrInt64, ____Autoarr_free_int64); kerepType_register(Autoarr_int64, kerepTypeId_AutoarrInt64, ____Autoarr_free_int64, NULL);
kerepType_register(Autoarr_uint64, kerepTypeId_AutoarrUInt64, ____Autoarr_free_uint64); kerepType_register(Autoarr_uint64, kerepTypeId_AutoarrUInt64, ____Autoarr_free_uint64, NULL);
// base type autoarr pointers // base type autoarr pointers
kerepType_register(Autoarr_char*, kerepTypeId_AutoarrCharPtr, ____Autoarr_free_char); kerepType_register(Autoarr_char*, kerepTypeId_AutoarrCharPtr, ____Autoarr_free_char, NULL);
kerepType_register(Autoarr_bool*, kerepTypeId_AutoarrBoolPtr, ____Autoarr_free_bool); kerepType_register(Autoarr_bool*, kerepTypeId_AutoarrBoolPtr, ____Autoarr_free_bool, NULL);
kerepType_register(Autoarr_float32*, kerepTypeId_AutoarrFloat32Ptr, ____Autoarr_free_float32); kerepType_register(Autoarr_float32*, kerepTypeId_AutoarrFloat32Ptr, ____Autoarr_free_float32, NULL);
kerepType_register(Autoarr_float64*, kerepTypeId_AutoarrFloat64Ptr, ____Autoarr_free_float64); kerepType_register(Autoarr_float64*, kerepTypeId_AutoarrFloat64Ptr, ____Autoarr_free_float64, NULL);
kerepType_register(Autoarr_int8*, kerepTypeId_AutoarrInt8Ptr, ____Autoarr_free_int8); kerepType_register(Autoarr_int8*, kerepTypeId_AutoarrInt8Ptr, ____Autoarr_free_int8, NULL);
kerepType_register(Autoarr_uint8*, kerepTypeId_AutoarrUInt8Ptr, ____Autoarr_free_uint8); kerepType_register(Autoarr_uint8*, kerepTypeId_AutoarrUInt8Ptr, ____Autoarr_free_uint8, NULL);
kerepType_register(Autoarr_int16*, kerepTypeId_AutoarrInt16Ptr, ____Autoarr_free_int16); kerepType_register(Autoarr_int16*, kerepTypeId_AutoarrInt16Ptr, ____Autoarr_free_int16, NULL);
kerepType_register(Autoarr_uint16*, kerepTypeId_AutoarrUInt16Ptr, ____Autoarr_free_uint16); kerepType_register(Autoarr_uint16*, kerepTypeId_AutoarrUInt16Ptr, ____Autoarr_free_uint16, NULL);
kerepType_register(Autoarr_int32*, kerepTypeId_AutoarrInt32Ptr, ____Autoarr_free_int32); kerepType_register(Autoarr_int32*, kerepTypeId_AutoarrInt32Ptr, ____Autoarr_free_int32, NULL);
kerepType_register(Autoarr_uint32*, kerepTypeId_AutoarrUInt32Ptr, ____Autoarr_free_uint32); kerepType_register(Autoarr_uint32*, kerepTypeId_AutoarrUInt32Ptr, ____Autoarr_free_uint32, NULL);
kerepType_register(Autoarr_int64*, kerepTypeId_AutoarrInt64Ptr, ____Autoarr_free_int64); kerepType_register(Autoarr_int64*, kerepTypeId_AutoarrInt64Ptr, ____Autoarr_free_int64, NULL);
kerepType_register(Autoarr_uint64*, kerepTypeId_AutoarrUInt64Ptr, ____Autoarr_free_uint64); kerepType_register(Autoarr_uint64*, kerepTypeId_AutoarrUInt64Ptr, ____Autoarr_free_uint64, NULL);
// Unitype // Unitype
kerepType_register(Unitype, kerepTypeId_Unitype, __UnitypePtr_free); kerepType_register(Unitype, kerepTypeId_Unitype, __UnitypePtr_free, NULL);
kerepType_register(Unitype*, kerepTypeId_UnitypePtr, __UnitypePtr_free); kerepType_register(Unitype*, kerepTypeId_UnitypePtr, __UnitypePtr_free, NULL);
kerepType_register(Autoarr_Unitype, kerepTypeId_AutoarrUnitype, ____Autoarr_free_Unitype_); kerepType_register(Autoarr_Unitype, kerepTypeId_AutoarrUnitype, ____Autoarr_free_Unitype_, NULL);
kerepType_register(Autoarr_Unitype*, kerepTypeId_AutoarrUnitypePtr, ____Autoarr_free_Unitype_); kerepType_register(Autoarr_Unitype*, kerepTypeId_AutoarrUnitypePtr, ____Autoarr_free_Unitype_, NULL);
// replacing autogenerated freear() function to custom // replacing autogenerated freear() function to custom
Autoarr_Unitype* _uar=Autoarr_create(Unitype, 1, 1); Autoarr_Unitype* _uar=Autoarr_create(Unitype, 1, 1);
_uar->functions->freear=__Autoarr_free_Unitype_; _uar->functions->freear=__Autoarr_free_Unitype_;
Autoarr_free(_uar, true); Autoarr_free(_uar, true);
// SearchTreeNode // SearchTreeNode
kerepType_register(STNode, kerepTypeId_STNode, __STNode_free); kerepType_register(STNode, kerepTypeId_STNode, __STNode_free, NULL);
kerepType_register(STNode*, kerepTypeId_STNodePtr, __STNode_free); kerepType_register(STNode*, kerepTypeId_STNodePtr, __STNode_free, NULL);
// KeyValuePair // KeyValuePair
kerepType_register(KVPair, kerepTypeId_KVPair, __KVPair_free); kerepType_register(KVPair, kerepTypeId_KVPair, __KVPair_free, NULL);
kerepType_register(KVPair*, kerepTypeId_KVPairPtr, __KVPair_free); kerepType_register(KVPair*, kerepTypeId_KVPairPtr, __KVPair_free, NULL);
kerepType_register(Autoarr_KVPair, kerepTypeId_AutoarrKVPair, ____Autoarr_free_KVPair_); kerepType_register(Autoarr_KVPair, kerepTypeId_AutoarrKVPair, ____Autoarr_free_KVPair_, NULL);
kerepType_register(Autoarr_KVPair*, kerepTypeId_AutoarrKVPairPtr, ____Autoarr_free_KVPair_); kerepType_register(Autoarr_KVPair*, kerepTypeId_AutoarrKVPairPtr, ____Autoarr_free_KVPair_, NULL);
// replacing autogenerated freear() function to custom // replacing autogenerated freear() function to custom
Autoarr_KVPair* _kvpar=Autoarr_create(KVPair, 1, 1); Autoarr_KVPair* _kvpar=Autoarr_create(KVPair, 1, 1);
_kvpar->functions->freear=__Autoarr_free_KVPair_; _kvpar->functions->freear=__Autoarr_free_KVPair_;
Autoarr_free(_kvpar, true); Autoarr_free(_kvpar, true);
// Hashtable // Hashtable
kerepType_register(Hashtable, kerepTypeId_Hashtable, __Hashtable_free); kerepType_register(Hashtable, kerepTypeId_Hashtable, __Hashtable_free, NULL);
kerepType_register(Hashtable*, kerepTypeId_HashtablePtr, __Hashtable_free); kerepType_register(Hashtable*, kerepTypeId_HashtablePtr, __Hashtable_free, NULL);
// string
kerepType_register(string, kerepTypeId_string, NULL, NULL);
kerepType_register(string*, kerepTypeId_stringPtr, NULL, NULL);
kerepType_register(string, kerepTypeId_AutoarrString, ____Autoarr_free_string, NULL);
kerepType_register(string*, kerepTypeId_AutoarrStringPtr, ____Autoarr_free_string, NULL);
// StringBuilder // StringBuilder
kerepType_register(Autoarr_string, kerepTypeId_AutoarrString, ____Autoarr_free_string); kerepType_register(StringBuilder, kerepTypeId_StringBuilder, __StringBuilder_free, NULL);
kerepType_register(Autoarr_string*, kerepTypeId_AutoarrStringPtr, ____Autoarr_free_string); kerepType_register(StringBuilder*, kerepTypeId_StringBuilderPtr, __StringBuilder_free, NULL);
kerepType_register(StringBuilder, kerepTypeId_StringBuilder, __StringBuilder_free);
kerepType_register(StringBuilder*, kerepTypeId_StringBuilderPtr, __StringBuilder_free);
} }

View File

@ -32,6 +32,9 @@ kerepTypeId_define(kerepTypeId_UInt32Ptr);
kerepTypeId_define(kerepTypeId_Int64Ptr); kerepTypeId_define(kerepTypeId_Int64Ptr);
kerepTypeId_define(kerepTypeId_UInt64Ptr); kerepTypeId_define(kerepTypeId_UInt64Ptr);
kerepTypeId_define(kerepTypeId_kerepTypeDescriptor);
kerepTypeId_define(kerepTypeId_kerepTypeDescriptorPtr);
// type descriptors are stored here during initialization // type descriptors are stored here during initialization
Autoarr(kerepTypeDescriptor)* __kerepTypeDescriptors=NULL; Autoarr(kerepTypeDescriptor)* __kerepTypeDescriptors=NULL;
// here type descriptors are stored when initialization is complited // here type descriptors are stored when initialization is complited
@ -56,16 +59,18 @@ void kerepTypeDescriptors_endInit(){
printf("\e[92minitialized %u type descriptors\n", kerepTypeId_last); printf("\e[92minitialized %u type descriptors\n", kerepTypeId_last);
} }
void __kerepType_register(char* name, int16 size, void (*free_members)(void*)){ void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, int32)){
kerepTypeDescriptor typeDesc={ kerepTypeDescriptor typeDesc={
.name=name, .name=name,
.size=size, .size=size,
.free_members=free_members, .id=++kerepTypeId_last,
.id=++kerepTypeId_last .freeMembers=freeMembers,
.toString=toString
}; };
Autoarr_add(__kerepTypeDescriptors, typeDesc); Autoarr_add(__kerepTypeDescriptors, typeDesc);
} }
kerepTypeDescriptor kerepTypeDescriptor_get(kerepTypeId id){ Maybe kerepTypeDescriptor_get(kerepTypeId id){
return typeDescriptors[id]; if(id>kerepTypeId_last) safethrow("invalid type id",;);
return SUCCESS(UniStack(kerepTypeId_kerepTypeDescriptorPtr, &typeDescriptors[id]));
} }

View File

@ -9,10 +9,12 @@ extern "C" {
typedef uint16 kerepTypeId; typedef uint16 kerepTypeId;
typedef struct kerepTypeDescriptor{ typedef struct kerepTypeDescriptor{
void (*free_members)(void*); // NULL or function which frees all struct members
char* name; char* name;
kerepTypeId id; kerepTypeId id;
uint16 size; uint16 size;
void (*freeMembers)(void*); // NULL or function which frees all struct members
///@return Maybe<char*>
Maybe (*toString)(void*, int32); // NULL or function which generates string representaion of object
} kerepTypeDescriptor; } kerepTypeDescriptor;
#define kerepTypeId_declare(ID_VAR_NAME)\ #define kerepTypeId_declare(ID_VAR_NAME)\
@ -21,15 +23,17 @@ typedef struct kerepTypeDescriptor{
kerepTypeId ID_VAR_NAME=-1 kerepTypeId ID_VAR_NAME=-1
extern kerepTypeId kerepTypeId_last; extern kerepTypeId kerepTypeId_last;
void __kerepType_register(char* name, int16 size, void (*free_members)(void*)); void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, int32));
#define kerepType_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC)\ #define kerepType_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\
__kerepType_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC);\ __kerepType_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\
ID_VAR_NAME=kerepTypeId_last; ID_VAR_NAME=kerepTypeId_last;
void kerepTypeDescriptors_beginInit(); void kerepTypeDescriptors_beginInit();
void kerepTypeDescriptors_endInit(); void kerepTypeDescriptors_endInit();
kerepTypeDescriptor kerepTypeDescriptor_get(kerepTypeId id); /// @param id id of registered type
/// @return Maybe<kerepTypeDescriptor*>
Maybe kerepTypeDescriptor_get(kerepTypeId id);
kerepTypeId_declare(kerepTypeId_Null); kerepTypeId_declare(kerepTypeId_Null);
@ -59,6 +63,9 @@ kerepTypeId_declare(kerepTypeId_UInt32Ptr);
kerepTypeId_declare(kerepTypeId_Int64Ptr); kerepTypeId_declare(kerepTypeId_Int64Ptr);
kerepTypeId_declare(kerepTypeId_UInt64Ptr); kerepTypeId_declare(kerepTypeId_UInt64Ptr);
kerepTypeId_declare(kerepTypeId_kerepTypeDescriptor);
kerepTypeId_declare(kerepTypeId_kerepTypeDescriptorPtr);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@ -5,8 +5,8 @@ kerepTypeId_define(kerepTypeId_UnitypePtr);
void Unitype_free(Unitype u){ void Unitype_free(Unitype u){
kerepTypeDescriptor type=kerepTypeDescriptor_get(u.typeId); kerepTypeDescriptor type=kerepTypeDescriptor_get(u.typeId);
if(type.free_members) if(type.freeMembers)
type.free_members(u.VoidPtr); type.freeMembers(u.VoidPtr);
if(u.allocatedInHeap) if(u.allocatedInHeap)
free(u.VoidPtr); free(u.VoidPtr);
} }

View File

@ -22,20 +22,20 @@ kerepTypeId_declare(kerepTypeId_Unitype);
kerepTypeId_declare(kerepTypeId_UnitypePtr); kerepTypeId_declare(kerepTypeId_UnitypePtr);
#define Uni(TYPE, VAL) (Unitype){\ #define __UniDef(TYPE, VAL) (Unitype){\
.TYPE=VAL, .typeId=kerepTypeId_##TYPE, .allocatedInHeap=false} .TYPE=VAL, .typeId=kerepTypeId_##TYPE, .allocatedInHeap=false}
#define UniInt64(VAL) Uni(Int64, VAL) #define UniInt64(VAL) __UniDef(Int64, VAL)
#define UniUInt64(VAL) Uni(UInt64, VAL) #define UniUInt64(VAL) __UniDef(UInt64, VAL)
#define UniFloat64(VAL) Uni(Float64, VAL) #define UniFloat64(VAL) __UniDef(Float64, VAL)
#define UniBool(VAL) Uni(Bool, VAL) #define UniBool(VAL) __UniDef(Bool, VAL)
#define UniPtrStack(ID_VAR_NAME, VAL) (Unitype){\ #define UniStack(ID_VAR_NAME, VAL) (Unitype){\
.VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=false} .VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=false}
#define UniPtrHeap(ID_VAR_NAME, VAL) (Unitype){\ #define UniHeap(ID_VAR_NAME, VAL) (Unitype){\
.VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=true} .VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=true}
#define UniNull UniPtrStack(kerepTypeId_Null, NULL) #define UniNull UniStack(kerepTypeId_Null, NULL)
#define UniTrue UniBool(true) #define UniTrue UniBool(true)
#define UniFalse UniBool(false) #define UniFalse UniBool(false)

View File

@ -4,7 +4,7 @@ EXPORT void CALL test_marshalling(char* text, KVPair** kptr){
KVPair* k=malloc(sizeof(KVPair)); KVPair* k=malloc(sizeof(KVPair));
k->key="message"; k->key="message";
char* tc=cptr_copy(text); char* tc=cptr_copy(text);
Unitype u=UniPtrHeap(kerepTypeId_CharPtr,tc); Unitype u=UniHeap(kerepTypeId_CharPtr,tc);
k->value=u; k->value=u;
*kptr=k; *kptr=k;
} }

View File

@ -44,11 +44,11 @@ void test_searchtree(){
printuni(u); printuni(u);
ST_push(node,"channel_id", u); ST_push(node,"channel_id", u);
printf(" -> channel_id\n "); printf(" -> channel_id\n ");
u=UniPtrHeap(kerepTypeId_CharPtr, cptr_copy("32.2004")); u=UniHeap(kerepTypeId_CharPtr, cptr_copy("32.2004"));
printuni(u); printuni(u);
ST_push(node,"message_id", u); ST_push(node,"message_id", u);
printf(" -> message_id\n "); printf(" -> message_id\n ");
u=UniPtrStack(kerepTypeId_CharPtr,"some text UwU"); u=UniStack(kerepTypeId_CharPtr,"some text UwU");
printuni(u); printuni(u);
ST_push(node,"text", u); ST_push(node,"text", u);
printf(" -> text\n"); printf(" -> text\n");