theKernel 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - cs - py - rb - jv - cc
Loading...
Searching...
No Matches
MkObjectC_TOR_C_API

MkObjectC - create and destroy a managed-objectMore...

+ Collaboration diagram for MkObjectC_TOR_C_API:

Macros

#define MkObjInit2(rtmkV, rtExtV, sigV, typeV, refCountV, isLocalV)
 Initialize an MkObjectS.
 
#define MkObjInit(rtmkV, rtExtV, cls, refCountV, isLocalV)
 
#define MkObjInitFromType(typeV, isLocalV)
 
#define MkObjInitFromInstance(instV)
 
#define MkObjectDelete_NULL(obj)
 
#define MkObjectDelete_NULL_X(x)
 
#define MkObjectDelete_1X(x)
 
#define MkObjectDeleteToNull(fct, NS, x)
 
#define MkObjectDeleteToNull_X(fct, NS, x)
 
#define MkObjectDispose_NULL(obj)
 
#define MkObjectDispose_NULL_X(x)
 
#define MkObjectDispose_1X(x)
 
#define MkObjectDeleteCallF_CHECK
 validate call to MkObjectDeleteCallF
 
#define MkObjectDeleteCallF_ARGS
 the MkObjectDeleteCallF arguments with default names
 
#define MkObjectDeleteCallF_CALL   MK_RT_CALL obj, __data__
 
#define MkObjectDeleteFreeF_ARGS   MK_RT_ARGS MK_CBP *dataP __parser__(inout)
 the MkObjectDeleteFreeF arguments with default names
 

Typedefs

typedef enum MkErrorE(* MkObjectDeleteCallF) (MK_RT mkrt, MK_OBJN const obj, MK_STRN const typeName, MK_HDL const typeHdl, MK_HDL const objHdl, MK_CBP const __data__)
 static callback to delete an obj
 
typedef void(* MkObjectDeleteFreeF) (MkObjectDeleteFreeF_ARGS)
 

Functions

MK_OBJ MkObjDup_RT (MK_RT mkrt, MK_OBJ const srcobj)
 call the Dup-Constructor from the object
 
MK_OBJ MkObjDup2_RT (MK_RT mkrt, MK_OBJ const srcmng, MK_STRN const ident)
 call the Dup2-Constructor from the object
 
MK_OBJ MkObjMerge_RT (MK_RT mkrt, MK_OBJ const obj)
 Constructor - create a new object as a merge from an existing object
 
MK_OBJ MkObjCreate_RT (MK_RT mkrt, MK_TYP type, MK_PTR nat, MK_PTR lnk)
 call the Constructor from the object
 
void MkObjectDelete_RT (MK_RT mkrt, MK_OBJ obj)
 Delete-Slot - delete an instance.
 
void MkObjectDispose_RT (MK_RT mkrt, MK_OBJ obj)
 Dispose-Slot - untie the connection between the Native-C-Instance and the libmkkernel-Instance.
 
enum MkErrorE MkObjectDeleteCallbackSetup_RT (MK_RT mkrt, MK_STRN ident, MkObjectDeleteCallF fCall, MK_CBP callback, MkObjectDeleteFreeF fFree, MK_STRN filter)
 Create/Delete the instance-delete-callback
 
void MkObjectDeleteCallbackCleanup_RT (MK_RT mkrt, MK_STRN ident)
 cleanup the DeleteCallback installed with MkObjectDeleteCallbackSetup
 

MkObjectC - MkObjectC_TOR_C_API - overload

#define MkObjDup_NULL(...)
 
#define MkObjDup(...)
 
#define MkObjMerge_NULL(...)
 
#define MkObjMerge(...)
 
#define MkObjCreate_NULL(...)
 
#define MkObjCreate(...)
 
#define MkObjCreate_2(nat, lnk)
 
#define MkObjectDispose(x)
 
#define MkObjectDelete(x)
 
#define MkObjDup2_NULL(...)
 
