theKernel 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - cs - py - rb - jv - cc
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)
Returns
the MkErrorC created with data from exception

Definition at line 51 of file MkExceptionC_py.c.

56 {
57 //MQ_CTX context = MqCtx(fmtObj);
58
59 PyObject *expO = (PyObject*) exception;
60
61 MK_ERR err = MkErrorFORMAT_1M(expobj);
62 PyObject *typeO = NULL, *valueO=NULL;
63
64 if (expO == Py_None || expO == NULL) {
65 valueO = PyErr_GetRaisedException();
66 if (valueO == NULL) {
67 MkErrorSetC(err,"unspecified error",callfunc,1);
68 return err;
69 }
70 typeO = Py_NewRef(Py_TYPE(valueO));
71 } else {
72 typeO = Py_NewRef(Py_TYPE(expO));
73 valueO = Py_NewRef(expO);
74 }
75
76//printLngObj(typeO)
77//printLngObj(valueO)
78 {
79 // step 1. - is it an error?
80 if (typeO == Py_None || typeO == NULL) {
81 MkErrorSetC (err, "No active exception to reraise", callfunc, -1);
82
83 // step 2. - is it an MQ error?
84 } else if (PyErr_GivenExceptionMatches(typeO,NS(MkKernelThreadState).MkExceptionC)) {
85 MK_ERR newerr = NULL;
86 while (true) {
87 if (PyObject_TypeCheck(valueO,&NS(MkErrorCR))) {
88 newerr = MkErr(((MkErrorC_Obj*)expO)->hdl);
89 } else if (PyObject_TypeCheck(valueO,(PyTypeObject*)PyExc_BaseException)) {
90 PyObject *tupO = ((PyBaseExceptionObject*)valueO)->args;
91 if (tupO == NULL || !PyTuple_Check(tupO)) break;
92 PyObject *expO = PyTuple_GetItem(tupO, 0);
93 if (expO == NULL) break;
94 if (PyObject_TypeCheck(expO,&NS(MkErrorCR))) {
95 newerr = MkErr(((MkErrorC_Obj*)expO)->hdl);
96 }
97 }
98 break;
99 }
100 if (newerr) {
101 MkErrorSetE (err, newerr);
102 } else {
103 MkErrorSetC (err, "No active exception value object to reraise", callfunc, -1);
104 }
105
106 // step 3. - is it an PYTHON error?
107 } else if (valueO) {
108 OT_LNG_T errO = OT_TMP_ERR_OBJ(err);
109 OT_LNG_T tstO = PyObject_CallFunction(NS(MkErrorC_FormatException), "OOs", errO, valueO, callfunc);
110 if (tstO == NULL) {
111 if (PyErr_Occurred()) PyErr_Print();
112 } else {
113 Py_CLEAR(tstO);
114 }
116 MkErrorSetV(err, callfunc, -1, "%s: python error", PyExceptionClass_Name(typeO));
117 }
118 }
119
120 Py_CLEAR(typeO);
121 Py_CLEAR(valueO);
122 if (PyErr_Occurred()) PyErr_Clear();
123 return err;
124}
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)
[in]calllinethe number of the line the call take place (e.g. LINE)
[in]docdocumentation string

Definition at line 26 of file MkExceptionC_py.c.

33{
34 PyErr_Clear();
35 MK_ERR err = MkErrorFORMAT_1M(expobj);
36 MkErrorStackFormat(err,doc,callfunc,callline);
37 PyObject *stackO = NULL; // buffer hold all the current stack frame
38 for (int lvl = 0; MK(Get_Call_Stack)(MK_RT_CALL err, lvl, &stackO); lvl++) {
39 //printI(lvl);
40 }
41 Py_CLEAR(stackO);
42 MK_ERR newerr = MkErrCheck(expobj) && expobj != err ? (MK_ERR)expobj : MkErrorDup(err);
43 PyObject* errO = OT_TMP_ERR_OBJ(newerr);
44 PyErr_SetObject(NS(MkKernelThreadState).MkExceptionC, errO);
45 Py_CLEAR(errO);
46 // TODO difference between python and tcl MkErrorReset_1M(expobj) versa MkErrorReset_1(err)
47 if (expobj) MkErrorReset_1M(expobj);
48}
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