theKernel 10.0
Loading...
Searching...
No Matches
MkTypeC_TOR_C_API

MkTypeS - various functions to create, initialize and destroy a typeMore...

+ Collaboration diagram for MkTypeC_TOR_C_API:

Macros

#define MkTypeCreate(clsV, basicV, identV)
 
#define MkTypeForeachInstancesSave(typ)
 

Functions

MK_TYP MkTypeCreate (MK_MACRO_TYP const clsV, MK_MACRO_TYP const basicV, MK_STRN const identV)
 create a new type …
 
MK_TYP MkTypeDup2_RT (MK_RT mkrt, MK_TYPN const typ, MK_STRN const ident)
 duplicate typ to create a lightweight-type
 
MK_OBJ MkTypeAlloc_RT (MK_RT mkrt, MK_TYPN const typ)
 alloc instance-memory for MkTypeS
 
MK_TYP MkTypeResolve_RT (MK_RT mkrt, MK_TYPN const typ)
 resolve a new type
 
void MkTypeDelete_RT (MK_RT mkrt, MK_TYP const typ)
 delete a type object
 
static MK_OBJ MkTypeInstances (MK_TYP const typ)
 access the instance attribute of the type…
 
static MK_TYPN MkTypeNextN (MK_TYPN const typ)
 get next instance from linked-list of MkObjectS type
 

MkTypeC - MkTypeC_TOR_C_API - overload

#define MkTypeAlloc_NULL(...)
 
#define MkTypeAlloc(...)
 
#define MkTypeDup2_NULL(...)
 
#define MkTypeDup2(...)
 
#define MkTypeResolve_NULL(...)
 
#define MkTypeResolve(...)
 
#define MkTypeDelete_NULL(...)
 
#define MkTypeDelete(...)
 

Detailed Description

MkTypeS - various functions to create, initialize and destroy a type

Macro Definition Documentation

◆ MkTypeAlloc

#define MkTypeAlloc ( ...)
Value:
#define MK_RT_CALL
MK_OBJ MkTypeAlloc_RT(MK_RT mkrt, MK_TYPN const typ)
alloc instance-memory for MkTypeS …

Definition at line 1915 of file kernel_overload_mk.h.

◆ MkTypeAlloc_NULL

#define MkTypeAlloc_NULL ( ...)
Value:
#define MK_RT_CALL_NULL

Definition at line 1914 of file kernel_overload_mk.h.

◆ MkTypeCreate

