theKernel 10.0
Loading...
Searching...
No Matches
MkExceptionC_PY_API

MkExceptionC - The default-exception of the Programming-Language-Micro-Kernel (PLMK)More...

+ Collaboration diagram for MkExceptionC_PY_API:

Functions

void pymkkernel_MkExceptionC_Raise (OT_Prefix_ARGS MK_MNGN const expobj, MK_STRN const doc, MK_STRN const callfunc, MK_I32 callline)
 C-API: MkExceptionRaise - convert an MkErrorC into a Target-Programming-Language (TPL) exception …
 
MK_ERR pymkkernel_MkExceptionC_Catch (OT_Prefix_ARGS MK_MNG const expobj, MK_EXP const exception, MK_STRN const callfunc)
 C-API: MkExceptionCatch - convert an Target-Programming-Language (TPL) exception into an MkErrorC
 

Detailed Description

MkExceptionC - The default-exception of the Programming-Language-Micro-Kernel (PLMK)

The Programming-Language-Micro-Kernel (PLMK) provide with MkErrorC a complete error-handling with focus to support the "C" Programming-Language. The support include catch, raise, signal and attributes. In addition every Target-Programming-Language (TPL) add their own error-handling and the purpose of MkExceptionC is to integrate the MkErrorC into the Target-Programming-Language (TPL).

The default-exception MkExceptionC is used to connect the MkErrorC with the Target-Programming-Language (TPL) error-object.

The implementation of an exception depends heavily on the Target-Programming-Language (TPL), starting with no exception at all, for example. C, an exception as a class object, or as an exception as a global attribute.

Attention

Function Documentation

◆ pymkkernel_MkExceptionC_Catch()

MK_ERR pymkkernel_MkExceptionC_Catch ( OT_Prefix_ARGS MK_MNG const expobj,
MK_EXP const exception,
MK_STRN const callfunc )

C-API: MkExceptionCatch - convert an Target-Programming-Language (TPL) exception into an MkErrorC

Parameters
[in]expobjThe LibMsgqueObject used to personalize the exception/error (will be validated first)
[in]exceptionthe exception object from Python, if None the global exception object is used
[in]callfunca user-defined postfix to identify the calling-function or the environment (default = name-of-function, None = resolve-own-name)
Returns
the MkErrorC created with data from exception

Definition at line 48 of file MkExceptionC_py.c.