#define MkObjDup2(...)
 
#define MkObjectDeleteCallbackCleanup_NULL(...)
 
#define MkObjectDeleteCallbackCleanup(...)
 
#define MkObjectDeleteCallbackSetup_NULL(...)
 
#define MkObjectDeleteCallbackSetup(...)
 
#define MkObjectDeleteCallbackSetup_E(...)
 
#define MkObjectDeleteCallbackSetup_C(...)
 

Detailed Description

MkObjectC - create and destroy a managed-object

Macro Definition Documentation

◆ MkObjCreate

#define MkObjCreate ( ...)
Value:
MK_OBJ MkObjCreate_RT(MK_RT mkrt, MK_TYP type, MK_PTR nat, MK_PTR lnk)
call the Constructor from the object
#define MK_RT_CALL

Definition at line 1760 of file kernel_overload_mk.h.

◆ MkObjCreate_2

#define MkObjCreate_2 ( nat,
lnk )
Value:
MkObjCreate(NULL,nat,lnk)
#define MkObjCreate(...)

Definition at line 1761 of file kernel_overload_mk.h.

◆ MkObjCreate_NULL

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

Definition at line 1759 of file kernel_overload_mk.h.

◆ MkObjDup

#define MkObjDup ( ...)
Value:
MkObjDup_RT(MK_RT_CALL __VA_ARGS__)
MK_OBJ MkObjDup_RT(MK_RT mkrt, MK_OBJ const srcobj)
call the Dup-Constructor from the object

Definition at line 1754 of file kernel_overload_mk.h.

◆ MkObjDup2

#define MkObjDup2 ( ...)
Value:
MK_OBJ MkObjDup2_RT(MK_RT mkrt, MK_OBJ const srcmng, MK_STRN const ident)
call the Dup2-Constructor from the object

Definition at line 1771 of file kernel_overload_mk.h.

◆ MkObjDup2_NULL

#define MkObjDup2_NULL ( ...)
Value:

Definition at line 1770 of file kernel_overload_mk.h.

◆ MkObjDup_NULL

#define MkObjDup_NULL ( ...)
Value:

Definition at line 1753 of file kernel_overload_mk.h.

◆ MkObjectDelete

#define MkObjectDelete ( x)
Value:
#define MkObjectDeleteToNull(fct, NS, x)
void MkObjectDelete_RT(MK_RT mkrt, MK_OBJ obj)
Delete-Slot - delete an instance.

Definition at line 1767 of file kernel_overload_mk.h.

◆ MkObjectDelete_1X

#define MkObjectDelete_1X ( x)
Value:
#define MkObjectDeleteToNull_X(fct, NS, x)

Definition at line 4186 of file LibMkKernel_mk.h.

◆ MkObjectDelete_NULL

#define MkObjectDelete_NULL ( obj)
Value:

Definition at line 4184 of file LibMkKernel_mk.h.

◆ MkObjectDelete_NULL_X

#define MkObjectDelete_NULL_X ( x)
Value:

Definition at line 4185 of file LibMkKernel_mk.h.

◆ MkObjectDeleteCallbackCleanup

#define MkObjectDeleteCallbackCleanup ( ...)
Value:
void MkObjectDeleteCallbackCleanup_RT(MK_RT mkrt, MK_STRN ident)
cleanup the DeleteCallback installed with MkObjectDeleteCallbackSetup …

Definition at line 1775 of file kernel_overload_mk.h.

◆ MkObjectDeleteCallbackCleanup_NULL

#define MkObjectDeleteCallbackCleanup_NULL ( ...)
Value:

Definition at line 1774 of file kernel_overload_mk.h.

◆ MkObjectDeleteCallbackSetup

#define MkObjectDeleteCallbackSetup ( ...)
Value:
enum MkErrorE MkObjectDeleteCallbackSetup_RT(MK_RT mkrt, MK_STRN ident, MkObjectDeleteCallF fCall, MK_CBP callback, MkObjectDeleteFreeF fFree, MK_STRN filter)
Create/Delete the instance-delete-callback …