#define MkTypeCreate ( clsV,
basicV,
identV )
Value:
({ \
assert(!MkSysStringIsNULL(identV)); \
MK_TYP ret = MkTypeDup2(basicV ## _TT,identV); \
ret->objsig = clsV ## _SIGNATURE; \
ret->objmask = clsV ## _MASK; \
ret->objsize = sizeof(clsV##R); \
ret->type_base = basicV ## _TT; \
ret->type_class = ret; \
ret ; \
})
static bool MkSysStringIsNULL(MK_STRN str)
test if string is NULL or EMPTY …
#define MkTypeDup2(...)
MkTypeS - class known as typ or type is used as class-base for a Managed-Object-Technology (MOT) type...
MK_TYP type_class
point to the instancesR linked list of the class-type
size_t objsize
the size of the new object created with this type, used in malloc
MK_SIG objsig
type-instance: signature as unsinged integer (32bit)
MK_SIG objmask
type-instance: mask to filter out the valid part of the signatur
MK_TYP type_base
base type

Definition at line 5042 of file LibMkKernel_mk.h.

5042#define MkTypeCreate(clsV, basicV, identV) ({ \
5043 assert(!MkSysStringIsNULL(identV)); \
5044 MK_TYP ret = MkTypeDup2(basicV ## _TT,identV); \
5045 ret->objsig = clsV ## _SIGNATURE; \
5046 ret->objmask = clsV ## _MASK; \
5047 ret->objsize = sizeof(clsV##R); \
5048 ret->type_base = basicV ## _TT; \
5049 ret->type_class = ret; \
5050 ret ; \
5051})

◆ MkTypeDelete

#define MkTypeDelete ( ...)
Value:
void MkTypeDelete_RT(MK_RT mkrt, MK_TYP const typ)
delete a type object

Definition at line 1923 of file kernel_overload_mk.h.

◆ MkTypeDelete_NULL

#define MkTypeDelete_NULL ( ...)
Value:

Definition at line 1922 of file kernel_overload_mk.h.

◆ MkTypeDup2

#define MkTypeDup2 ( ...)
Value:
MK_TYP MkTypeDup2_RT(MK_RT mkrt, MK_TYPN const typ, MK_STRN const ident)
duplicate typ to create a lightweight-type …

Definition at line 1917 of file kernel_overload_mk.h.

◆ MkTypeDup2_NULL

#define MkTypeDup2_NULL ( ...)
Value:

Definition at line 1916 of file kernel_overload_mk.h.

◆ MkTypeForeachInstancesSave

#define MkTypeForeachInstancesSave ( typ)
Value:
DL_FOREACH_SAFE2((typ)->type_class->instancesR,obj,tmp,obj_protect.next)

iterate over instances of a class with the intention of deleting the instance

Attention
require "utlist_mk.h" include

Definition at line 5131 of file LibMkKernel_mk.h.

◆ MkTypeResolve

#define MkTypeResolve ( ...)
Value:
MK_TYP MkTypeResolve_RT(MK_RT mkrt, MK_TYPN const typ)
resolve a new type

Definition at line 1919 of file kernel_overload_mk.h.

◆ MkTypeResolve_NULL

#define MkTypeResolve_NULL ( ...)
Value:

Definition at line 1918 of file kernel_overload_mk.h.

Function Documentation

◆ MkTypeAlloc_RT()

MK_OBJ MkTypeAlloc_RT ( MK_RT mkrt,
MK_TYPN const typ )

alloc instance-memory for MkTypeS

The following steps are done:

  1. resolve the type to fit into MkRuntimeC
  2. allocate the memory using the allocator from the type -> (MkTypeS::objalloc)
  3. initialize the memory to zero
  4. initialize the instance
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on (nonnull)

◆ MkTypeCreate()

MK_TYP MkTypeCreate ( MK_MACRO_TYP const clsV,
MK_MACRO_TYP const basicV,
MK_STRN const identV )

create a new type …

Ther are three scenarios in which a new type is created:

  1. when a new c-library is created and the new c-library creates a c-library-specific type.
    → this is called full-weight-type
  2. when a new type is created as an extension of an already existing type but without signature and mask.
    → this is called light-weight-type
  3. when a Target-Programming-Language (TPL) is linked to an existing meta-code-c-library.
    → this is called shadow-type

shadow-type

The shadow-type is used to link a Target-Programming-Language (TPL) with a meta-code-library (META-LIBRARY). The goal is not to create a new-type but to map an already-existing-type into the Target-Programming-Language (TPL).

The shadow-type has not its own memory and all changes to the shadow-type will change the already-existing-type.

lightweight-type

The light-weight-type is created from an already-existing-type and a specific-instance-struct but without an own MkTypeS::objsig and MkTypeS::objmask. This type reuse all features of the already-existing-type without replaceing the already-existing-type.
The light-weight-type has its own memory and all changes to the light-weight-type will not change the already-existing-type.

Example: the "acut" tool
struct CutCtxS {
struct MqContextS mqctx;
MK_I32 fields[256];
};
...
static MK_TYP CutTT = NULL;
#define CutT ( (typeof(MqContextC_T)) CutTT )
static enum MkErrorE
CutFactory ( MQ_CALLBACK_FACTORY_CTOR_ARGS )
{
MQ_CTX const mqctx = MqContextCreate(CutTT,tmpl);
MqConfigSetName(mqctx, "cut");
MqConfigSetIsServer(mqctx, true);
*contextP = mqctx;
return MK_OK;
}
void CutInit( MQ_RT_ARGS_ONLY ) {
CutTT = MkTypeDup2(MqContextC_TT,"CutC");
CutTT->objsize = sizeof(struct CutCtxS);
CutT->Parent.fCreate = CutCreate;
CutT->fHelp = CutHelp;
MqFactoryAdd (MK_ERROR_PANIC, CutFactory, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "cut");
}

fullweight-type

The full-weight-type is created using the MkTypeCreate with a type-class, class-base, type-name.

The type is created as MkTypeDup2 from the basic type followed by an update of the type specific fields objsig, objmask and objsize.

This kind of type is called a full-weight-type, because this type does provide a new signature and mask. In difference to MkTypeCreate the MkTypeDup2 create a lightweight-type.

The fullweight-type is defined by the tool c_Class.tcl and is able to operate independent from any other type.

Parameters
[in]clsVthe real type-name in "C" (usually the same as identV), the type-name who was registerd with the c_CLS.tcl tool. (syntax: NsClassC, Ns=namespace)
[in]basicVthe basic-type, have to be MkObjectC or a decend of this
[in]identVset the display-name (MkTypeS::type_name), have to be NON null
Attention
The newType MkTypeS::type_base is set to basicType and the MkObjectS::refCount of basicType is incremented.

example - create a NEW type

// the new type "LcConfigC" is thread-local
SQ3_EXTERN_DATA MkThreadLocal MK_TYP LcConfigC_TT;
// setup the NEW type with name "LcConfigC" using the base class "MkObjectC"
void LcConfig_Setup (MK_RT mkrt) {
LcConfigC_TT = MkTypeCreate(LcConfigC, MkObjectC, "LcConfigC");
...
}
// every NEW runtime call sLcRuntimeInitCallback and create the NEW type "LcConfigC"
static void sLcRuntimeInitCallback ( struct MkRuntimeS * mkrt ) {
// BEGIN-Class-Setup - created by 'c_Class.tcl -i NHI1_HOME/theConfig/c/.liblcconfig.meta' - DO NOT change
LcConfig_Setup (mkrt);
LcSetting_Setup (mkrt);
// END-Class-Setup - created by 'c_Class.tcl -i NHI1_HOME/theConfig/c/.liblcconfig.meta' - DO NOT change
...
}
// the library-constructor register the runtime-setup-callback: sLcRuntimeInitCallback
void LcSetup(void)
{
...
MkRuntimeCallbackAdd( &sLcRuntimeCallback, MK_RT_PTR, sLcRuntimeInitCallback, "LcConfig" );
...
}
// the library-constructor have to be called FIRST
LC_EXTERN void MK_DECL LcSetup (void) __attribute__ ((constructor(1000)));
#define MK_DECL
void MkSetup(void)
setup libmkkernel internal memory …
size_t MkRuntimeCallbackAdd(MK_RT mkrt, MkRuntimeCallbackS *cbdata, MkRuntimeInitF rt_callback, MK_STRN ident)
add a callback to the runtime …
#define MkThreadLocal
#define MK_RT_PTR
#define MkTypeCreate(clsV, basicV, identV)
The MkRuntimeS provide a per-thread environment for libmkkernel …

definition - of the macro

#define MkTypeCreate(clsV, basicV, identV) ({ \
assert(!MkSysStringIsNULL(identV)); \
MK_TYP ret = MkTypeDup2(basicV ## _TT,identV); \
ret->objsig = clsV ## _SIGNATURE; \
ret->objmask = clsV ## _MASK; \
ret->objsize = sizeof(clsV##R); \
ret->type_base = basicV ## _TT; \
ret->type_class = ret; \
ret ; \
})
See also
MkTypeDup2

◆ MkTypeDelete_RT()

void MkTypeDelete_RT ( MK_RT mkrt,
MK_TYP const typ )

delete a type object

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on - (nonnull)

◆ MkTypeDup2_RT()

MK_TYP MkTypeDup2_RT ( MK_RT mkrt,
MK_TYPN const typ,
MK_STRN const ident )

duplicate typ to create a lightweight-type

The lightweight-type has the following features:

The fullweight-type is created with MkTypeCreate.

  • slot : MkObjDup2 = call the Dup2-Constructor from the object
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on
[in]identset the display-name (MkTypeS::type_name)
Attention
PANIC on error

◆ MkTypeInstances()

static MK_OBJ MkTypeInstances ( MK_TYP const typ)
inlinestatic

access the instance attribute of the type…

Definition at line 5114 of file LibMkKernel_mk.h.

5116 {
5117 assert(typ != NULL);
5118 assert(typ->type_class != NULL);
5119 MK_OBJ ret = typ->type_class->instancesR;
5120 // BUG FIX 2 mar 2025
5121 // test: Nhi1Exec int.test --dev-testing --lang-cc --valgrind-server
5122 // analyse: after "Delete" the "prev/next" is NOT proper set if "type" from "Instances->Next"
5123 // and "type" from "ret->type->instances" are NOT in sync
5124 // Fix: pMkTypeDup2 take "sourceTyp->instances"
5125 if (ret) assert(ret->type->type_class == typ->type_class);
5126 return ret;
5127}
object header …
MK_TYP type
link to the object type
+ Here is the caller graph for this function:

◆ MkTypeNextN()

static MK_TYPN MkTypeNextN ( MK_TYPN const typ)
inlinestatic

get next instance from linked-list of MkObjectS type

Definition at line 5135 of file LibMkKernel_mk.h.

5135 {
5136 MK_INSTANCE_HDL(typ);
5137 return (MK_TYP)MkTypeC_X2obj(typ)->obj_protect.next;
5138}
#define MK_INSTANCE_HDL(x)
#define MkTypeC_X2obj(x)

◆ MkTypeResolve_RT()

MK_TYP MkTypeResolve_RT ( MK_RT mkrt,
MK_TYPN const typ )

resolve a new type

Every NEW runtime require a new Type, This code is called in a callback registered with MkRuntimeCallbackAdd TODO: htmlcode{mqsetting,resolve_example,create a new type and resolve}

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on - (nonnull)