53 {
54 //MQ_CTX context = MqCtx(fmtObj);
55
56 PyObject *expO = (PyObject*) exception;
57
58 MK_ERR err = MkErrorFORMAT_1M(expobj);
59 PyObject *typeO = NULL, *valueO=NULL;
60
61 if (expO == Py_None || expO == NULL) {
62 valueO = PyErr_GetRaisedException();
63 if (valueO == NULL) {
64 MkErrorSetC (err, "No active exception to reraise", callfunc, -1);
65 return err;
66 }
67 typeO = Py_NewRef(Py_TYPE(valueO));
68 } else {
69 typeO = Py_NewRef(Py_TYPE(expO));
70 valueO = Py_NewRef(expO);
71 }
72
73//printLngObj(typeO)
74//printLngObj(valueO)
75 {
76 // step 1. - is it an error?
77 if (typeO == Py_None || typeO == NULL) {
78 MkErrorSetC (err, "No active exception to reraise", callfunc, -1);
79
80 // step 2. - is it an MQ error?
81 } else if (PyErr_GivenExceptionMatches(typeO,NS(MkKernelThreadState).MkExceptionC)) {
82 MK_ERR newerr = NULL;
83 while (true) {
84 if (PyObject_TypeCheck(valueO,&NS(MkErrorCR))) {
85 newerr = MkErr(((MkErrorC_Obj*)expO)->hdl);
86 } else if (PyObject_TypeCheck(valueO,(PyTypeObject*)PyExc_BaseException)) {
87 PyObject *tupO = ((PyBaseExceptionObject*)valueO)->args;
88 if (tupO == NULL || !PyTuple_Check(tupO)) break;
89 PyObject *expO = PyTuple_GetItem(tupO, 0);
90 if (expO == NULL) break;
91 if (PyObject_TypeCheck(expO,&NS(MkErrorCR))) {
92 newerr = MkErr(((MkErrorC_Obj*)expO)->hdl);
93 }
94 }
95 break;
96 }
97 if (newerr) {
98 MkErrorSetE (err, newerr);
99 } else {
100 MkErrorSetC (err, "No active exception value object to reraise", callfunc, -1);
101 }
102
103 // step 3. - is it an PYTHON error?
104 } else if (valueO) {
105 OT_OBJ_T errO = OT_TMP_ERR_OBJ(err);
106 OT_OBJ_T tstO = PyObject_CallFunction(NS(MkErrorC_FormatException), "OOs", errO, valueO, callfunc);
107 if (tstO == NULL) {
108 if (PyErr_Occurred()) PyErr_Print();
109 } else {
110 Py_CLEAR(tstO);
111 }
113 MkErrorSetV(err, callfunc, -1, "%s: python error", PyExceptionClass_Name(typeO));
114 }
115 }
116
117 Py_CLEAR(typeO);
118 Py_CLEAR(valueO);
119 if (PyErr_Occurred()) PyErr_Clear();
120 return err;
121}
#define NS(n)
#define OT_TMP_ERR_OBJ(val)
PyObject * OT_OBJ_T
static MK_ERR MkErr(MK_MNG mng)
cast a unknown-object into an MkErrorS pointer or NULL if not possible
#define MkErrorGetCode_0E()
#define MkErrorSetC(...)
#define MkErrorSetV(...)
#define MkErrorSetE(...)
#define MkErrorFORMAT_1M(m)
@ MK_ERROR
(persistent) raise an error-event, the calling-fucntion is interrupted.
The data-type to store and handle the error-condition …

◆ pymkkernel_MkExceptionC_Raise()

void pymkkernel_MkExceptionC_Raise ( OT_Prefix_ARGS MK_MNGN const expobj,
MK_STRN const doc,
MK_STRN const callfunc,
MK_I32 callline )

C-API: MkExceptionRaise - convert an MkErrorC into a Target-Programming-Language (TPL) exception …

Parameters
[in]expobjThe LibMsgqueObject used to personalize the exception/error (will be validated first)
[in]callfunca user-defined postfix to identify the calling-function or the environment (default = name-of-function, None = resolve-own-name)
[in]calllinethe number of the line the call take place (e.g. LINE)
[in]docdocumentation string

Definition at line 23 of file MkExceptionC_py.c.

30{
31 PyErr_Clear();
32 MK_ERR err = MkErrorFORMAT_1M(expobj);
33 MkErrorStackFormat(err,doc,callfunc,callline);
34 PyObject *stackO = NULL; // buffer hold all the current stack frame
35 for (int lvl = 0; MK(Get_Call_Stack)(MK_RT_CALL err, lvl, &stackO); lvl++) {
36 //printI(lvl);
37 }
38 Py_CLEAR(stackO);
39 MK_ERR newerr = MkErrCheck(expobj) && expobj != err ? (MK_ERR)expobj : MkErrorDup(err);
40 PyObject* errO = OT_TMP_ERR_OBJ(newerr);
41 PyErr_SetObject(NS(MkKernelThreadState).MkExceptionC, errO);
42 Py_CLEAR(errO);
43 // TODO difference between python and tcl MkErrorReset_1M(expobj) versa MkErrorReset_1(err)
44 if (expobj) MkErrorReset_1M(expobj);
45}
#define MK(n)
struct MkErrorS * MK_ERR
class-shortcut for struct MkErrorS *, all shortcut using the XX_YYY syntax (only for public API) …
static bool MkErrCheck(MK_MNGN mng)
check MkErrorS -> MkObjectS::signature …
#define MkErrorStackFormat(...)
#define MkErrorReset_1M(err)
#define MkErrorDup(...)
#define MK_RT_CALL