Definition at line 1777 of file kernel_overload_mk.h.

◆ MkObjectDeleteCallbackSetup_C

#define MkObjectDeleteCallbackSetup_C ( ...)
Value:
#define MkErrorCheckI(err)
#define MkObjectDeleteCallbackSetup(...)

Definition at line 1779 of file kernel_overload_mk.h.

◆ MkObjectDeleteCallbackSetup_E

#define MkObjectDeleteCallbackSetup_E ( ...)
Value:
#define MkErrorCheck(err)
check return-code and goto error on error …

Definition at line 1778 of file kernel_overload_mk.h.

◆ MkObjectDeleteCallbackSetup_NULL

#define MkObjectDeleteCallbackSetup_NULL ( ...)
Value:

Definition at line 1776 of file kernel_overload_mk.h.

◆ MkObjectDeleteCallF_ARGS

#define MkObjectDeleteCallF_ARGS
Value:
MK_RT_ARGS \
MK_OBJN const obj __parser__(internal), \
MK_STRN const typeName, \
MK_HDL const typeHdl, \
MK_HDL const objHdl, \
MK_CBP const __data__ \
#define __parser__(...)
parser: apply an attribute to an object in local scope …
const MK_STRB * MK_STRN
constant string pointer data-type
MK_PTRB * MK_CBP
generic pointer to call-back data
int32_t MK_HDL
4 byte int handle data-type

the MkObjectDeleteCallF arguments with default names

Definition at line 4223 of file LibMkKernel_mk.h.

4223#define MkObjectDeleteCallF_ARGS \
4224 MK_RT_ARGS \
4225 MK_OBJN const obj __parser__(internal), \
4226 MK_STRN const typeName, \
4227 MK_HDL const typeHdl, \
4228 MK_HDL const objHdl, \
4229 MK_CBP const __data__ \
4230

◆ MkObjectDeleteCallF_CALL

#define MkObjectDeleteCallF_CALL   MK_RT_CALL obj, __data__

Definition at line 4231 of file LibMkKernel_mk.h.

◆ MkObjectDeleteCallF_CHECK

#define MkObjectDeleteCallF_CHECK
Value:
do { \
assert (__data__ != NULL); \
} while (0)

validate call to MkObjectDeleteCallF

Definition at line 4217 of file LibMkKernel_mk.h.

4217#define MkObjectDeleteCallF_CHECK do { \
4218 assert (__data__ != NULL); \
4219} while (0)

◆ MkObjectDeleteFreeF_ARGS

#define MkObjectDeleteFreeF_ARGS   MK_RT_ARGS MK_CBP *dataP __parser__(inout)

the MkObjectDeleteFreeF arguments with default names

Definition at line 4281 of file LibMkKernel_mk.h.

◆ MkObjectDeleteToNull

#define MkObjectDeleteToNull ( fct,
NS,
x )
Value:
if (x) { fct (NS##_RT_CALL x); (x) = NULL ; }

Definition at line 4188 of file LibMkKernel_mk.h.

◆ MkObjectDeleteToNull_X

#define MkObjectDeleteToNull_X ( fct,
NS,
x )
Value:
if (x) { fct (NS##_RT_CALL MkOBJ(x)); (x) = NULL ; }
#define MkOBJ(x)
cast a known-object into an MkObjectS pointer

Definition at line 4189 of file LibMkKernel_mk.h.

◆ MkObjectDispose

#define MkObjectDispose ( x)
Value:
void MkObjectDispose_RT(MK_RT mkrt, MK_OBJ obj)
Dispose-Slot - untie the connection between the Native-C-Instance and the libmkkernel-Instance.

Definition at line 1764 of file kernel_overload_mk.h.

◆ MkObjectDispose_1X

#define MkObjectDispose_1X ( x)
Value:
#define MkObjectDispose(x)

Definition at line 4214 of file LibMkKernel_mk.h.

◆ MkObjectDispose_NULL

#define MkObjectDispose_NULL ( obj)
Value:

Definition at line 4212 of file LibMkKernel_mk.h.

◆ MkObjectDispose_NULL_X

#define MkObjectDispose_NULL_X ( x)
Value:

Definition at line 4213 of file LibMkKernel_mk.h.

◆ MkObjInit

#define MkObjInit ( rtmkV,
rtExtV,
cls,
refCountV,
isLocalV )
Value:
MkObjInit2(rtmkV,rtExtV,cls##_SIGNATURE,cls##_TT,refCountV,isLocalV)
#define MkObjInit2(rtmkV, rtExtV, sigV, typeV, refCountV, isLocalV)
Initialize an MkObjectS.

Definition at line 4076 of file LibMkKernel_mk.h.

4076#define MkObjInit(rtmkV,rtExtV,cls,refCountV,isLocalV) \
4077 MkObjInit2(rtmkV,rtExtV,cls##_SIGNATURE,cls##_TT,refCountV,isLocalV)

◆ MkObjInit2

#define MkObjInit2 ( rtmkV,
rtExtV,
sigV,
typeV,
refCountV,
isLocalV )
Value:
(struct MkObjectS) { \
.signature = sigV, \
.refCount = refCountV, \
.self = NULL, \
.type = typeV, \
.env = NULL, \
.selfCreated = false, \
.selfRefCount = 0, \
.objRt = rtmkV, \
.objRtExt = rtExtV, \
.obj_protect = { \
.isLocal = isLocalV, \
.prev = NULL, \
.next = NULL, \
}, \
}
object header …

Initialize an MkObjectS.

This is internal code used in the CTOR toinitialize the memory after the new object was created.

#define MkDumpObjInit MkObjInit(MkDump, 0, false)
...
Attention
with .obj_protect.isLocal=true the MkSelfDeleteForce_RT will NOT delete the memory

Definition at line 4039 of file LibMkKernel_mk.h.

4039 #define MkObjInit2(rtmkV,rtExtV,sigV,typeV,refCountV,isLocalV) \
4040 (struct MkObjectS) { \
4041 .signature = sigV, \
4042 .refCount = refCountV, \
4043 .self = NULL, \
4044 .type = typeV, \
4045 .env = NULL, \
4046 .selfCreated = false, \
4047 .selfRefCount = 0, \
4048 .objRt = rtmkV, \
4049 .objRtExt = rtExtV, \
4050 .obj_protect = { \
4051 .isLocal = isLocalV, \
4052 .prev = NULL, \
4053 .next = NULL, \
4054 }, \
4055 }

◆ MkObjInitFromInstance

#define MkObjInitFromInstance ( instV)
Value:
MkObjInit2(MK_RT_PTR, NULL, MkOBJ_R(instV).type->objsig, MkOBJ_R(instV).type, 0, false)
#define MkOBJ_R(x)
cast a known-object into an MkObjectS reference
#define MK_RT_PTR

Definition at line 4084 of file LibMkKernel_mk.h.

4084#define MkObjInitFromInstance(instV) \
4085 MkObjInit2(MK_RT_PTR, NULL, MkOBJ_R(instV).type->objsig, MkOBJ_R(instV).type, 0, false)

◆ MkObjInitFromType

#define MkObjInitFromType ( typeV,
isLocalV )
Value:
MkObjInit2(MK_RT_PTR, NULL, (*typeV).objsig, typeV, 0, isLocalV)

Definition at line 4080 of file LibMkKernel_mk.h.

4080#define MkObjInitFromType(typeV,isLocalV) \
4081 MkObjInit2(MK_RT_PTR, NULL, (*typeV).objsig, typeV, 0, isLocalV)

◆ MkObjMerge

#define MkObjMerge ( ...)
Value:
MK_OBJ MkObjMerge_RT(MK_RT mkrt, MK_OBJ const obj)
Constructor - create a new object as a merge from an existing object

Definition at line 1756 of file kernel_overload_mk.h.

◆ MkObjMerge_NULL

#define MkObjMerge_NULL ( ...)
Value:

Definition at line 1755 of file kernel_overload_mk.h.

Typedef Documentation

◆ MkObjectDeleteCallF

typedef enum MkErrorE( * MkObjectDeleteCallF) (MK_RT mkrt,MK_OBJN const obj, MK_STRN const typeName, MK_HDL const typeHdl, MK_HDL const objHdl, MK_CBP const __data__)

static callback to delete an obj

This callback is called when the obj is deleted. Setting up the callback is done using the MkObjectDeleteCallbackSetup function.

Introduction

Deleting an obj is not easy because there are generally two parts, the Target-Programming-Language (TPL) part and the Programming-Language-Micro-Kernel (PLMK) part.

Generally, two callbacks are involved:

  • The C-callback runs under the control of the PLMK
  • The TPL-callback runs under the control of the TPL. (non C language)
Definition
The obj is defined by the three callback arguments typeName, typeHdl and objHdl.
  • The objHdl is important because this is the export handle used as a reference to the internal object.
  • In Remote-Procedure-Call (RPC), this export handle is used to link the client object to the server object, and when the server object is deleted, the client object must also be deleted.
Workflow
This callback is called in MkRefDecrWithoutSelf and MkRefDecrWithUnlinkSelf, immediately before the PLMK-part is deleted and generally (not always) after the TPL-part is deleted.
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe theKernel part of the object, only use internal in the C-callback
[in]typeNamethe return from MkObjectToNameOfType
[in]typeHdlthe return from MkObjectHandleGetOfType
[in]objHdlthe return from MkObjectHandleGet
Returns
The MkErrorE status from the DEFAULT MkErrorC in MkRuntimeS::error_mk
Attention

It is a design flaw to use obj in the TPL-callback because using obj or using the MkObjectHandleResolve function on objHdl will recreate the already deleted TPL-object and this generally breaks the TPL-runtime.

Just think of a Garbage-Collection (GC) deleting an object and that object is reborn in the GC deletion process.

Note
In the Target-Programming-Language (TPL) the TPL-callback is only called if the obj has a MkObjectS::self pointer.

Definition at line 4207 of file LibMkKernel_mk.h.

◆ MkObjectDeleteFreeF

typedef void( * MkObjectDeleteFreeF) (MkObjectDeleteFreeF_ARGS)

Definition at line 4284 of file LibMkKernel_mk.h.

Function Documentation

◆ MkObjCreate_RT()

MK_OBJ MkObjCreate_RT ( MK_RT mkrt,
MK_TYP type,
MK_PTR nat,
MK_PTR lnk )

call the Constructor from the object

Create a new object using type and an additional nat. This requie a MkTypeS::constructor be available

Attention
the type have to be resolved fist, already done in MkObjCreate->MkTypeResolve

◆ MkObjDup2_RT()

MK_OBJ MkObjDup2_RT ( MK_RT mkrt,
MK_OBJ const srcmng,
MK_STRN const ident )

call the Dup2-Constructor from the object

The Dup2-Constructor create a new object-shell, and copy all the internal data from the srcobj to the newobj. An additional ident is used to set e name ressource After the Dup2-Constructor the srcobj is unchanged.

Returns
the new object or MK_NULL if no Dup2-Constructor fails
See also
MkObjMerge MkObjReset MkTypeDup2

◆ MkObjDup_RT()

MK_OBJ MkObjDup_RT ( MK_RT mkrt,
MK_OBJ const srcobj )

call the Dup-Constructor from the object

This is an Instance-Callback the real Dup function called depend on the MkObjectS::type.

The Dup-Constructor create a new object-shell, and copy all the internal data from the srcobj to the newobj. After the Dup-Constructor the srcobj is unchanged.

The new instance belongs to the caller and may have to be released if necessary. A manual release using ObjectDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkObjectC instance, the instance is owned by the caller
See also
MkObjMerge_RT MkObjReset_RT

◆ MkObjectDelete_RT()

void MkObjectDelete_RT ( MK_RT mkrt,
MK_OBJ obj )

Delete-Slot - delete an instance.

There are two different ways to delete an instance:

ObjectDisposeto free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
  1. The internal memory will be freed and the object-pointer will be set to NULL. If the object-pointer is already NULL nothing will be done.
  2. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
  3. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
  4. After a SOFT-delete, the outher shell is still alive, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.
  5. On HARD-delete read more at MkSelfDeleteForce

◆ MkObjectDeleteCallbackCleanup_RT()

void MkObjectDeleteCallbackCleanup_RT ( MK_RT mkrt,
MK_STRN ident )

cleanup the DeleteCallback installed with MkObjectDeleteCallbackSetup

See also
MkObjectDeleteCallbackSetup

◆ MkObjectDeleteCallbackSetup_RT()

enum MkErrorE MkObjectDeleteCallbackSetup_RT ( MK_RT mkrt,
MK_STRN ident,
MkObjectDeleteCallF fCall,
MK_CBP callback,
MkObjectDeleteFreeF fFree,
MK_STRN filter )

Create/Delete the instance-delete-callback

The callback is called shortly before deleting an instance and is used to synchronize object management across the network.

The ident identifies the callback

  • before a new callback is created the existing-callback with name ident is deleted.
  • The ident is also required to delete the callback.
  • If the special ident ALL is used than all callbacks are deleted first.

The fCall (C-Only) or callback (Non-C) it is the callback called

  • If MK_NULL than the callback with name ident is deleted if exists and no new callback is created.
  • If MK_NULL then it is identical to MkObjectDeleteCallbackCleanup(ident).

The filter is a POSIX Extended Regular Expression to filter on type-names.

  • The filter is optional and is only used if not MK_NULL and not "":
  • The filter is applied to MkTypeS::type_name like MkBufferC.
  • The POSIX Extended Regular Expression syntax is defined in man 7 regex.
  • If the filter is not used, the fCall is called on every instance deletion !
C-callback definition details:
Read more at MkObjectDeleteCallF
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]identIdentify the callback, have to ne non MK_NULL and not "".
[in]fCall(C-Only) Internal required: the callback, if MK_NULL than the callback is deleted.
[in]callbackOptional: the parameter for fcall, for cleanup use fFree.
[in]fFree(C-Only) Internal optional: cleanup callback data
[in]filterOptional: is an regular expression to filter for MkTypeS::type_name.
See also
MkObjectDeleteCallbackCleanup
MkObjectDeleteCallbackSetup : callback signature
Read more at: Callback signature
MkObjectDeleteCallbackSetup : callback example
Read more at: Callback example

◆ MkObjectDispose_RT()

void MkObjectDispose_RT ( MK_RT mkrt,
MK_OBJ obj )

Dispose-Slot - untie the connection between the Native-C-Instance and the libmkkernel-Instance.

There are two different ways to delete an instance:

ObjectDispose to free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
1. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
2. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
3. After a SOFT-delete, the outher shell is still active, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.

◆ MkObjMerge_RT()

MK_OBJ MkObjMerge_RT ( MK_RT mkrt,
MK_OBJ const obj )

Constructor - create a new object as a merge from an existing object

The Merge-Constructor create a new object-shell, and take-over all the internal data from the source-object. After the Merge-Constructor the source-object is empty as if a object-reset was called.

One usage of the Merge-Constructor is to get a lightweight-copy of a Thread-Local-Storage object for external usage.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objThe source-object of the merge.
Returns
The new object or MK_NULL if no Merge-Constructor is available
Attention
The new object have to be deleted.
See also
MkObjDup_RT MkObjReset_RT MkObjectDelete