theSq3Lite 10.0
Loading...
Searching...
No Matches
LibMkKernel_rb.h
Go to the documentation of this file.
1
9#pragma once
10
11#include "ruby.h"
12
13#include "nhi1_config.h"
14#include "debug_mk.h"
15
16#include "LibMkKernel_mk.h"
17
18#include "tmpl/mk_type_S_lng.h"
19
20/*****************************************************************************/
21/* */
22/* Macro_API */
23/* */
24/*****************************************************************************/
25
26// BEGIN-HEADER - created by 'rb_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
27
28#undef HEADER
29#define HEADER
30
31// If the source of libmkkernel is direct used in an external library
32// (without dynamic linking) and this library should *not* export
33// the symbol's of libmkkernel then the flag META_IGNORE_EXTERN have
34// to be set
35#undef MK_RB_EXTERN
36#if defined(META_IGNORE_EXTERN)
37# define MK_RB_EXTERN
38#elif defined(PIC)
39 // does we build a DLL ?
40# if defined(DLL_EXPORT)
41 // does we build the libmkkernel library ?
42# if defined(MK_RB_BUILD_DLL)
43# define MK_RB_EXTERN __declspec(dllexport)
44# else
45# define MK_RB_EXTERN __declspec(dllimport)
46# endif
47# else
48 // no DLL - architecture specific extern specifier
49# define MK_RB_EXTERN __attribute__ ((visibility("default")))
50# endif
51#else
53# define MK_RB_EXTERN
54#endif
55
56// external data lookup
57#undef MK_RB_EXTERN_DATA
58#if defined(META_PRIVATE)
59# define MK_RB_EXTERN_DATA extern
60#elif defined(META_IGNORE_EXTERN)
61# define MK_RB_EXTERN_DATA extern
62#elif defined(PIC)
63 // does we build a DLL ?
64# if defined(DLL_EXPORT)
65 // does we build the libmkkernel library ?
66# if defined(MK_RB_BUILD_DLL)
67# define MK_RB_EXTERN_DATA __declspec(dllexport)
68# else
69# define MK_RB_EXTERN_DATA __declspec(dllimport)
70# endif
71# else
72 // no DLL - architecture specific extern specifier
73# define MK_RB_EXTERN_DATA __attribute__ ((visibility("default"))) extern
74# endif
75#else
76# define MK_RB_EXTERN_DATA extern
77#endif
78
79#undef MK
80#define MK(n) rbmkkernel_ ## n
81#undef NS
82#define NS(n) rbmkkernel_ ## n
83
84// END-HEADER - created by 'rb_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
85
86#undef OT_PKG
87#define OT_PKG MK(MkKernel)
88
89// LNG ******************************************************************************
90
91#define OT_OBJ_T VALUE
92#define OT_ENUM_T VALUE
93#define OT_CLS_T VALUE
94
95#define OT_LNG_NULL Qnil
96#define OT_LNG_UNDEF Qundef
97#define OT_LNG_IS_NULL(val) RB_NIL_OR_UNDEF_P(val)
98#define OT_LNG_RETURN(ret,cmd) ret=cmd
99
100#define OT_LNG_NAME_FROM_OBJ(obj) VAL2STRN(obj)
101#define OT_LNG_NAME_FROM_CLASS(cls) rb_class2name(cls)
102#define OT_LNG_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
103
104#define OT_LNG_OBJV(idx) objv[idx]
105
106#define OT_LNG_OBJ_CLASS_IS(obj,cls) (rb_obj_is_kind_of(obj,cls) == Qtrue)
107#define OT_OBJ_TO_CLASS(str) str
108#define OT_OBJ_TO_ENUM(str) NS(str)
109
110#define OT_LNG_OBJECT_IS(obj) OT_LNG_OBJ_CLASS_IS(obj,MK(MkObjectC))
111
112/*
113#define OT_LNG_ARRAY_LEN(ary) rb_array_len(ary)
114#define OT_LNG_ARRAY_IDX(ary,idx) rb_ary_entry(ary,idx)
115#define OT_LNG_ARRAY_PUSH(ary,val) rb_ary_push(ary,val)
116
117#define OT_LNG_I32_IS(obj) (rb_check_to_int(objV) != Qnil)
118
119#define OT_OBJ_TYPE_STRING(obj) rb_obj_classname(obj)
120*/
121
122#define OT_LNG_NULL_IS(obj) (!RB_TEST(obj))
123
124#define OT_LNG_OBJ_ENUM_IS(obj,enm) (rb_obj_is_kind_of(obj,enm) == Qtrue)
125#define OT_LNG_ENUM_NAME(enm) OT_LNG_NAME_FROM_CLASS(enm)
126#define OT_ENUM_TO_I32(o,e) o = rb_funcallv(o,MK(id_to_i),0,NULL)
127#define OT_ENUM_TO_I32_2(o,e) o = rb_funcallv(o,MK(id_to_i),0,NULL)
128
129#define OT_LNG_ARRAY_IS(o) (RB_TYPE_P(o,T_ARRAY))
130//#define OT_LNG_ARRAY_IS(ary) (TYPE(ary) == T_ARRAY)
131
132#define OT_LNG_STRN_PRE(cs,obj) MK_STRN cs = VAL2STRN(obj)
133#define OT_LNG_STRN_POST(cs,obj)
134
135#define OT_LNG_LONG_IS(obj) (CHECK_LONG(obj) || CHECK_STRING(obj)) // from "high"
136#define OT_LNG_I32_IS(obj) (CHECK_LONG(obj) || CHECK_STRING(obj)) // from "high"
137
138#define OT_LNG_SKIP_TYPE int
139
140/*****************************************************************************/
141/* */
142/* Class_API */
143/* */
144/*****************************************************************************/
145
146#define LNG_ARGS int objc, VALUE *objv, VALUE self
147#define LNG_ARGS_CALL objc, objv, self
148
149#define CONSTR_ARGS LNG_ARGS
150#define CONSTR_ARGS_CALL LNG_ARGS_CALL
151
152#define OtClass_ARGS int objc, VALUE *objv, VALUE self
153#define OtClass_ARGS_CALL objc, objv, self
154
155
156#define OT_OBJECT_DELETE_SOFT(obj) MK(AtomDeleteSoft)(VAL2MNG(obj));
157// RUBY does NOT support HARD destructor
158#define OT_OBJECT_DELETE_HARD(obj) MK(AtomDeleteHard)(MK_RT_CALL obj);
159#define OT_OBJECT_DELETE(obj) MK(AtomDelete)(MK_RT_CALL hdl);
160#define OT_OBJECT_DISPOSE(obj) MK(AtomDispose)(MK_RT_CALL hdl);
161
162#if !defined(MK_BASE_CLASS)
163# define MK_BASE_CLASS MK(MkObjectC)
164#endif
165
166// called from ALL "*_ObjNew" style functions
167mk_inline VALUE MK(AtomObjNew) (MK_RT_ARGS MK_OBJ obj) ;
168mk_inline void MK(AtomDeleteSoft) (MK_MNG);
169mk_inline void MK(AtomDeleteHard) (MK_RT_ARGS OT_OBJ_T);
170mk_inline void MK(AtomDelete) (MK_RT_ARGS MK_MNG);
171mk_inline void MK(AtomDispose) (MK_RT_ARGS MK_MNG);
172
175
176// BEGIN-CLASS - created by 'rb_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
177
178// ----------------------------------------------------------------------
179// class: MkBufferListC
180
182 #define MkBufferListC_lngO MK(MkBufferListC)
183 #define MkBufferListC_base MK(MkObjectC)
184
185 // MK_NULL singelton
187 #define MkBufferListC_MK_NULL MK(MkBufferListC_MK_NULL)
188
189 // arguments
190 #define MkBufferListC_ARGS LNG_ARGS
191 #define MkBufferListC_ARGS_CALL LNG_ARGS_CALL
192
193 // return object
194 #define OT_retObj_SET_BFL(nat) retObj = MK(MkBufferListC_ObjNew) (MK_RT_CALL nat)
195
196 // new object
197 #define OT_TMP_BFL_OBJ(val) MK(MkBufferListC_ObjNew)(MK_RT_CALL val)
199 mk_inline OT_OBJ_T MK(MkBufferListC_ObjNew) (MK_RT_ARGS MkBufferListC_type hdl) {
200 return hdl ? MK(AtomObjNew) (MK_RT_CALL MkBufferListC_X2obj(hdl)) : MkBufferListC_MK_NULL;
201 }
202
203 // cast from LNG to MQ
204 #define VAL2BFL(val) ((MK_BFL)DATA_PTR(val))
205
206// ----------------------------------------------------------------------
207// class: MkBufferC
208
210 #define MkBufferC_lngO MK(MkBufferC)
211 #define MkBufferC_base MK(MkObjectC)
212
213 // MK_NULL singelton
215 #define MkBufferC_MK_NULL MK(MkBufferC_MK_NULL)
216
217 // arguments
218 #define MkBufferC_ARGS LNG_ARGS
219 #define MkBufferC_ARGS_CALL LNG_ARGS_CALL
220
221 // return object
222 #define OT_retObj_SET_BUF(nat) retObj = MK(MkBufferC_ObjNew) (MK_RT_CALL nat)
223
224 // new object
225 #define OT_TMP_BUF_OBJ(val) MK(MkBufferC_ObjNew)(MK_RT_CALL val)
228 return hdl ? MK(AtomObjNew) (MK_RT_CALL MkBufferC_X2obj(hdl)) : MkBufferC_MK_NULL;
229 }
230
231 // cast from LNG to MQ
232 #define VAL2BUF(val) ((MK_BUF)DATA_PTR(val))
233
234// ----------------------------------------------------------------------
235// class: MkBufferStreamC
236
237 MK_RB_EXTERN_DATA OT_CLS_T MK(MkBufferStreamC);
238 #define MkBufferStreamC_lngO MK(MkBufferStreamC)
239 #define MkBufferStreamC_base MK(MkObjectC)
240
241 // MK_NULL singelton
243 #define MkBufferStreamC_MK_NULL MK(MkBufferStreamC_MK_NULL)
244
245 // arguments
246 #define MkBufferStreamC_ARGS LNG_ARGS
247 #define MkBufferStreamC_ARGS_CALL LNG_ARGS_CALL
248
249 // return object
250 #define OT_retObj_SET_BUS(nat) retObj = MK(MkBufferStreamC_ObjNew) (MK_RT_CALL nat)
251
252 // new object
253 #define OT_TMP_BUS_OBJ(val) MK(MkBufferStreamC_ObjNew)(MK_RT_CALL val)
255 mk_inline OT_OBJ_T MK(MkBufferStreamC_ObjNew) (MK_RT_ARGS MkBufferStreamC_type hdl) {
256 return hdl ? MK(AtomObjNew) (MK_RT_CALL MkBufferStreamC_X2obj(hdl)) : MkBufferStreamC_MK_NULL;
257 }
258
259 // cast from LNG to MQ
260 #define VAL2BUS(val) ((MK_BUS)DATA_PTR(val))
261
262// ----------------------------------------------------------------------
263// class: MkErrorC
264
266 #define MkErrorC_lngO MK(MkErrorC)
267 #define MkErrorC_base MK(MkObjectC)
268
269 // MK_NULL singelton
271 #define MkErrorC_MK_NULL MK(MkErrorC_MK_NULL)
272
273 // arguments
274 #define MkErrorC_ARGS LNG_ARGS
275 #define MkErrorC_ARGS_CALL LNG_ARGS_CALL
276
277 // return object
278 #define OT_retObj_SET_ERR(nat) retObj = MK(MkErrorC_ObjNew) (MK_RT_CALL nat)
279
280 // new object
281 #define OT_TMP_ERR_OBJ(val) MK(MkErrorC_ObjNew)(MK_RT_CALL val)
284 return hdl ? MK(AtomObjNew) (MK_RT_CALL MkErrorC_X2obj(hdl)) : MkErrorC_MK_NULL;
285 }
286
287 // cast from LNG to MQ
288 #define VAL2ERR(val) ((MK_ERR)DATA_PTR(val))
289
290// ----------------------------------------------------------------------
291// class: MkLogFileC
292
294 #define MkLogFileC_lngO MK(MkLogFileC)
295 #define MkLogFileC_base MK(MkObjectC)
296
297 // MK_NULL singelton
299 #define MkLogFileC_MK_NULL MK(MkLogFileC_MK_NULL)
300
301 // arguments
302 #define MkLogFileC_ARGS LNG_ARGS
303 #define MkLogFileC_ARGS_CALL LNG_ARGS_CALL
304
305 // return object
306 #define OT_retObj_SET_LFL(nat) retObj = MK(MkLogFileC_ObjNew) (MK_RT_CALL nat)
307
308 // new object
309 #define OT_TMP_LFL_OBJ(val) MK(MkLogFileC_ObjNew)(MK_RT_CALL val)
311 mk_inline OT_OBJ_T MK(MkLogFileC_ObjNew) (MK_RT_ARGS MkLogFileC_type hdl) {
312 return hdl ? MK(AtomObjNew) (MK_RT_CALL MkLogFileC_X2obj(hdl)) : MkLogFileC_MK_NULL;
313 }
314
315 // cast from LNG to MQ
316 #define VAL2LFL(val) ((MK_LFL)DATA_PTR(val))
317
318// ----------------------------------------------------------------------
319// class: MkObjectC
320
322 #define MkObjectC_lngO MK(MkObjectC)
323 #define MkObjectC_base NULL
324
325 // MK_NULL singelton
327 #define MkObjectC_MK_NULL MK(MkObjectC_MK_NULL)
328
329 // arguments
330 #define MkObjectC_ARGS LNG_ARGS
331 #define MkObjectC_ARGS_CALL LNG_ARGS_CALL
332
333 // return object
334 #define OT_retObj_SET_OBJ(nat) retObj = MK(MkObjectC_ObjNew) (MK_RT_CALL nat)
335
336 // new object
337 #define OT_TMP_OBJ_OBJ(val) MK(MkObjectC_ObjNew)(MK_RT_CALL val)
340 return hdl ? MK(AtomObjNew) (MK_RT_CALL MkObjectC_X2obj(hdl)) : MkObjectC_MK_NULL;
341 }
342
343 // cast from LNG to MQ
344 #define VAL2OBJ(val) ((MK_OBJ)DATA_PTR(val))
345
346// ----------------------------------------------------------------------
347// class: MkRuntimeC
348
350 #define MkRuntimeC_lngO MK(MkRuntimeC)
351 #define MkRuntimeC_base MK(MkObjectC)
352
353 // MK_NULL singelton
355 #define MkRuntimeC_MK_NULL MK(MkRuntimeC_MK_NULL)
356
357 // arguments
358 #define MkRuntimeC_ARGS LNG_ARGS
359 #define MkRuntimeC_ARGS_CALL LNG_ARGS_CALL
360
361 // return object
362 #define OT_retObj_SET_RT(nat) retObj = MK(MkRuntimeC_ObjNew) (MK_RT_CALL nat)
363
364 // new object
365 #define OT_TMP_RT_OBJ(val) MK(MkRuntimeC_ObjNew)(MK_RT_CALL val)
367 mk_inline OT_OBJ_T MK(MkRuntimeC_ObjNew) (MK_RT_ARGS MkRuntimeC_type hdl) {
368 return hdl ? MK(AtomObjNew) (MK_RT_CALL MkRuntimeC_X2obj(hdl)) : MkRuntimeC_MK_NULL;
369 }
370
371 // cast from LNG to MQ
372 #define VAL2RT(val) ((MK_RT)DATA_PTR(val))
373
374// END-CLASS - created by 'rb_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
375
376/*****************************************************************************/
377/* */
378/* lng_basic */
379/* */
380/*****************************************************************************/
381
382#define OT_ProcRet VALUE
383#define MK_CONTEXT_S hdl
384
385#define OT_METH_P(c,s,f) rb_define_private_method (NS(c),#s,NS(f),-1);
386#define OT_METH_C(c,s,f) rb_define_singleton_method (NS(c),#s,NS(f),-1);
387#define OT_METH_S(c,s,f) rb_define_singleton_method (NS(c),#s,NS(f),-1);
388#define OT_METH_O(c,s,f) rb_define_method (NS(c),#s,NS(f),-1);
389
390//RUBY does NOT support DTOR
391//#define OT_METH_D(c,s,f) rb_define_method (MK(c),#s,MK(f),-1);
392
393
394//#define OT_SETUP_VARARGS(d) VALUE retObj=Qundef; int __skip=0; static const MK_STRN doc-group=d;
395//#define OT_SETUP_ONEARG(d) VALUE retObj=Qundef; int __skip=0; static const MK_STRN doc-group=d;
396//#define OT_SETUP_NOARG(d) VALUE retObj=Qundef; int __skip=0; static const MK_STRN doc-group=d;
397
398#define OT_SETUP_ALL(d) \
399 VALUE retObj=Qundef; \
400 int __skip=0; \
401 __attribute__((unused)) const static char __doc[]=d; \
402 __attribute__((unused)) VALUE frame=0;
403
404#define OT_SETUP_CONSTRUCTOR_ARGS(min,max,d) \
405 OT_SETUP_ALL(d) \
406 OT_CHECK_NUM_ARGS(min,99); \
407
408#define OT_SETUP_VARARGS(min,max,d) \
409 OT_SETUP_ALL(d) \
410 OT_CHECK_NUM_ARGS(min,max); \
411
412#define OT_SETUP_ONEARG(d) \
413 OT_SETUP_ALL(d) \
414 OT_CHECK_NUM_ARGS(1,1); \
415
416#define OT_SETUP_NOARG(d) \
417 OT_SETUP_ALL(d) \
418 OT_CHECK_NUM_ARGS(0,0); \
419
420#define OT_FRAME_CLEANUP // cleanup by garbage collection.
421
422#define SETUP_ARGS MK_RT_ARGS LNG_ARGS
423#define SETUP_ARGS_CALL MK_RT_CALL LNG_ARGS_CALL
424
425#define OT_SELF self
426#define OT_RET_SELF OT_SELF
427#if !defined(OBJ)
428 #ifdef __SANITIZE_ADDRESS__
429 #define OBJ ((MK_OBJ)hdl)
430 #else
431 #define OBJ &hdl->obj
432 #endif
433#endif
434
435/*printV("NULL !! selfL: %lx, type=%x, type->data=%p\n",OT_SELF,TYPE(OT_SELF),RTYPEDDATA_DATA(OT_SELF)); */
436/* MkPanicC_2M(NULL,"'" #cls "C' hdl is NULL"); */
437/* rb_raise(MK(InitError), "'" #cls "' hdl is NULL"); */
438
439#define OT_SETUP_hdl_tmpl(cls) \
440 cls##_type hdl = cls##_VAL2(OT_SELF); \
441 if (hdl == NULL) { \
442 OT_ERROR_VAR_DEFAULT(MK(InitError),"'%s' hdl is NULL",OT_LNG_OBJ_CLASSNAME(OT_SELF)); \
443 } \
444 SetupRtFromObj_XN(hdl); \
445
446#define OT_SETUP_hdl_tmpl__null_allow(cls) \
447 cls##_type hdl = cls##_VAL2(OT_SELF); \
448 SetupRtFromObj_X(hdl); \
449
450#define OT_SETUP_doc __attribute__((unused)) const char *__doc = __func__;
451
452#define OT_retObj_SET(val) retObj = (val);
453#define OT_retObj_SET_None retObj = Qnil;
454#define OT_retObj_SET_Error retObj = Qundef;
455#define OT_retObj_SET_List retObj = rb_ary_new();
456#define OT_retObj_APPEND(var) rb_ary_push(retObj,var);
457#define OT_retObj_RETURN return retObj;
458
459#define OT_retObj_SET_BOL(nat) retObj = BOL2VAL(nat);
460#define OT_retObj_SET_I8(nat) retObj = I82VAL(nat);
461#define OT_retObj_SET_I16(nat) retObj = I162VAL(nat);
462#define OT_retObj_SET_I32(nat) retObj = INT2VAL(nat);
463#define OT_retObj_SET_I64(nat) retObj = I642VAL(nat);
464#define OT_retObj_SET_FLT(nat) retObj = FLT2VAL(nat);
465#define OT_retObj_SET_DBL(nat) retObj = DBL2VAL(nat);
466#define OT_retObj_SET_BIN(nat,len) retObj = BIN2VAL(nat,len);
467#define OT_retObj_SET_STR(nat) retObj = STRN2VAL(nat);
468#define OT_retObj_SET_STRN(nat) retObj = STRN2VAL(nat);
469#define OT_retObj_SET_LONG(nat) retObj = LONG2VAL(nat);
470#define OT_retObj_SET_HDL(nat) retObj = HDL2VAL(nat);
471
472// METHOD CALL **********************************************************************
473
474#define OT_MK_CALL_0(obj,cls,meth,ret) { \
475 static __thread ID methid = 0; \
476 if (methid == 0) methid = rb_intern(#meth); \
477 ret = rb_funcallv(cls##_constr(obj),methid,0,NULL); \
478}
479
480#define OT_MK_CALL_0_0(ret,obj,cls,meth) ret = rb_funcallv(obj,meth,0,NULL)
481
482// CONSTR *****************************************************************************
483
484#define OT_retObj_CONSTR(mng) OT_retObj_SET(NS(LNG_CONSTR)(clazz,mng,objc-__skip,objv+__skip))
485#define OT_CONSTRUCTOR_POST(x)
486
487// error ******************************************************************************
488
489#define OT_ERROR_LNG_RETURN \
490 rb_raise(rb_eRuntimeError, "%s", "not implemented"); \
491 MK_UNREACHABLE;
492
493#define OT_ERROR_SOFT_CONSTRUCTOR(clazz) \
494 rb_raise(MK(InitError), "InitSoftError: '%s' soft constructor return 'NULL' pointer", #clazz); \
495 MK_UNREACHABLE;
496
497#define OT_ERROR_CONSTRUCTOR(clazz) \
498 rb_raise(MK(InitError), "'%s' constructor return 'NULL' pointer", #clazz); \
499 MK_UNREACHABLE;
500
501#define OT_ERROR_TYPE(str) \
502 rb_raise(rb_eTypeError, "%s", str); \
503 MK_UNREACHABLE;
504
505#define OT_ERROR_RUNTIME(clazz, str) \
506 rb_raise(rb_eRuntimeError, "in class %s: %s.", #clazz, str); \
507 MK_UNREACHABLE;
508
509
510// !! attention → always jumps to error
511#define OT_ERROR_NUMARGS(...) \
512 MkErrorC_CheckD(WrongNumArgs(__VA_ARGS__)); \
513 MK_UNREACHABLE; \
514
515#define MkErrorC_Check(mng,PROC) \
516 if (unlikely(MkErrorCheckI(PROC))) { \
517 OT_ERROR_META_2_LNG(mng); \
518 MK_UNREACHABLE; \
519 } \
520
521#define MkErrorC_CheckD(PROC) \
522 if (unlikely(MkErrorCheckI(PROC))) { \
523 OT_ERROR_META_2_LNG(hdl); \
524 MK_UNREACHABLE; \
525 } \
526
527#define check_META(code) if (MkErrorCheckI(code))
528
529#define OT_ERROR_VAR_DEFAULT(exp,...) do { \
530 char buf[512]; \
531 ruby_snprintf(buf,512,__VA_ARGS__); \
532 rb_raise(exp,buf); \
533 MK_UNREACHABLE; \
534} while (0)
535
536// new object ******************************************************************************
537
538#define OT_TMP_BOL_OBJ(val) BOL2VAL(val)
539#define OT_TMP_I8_OBJ(val) I82VAL(val)
540#define OT_TMP_I16_OBJ(val) I162VAL(val)
541#define OT_TMP_I32_OBJ(val) INT2VAL(val)
542#define OT_TMP_I64_OBJ(val) I642VAL(val)
543#define OT_TMP_FLT_OBJ(val) FLT2VAL(val)
544#define OT_TMP_DBL_OBJ(val) DBL2VAL(val)
545#define OT_TMP_BIN_OBJ(val,len) BIN2VAL(val,len)
546#define OT_TMP_STR_OBJ(val) STRN2VAL(val)
547
548// check *********************************************************************************
549
550#define OT_Prefix_ARGS MK_RT_ARGS
551#define OT_Prefix_CALL MK_RT_CALL
552
553#define OT_Check_ARGS SETUP_ARGS, MK_MNG hdl, MK_STRN const arg, int *skipP
554#define OT_Check_CALL(arg) SETUP_ARGS_CALL, hdl, arg, &__skip
555#define OT_Check_CALL2(arg) SETUP_ARGS_CALL, hdl, arg, skipP
556
557#define OT_CHECK_OPTIONAL(val) if (__skip < objc) {val}
558#define OT_CHECK_REQUIRED(val) val
559
560#define OT_CHECK_NUM_ARGS(min,max) \
561 if ((objc-__skip) < min || (objc-__skip) > max) { \
562 OT_ERROR_NUMARGS(hdl, __skip, objc, min, max, ""); \
563 } \
564
565#define OT_CHECK_NOARGS \
566 if (__skip != objc) { \
567 OT_ERROR_NUMARGS(hdl, __skip, objc, -999, +999, ""); \
568 } \
569
570#define OT_CHECK_BNP(val,len) \
571 if (__skip >= objc) { \
572 OT_ERROR_NUMARGS(hdl, __skip, objc, -999, +999, #val); \
573 } else { \
574 OT_OBJ_T nat = objv[__skip++]; \
575 val = (MK_BIN) RSTRING_PTR(nat); \
576 len = (MK_SIZE) RSTRING_LEN(nat); \
577 } \
578
579#define OT_CHECK_BCP(val) \
580 if (__skip >= objc) { \
581 OT_ERROR_NUMARGS(hdl, __skip, objc, -999, +999, #val); \
582 } else { \
583 OT_OBJ_T nat = objv[__skip++]; \
584 val = (MK_BINN) RSTRING_PTR(nat); \
585 } \
586
587#define OT_GET_CONSTR_NAME(ctor) OT_LNG_NAME_FROM_OBJ((OT_OBJ_T)ctor)
588
589/*****************************************************************************/
590/* */
591/* debugging */
592/* */
593/*****************************************************************************/
594
596
597#define printLngObj(val) MK(_printObj)(MK_RT_CALL val,__func__);
598
599// enums ******************************************************************************
600
601#include "tmpl/mk_misc_check_lng.h"
602
603mk_inline VALUE MK(OtNewInstanceWithOneArg)(VALUE type, VALUE arg) {
604 VALUE args[1];
605 args[0] = arg;
606 VALUE ret = rb_class_new_instance(1,args,type);
607 return ret;
608}
609
610#define OT_NEW_Mk_enum_OBJ(typ,i) MK(OtNewInstanceWithOneArg)(MK(Mk##typ),INT2VAL(i))
611typedef VALUE(*MK(procCallF))(VALUE args);
612
630
631MK_EXTERN void NS(CallFree) (MK_PTR* callP);
632MK_EXTERN void NS(CallFreeOnce) (MK_PTR* callP);
633
634// BEGIN-enum - created by 'rb_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
635
640
641// END-enum - created by 'rb_MqS.tcl -i NHI1_HOME/theKernel/c/gen/c_mkkernel.meta' - DO NOT change
642
643// class ******************************************************************************
644
645// object 2 native *************************************************************************
646
648
649#define OT_CHECK_LNGTMPL(val,func) MkErrorC_CheckD (func(OT_Check_CALL(#val),&val));
650
651#define OT_CHECK_bool(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsBOOL))
652#define OT_CHECK_NB1(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsBOL))
653#define OT_CHECK_NI1(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsI8))
654#define OT_CHECK_NI2(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsI16))
655#define OT_CHECK_NI4(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsI32))
656#define OT_CHECK_NI8(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsI64))
657#define OT_CHECK_NF4(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsFLT))
658#define OT_CHECK_NF8(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsDBL))
659#define OT_CHECK_NIL(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsLONG))
660#define OT_CHECK_STRN(val) OT_CHECK_LNGTMPL(val,MK(Obj_AsSTRN))
661
662MK_RB_EXTERN enum MkErrorE MK(Obj_AsSTR_COPY) (OT_Check_ARGS,MK_STR,size_t);
663#define OT_CHECK_C_COPY(val,size) MkErrorCheck (MK(Obj_AsSTR_COPY)(OT_Check_CALL(#val),val,size));
664
665// isc nspection *************************************************************************
666
667#define OT_GET_CALL_PROC MK(Get_Call_Proc) (1,&frame)
668#define OT_GET_CALL_FILE MK(Get_Call_Script) (1,&frame)
669#define OT_GET_CALL_LINE MK(Get_Call_Line) (1,&frame)
670
671MK_RB_EXTERN MK_STRN MK(Get_Call_Proc) (int,VALUE*);
672MK_RB_EXTERN MK_STRN MK(Get_Call_Script) (int,VALUE*);
673MK_RB_EXTERN MK_I32 MK(Get_Call_Line) (int,VALUE*);
674MK_RB_EXTERN void MK(Get_Call_All) (int,MK_STRN*,MK_STRN*,MK_I32*);
675void MK(Get_Call_Stack) (MK_RT_ARGS MK_ERR const, int);
676void MK(printLNG_STACK) (MK_RT_ARGS MK_MNG mng);
677
678#define OT_GET_CALL_ALL \
679 MK_STRN proc,file; MK_I32 line; MK(Get_Call_All)(0,&proc,&file,&line);
680
681/*****************************************************************************/
682/* */
683/* functions */
684/* */
685/*****************************************************************************/
686
687// from misc_lng.c
688MK_RB_EXTERN void MK(MkExceptionC_Raise) (OT_Prefix_ARGS MK_MNGN const, MK_STRN const, MK_STRN const, MK_I32);
689MK_RB_EXTERN MK_ERR MK(MkExceptionC_Catch) (OT_Prefix_ARGS MK_MNG const, MK_EXP const, MK_STRN const, MK_STRN const);
690
691#define OT_ERROR_META_2_LNG(m) MK(MkExceptionC_Raise) (OT_Prefix_CALL m, __doc, __FILE__, __LINE__)
692#define OT_ERROR_LNG_2_META(m) MK(MkExceptionC_Catch) (OT_Prefix_CALL m, NULL, __func__, NULL)
693#define OT_ERROR_LNG_2_META_2(m,s) MK(MkExceptionC_Catch) (OT_Prefix_CALL m, NULL, __func__, s)
694
695// from MkBufferListC_rb.c
697
698#define NIL_Check(v) if (NIL_P(v)) goto error;
699
700/*****************************************************************************/
701/* */
702/* ref counting */
703/* */
704/*****************************************************************************/
705
706# define INCR_REG(val) rb_ary_push(MK(globalRef),val)
707# define DECR_REG(val) rb_ary_delete(MK(globalRef),val)
708
709# define INCR_REF(valP) rb_gc_register_address(valP)
710# define DECR_REF(valP) rb_gc_unregister_address(valP)
711
714
715/*****************************************************************************/
716/* */
717/* definition's */
718/* */
719/*****************************************************************************/
720
721#define VAL2I8(val) (MK_I8)NUM2CHR(val)
722#define VAL2BOL(val) (MK_BOL)MK(_VAL2BOL)(val)
723#define VAL2SRT(val) (MK_I16)NUM2SHORT(val)
724#define VAL2I32(val) (MK_I32)NUM2INT(val)
725#define VAL2I64(val) (MK_I64)NUM2LL(val)
726#define VAL2FLT(val) (MK_FLT)NUM2DBL(val)
727#define VAL2DBL(val) (MK_DBL)NUM2DBL(val)
728#define VAL2STRN(val) (MK_STRN)RSTRING_PTR(rb_obj_as_string(val))
729#define VAL2BIN(val) (MK_BINN)RSTRING_PTR(val),RSTRING_LEN(val)
730#define VAL2PTR(val) (MK_PTR)(val)
731#define VAL2REF(val) (MK_PTR)(val)
732#define VAL2LONG(val) NUM2LONG(val)
733#define VAL2MNG(val) (MK_MNG)DATA_PTR(val)
734
735#define PTR2VAL(nat) MK(_PTR2VAL)(nat)
736#define OBJ2VAL(nat) ((OT_OBJ_T)((MK_OBJ)nat)->self)
737#define I82VAL(nat) INT2FIX((MK_I8)nat)
738#define BOL2VAL(nat) ((nat)?Qtrue:Qfalse)
739#define I162VAL(nat) INT2FIX((MK_I16)nat)
740#define INT2VAL(nat) INT2NUM((MK_I32)nat)
741#define I642VAL(nat) LL2NUM((MK_I64)nat)
742#define FLT2VAL(nat) DBL2NUM((double)nat)
743#define DBL2VAL(nat) DBL2NUM((double)nat)
744#define STRN2VAL(nat) MK(_STRN2VAL)(nat)
745#define BIN2VAL(ptr,len) rb_str_new((const char*)ptr,(long)len)
746#define STR2VAL(ptr,len) rb_str_new((const char*)ptr,(long)len)
747#define LONG2VAL(nat) LONG2FIX(nat)
748#define HDL2VAL(nat) INT2NUM(nat)
749
750
751// *********************************************************************************************
752
753mk_inline bool MK(_VAL2BOL) (OT_OBJ_T val) {return RTEST(val); }
754mk_inline OT_OBJ_T MK(_PTR2VAL) (MK_PTR nat) {return (nat != NULL ? (OT_OBJ_T)(nat) : Qnil);}
755MK_RB_EXTERN_DATA VALUE MK(NULL_STR);
757 // mark=MK_NULL
758 if (val==MK_NULL) {
759 return MK(NULL_STR);
760 } else {
761 return rb_str_new_cstr(val);
762 }
763}
764
765/*****************************************************************************/
766/* */
767/* reference */
768/* */
769/*****************************************************************************/
770
771#define ME_REF_MkBinaryR MkBinaryR
772#define OT_GET__ME_REF_MkBinaryR(b) BIN2VAL(b.data,(int)b.size)
773#define VAL2MkBinaryR(_obj) ({ \
774 OT_OBJ_T obj=_obj; \
775 MK_BIN bin=NULL; \
776 MK_SIZE len=0; \
777 if (!OT_LNG_IS_NULL(obj)) { \
778 if (RB_TYPE_P(obj, T_STRING)) { \
779 bin = (MK_BIN)RSTRING_PTR(obj); \
780 len = (MK_SIZE)RSTRING_LEN(obj); \
781 } else { \
782 OT_ERROR_TYPE("parameter '" #_obj "' must be a 'byte-array'."); \
783 } \
784 } \
785 MkBinaryCreate(len,bin); \
786})
787#define OT_CHECK__ME_REF_MkBinaryR(val) \
788 if (__skip >= objc) { \
789 OT_ERROR_NUMARGS(hdl,__skip, objc, -999, +999, #val); \
790 } else { \
791 val=VAL2MkBinaryR(objv[__skip++]); \
792 }
793
794#define ME_REF_MkStringR MkStringR
795#define OT_GET__ME_REF_MkStringR(b) STR2VAL(b.ptr,b.len)
796#define VAL2MkStringR(_obj) ({ \
797 OT_OBJ_T obj=_obj; \
798 MK_STRN str=NULL; \
799 MK_NUM len=0; \
800 if (!OT_LNG_IS_NULL(obj)) { \
801 str=RSTRING_PTR(obj); \
802 len=RSTRING_LENINT(obj); \
803 } \
804 MkStringCreate(len,str); \
805})
806#define OT_CHECK__ME_REF_MkStringR(val) \
807 if (__skip >= objc) { \
808 OT_ERROR_NUMARGS(hdl,__skip, objc, -999, +999, #val); \
809 } else { \
810 val=VAL2MkStringR(objv[__skip++]); \
811 }
812
813/*****************************************************************************/
814/* */
815/* Misc's */
816/* */
817/*****************************************************************************/
818
820MK_RB_EXTERN_DATA ID MK(id_unbind);
822MK_RB_EXTERN_DATA ID MK(id_receiver);
823MK_RB_EXTERN_DATA ID MK(id_enum_attr);
825
826// called from ALL "*_ObjNew" style functions
827mk_inline VALUE MK(AtomObjNew) (MK_RT_ARGS MK_OBJ obj)
828{
829 if (obj == NULL) return Qnil;
830 #define __doc "AtomObjNew"
831 MK_PTR self = NULL;
832 MkErrorC_Check(obj, MkSelfNew(obj,&self,NULL))
833 return (VALUE) self;
834 #undef __doc
835}
836
837// called from ALL "LNG_CONSTR" style functions
838mk_inline VALUE MK(AtomObjCrt) (OT_CLS_T clazz, MK_PTR type, MK_MNG mng, int objc, VALUE* objv)
839{
840 OT_OBJ_T self = TypedData_Wrap_Struct (clazz, type, mng);
841 rb_obj_call_init(self, objc, objv);
842 rb_gc_register_mark_object(self);
843 return self;
844}
845
846mk_inline VALUE MK(AtomCreate) (MkObjectC_ARGS)
847{
848 MK_MNG mng = VAL2MNG(self);
849 if (mng == 0L) {
850 rb_raise(rb_eRuntimeError, "MkObjectC: the constructor has a NULL pointer");
852 }
853 MK_OBJ obj = MkObj((MK_MNG)mng);
854 if (obj == NULL) {
855 rb_raise(rb_eRuntimeError, "MkObjectC: signature check failed");
857 }
858 MK_PTR ref = VAL2PTR(self);
859 if (ref == NULL) {
860 rb_raise(rb_eRuntimeError, "MkObjectC: unable to create 'NewGlobalRef'");
862 }
863 MkRefIncrSelf(obj,ref,NULL);
864 // incr GC reference of SELF → decr in "AtomDeleteHard"
865 INCR_REF((VALUE*)&obj->self);
866 return Qnil;
867}
868
869// RUBY object is still alive
870// called by: "Delete" as pseudo-DTOR
871mk_inline void MK(AtomDeleteHard) (MK_RT_ARGS OT_OBJ_T self)
872{
873 if (OT_LNG_IS_NULL(self)) return;
874 // self
875 MK_MNG mng = VAL2MNG(self);
876 if (mng == NULL) return;
877 // object
878 MK_OBJ obj = MkObj(mng);
879 if (obj == NULL) return;
880 // delete link between SELF and META
881 // MkSelfUnlink(obj); → this does NOT work because the "self" is already NULL
882 DATA_PTR(self) = NULL;
883 // decr GC reference of SELF → incr in "AtomCreate"
884 DECR_REF((VALUE*)&obj->self);
885 // delete link between META and RELF
887}
888
889// RUBY object is already dead
890// called by: Data_Wrap_Struct on real object deletion
891mk_inline void MK(AtomDeleteSoft) (MK_MNG mng)
892{
893 MK_OBJ obj = MkObj(mng);
894//printXV(obj,"111111111111111111 → mng=%p, obj=%p, self=%#lx\n", mng , obj, (obj?OBJ2VAL(obj):0))
895 if (obj == NULL) return;
896 MkRtSetup_ON(obj);
897
898// if (MkBflCheck(obj)) {
899// printTxt(MkObjectToName(obj));
900// printSTACK_1(obj);
901// }
902
903 // delete link between MQ and RUBY
904//printV("mng<%p>, valid<%d>\n",mng,MkObjCheck(mng))
906}
907
908// RUBY object is still alive
909// called by: "Delete" as pseudo-DTOR
910mk_inline void MK(AtomDelete) (MK_RT_ARGS MK_MNG mng)
911{
912 // object
913 MK_OBJ obj = MkObj(mng);
914 if (obj == NULL) return;
915 // delete link between META and RUBY
917}
918
919// RUBY object is still alive
920// called by: "Dispose" as pseudo-DTOR
921mk_inline void MK(AtomDispose) (MK_RT_ARGS MK_MNG mng)
922{
923 // object
924 MK_OBJ obj = MkObj(mng);
925 if (obj == NULL) return;
926 // delete link between META and RUBY
928}
929
930#undef HEADER
#define MK(n)
#define MkObjectC_MK_NULL
#define MkLogFileC_MK_NULL
#define OT_CLS_T
#define OT_Check_ARGS
#define INCR_REF(valP)
#define OT_OBJ_T
#define MkBufferListC_MK_NULL
#define NS(n)
#define VAL2MNG(val)
#define MkRuntimeC_MK_NULL
#define MkObjectC_ARGS
#define DECR_REF(valP)
#define MkErrorC_MK_NULL
#define MK_RB_EXTERN_DATA
#define MK_RB_EXTERN
static library
#define MkBufferC_MK_NULL
#define MkBufferStreamC_MK_NULL
#define OT_LNG_IS_NULL(val)
#define VAL2PTR(val)
#define MkBufferListC_ARGS
#define MkErrorC_Check(mng, PROC)
#define OT_ProcRet
#define OT_Prefix_ARGS
OT_ProcRet MK MkBufferListC_ToList(MkBufferListC_ARGS)
#define MkBufferC_type
#define MkBufferC_X2obj(x)
#define MkBufferListC_type
#define MkBufferListC_X2obj(x)
#define MkBufferStreamC_type
#define MkBufferStreamC_X2obj(x)
#define MkErrorC_X2obj(x)
#define MkErrorC_type
#define MK_UNREACHABLE
#define mk_inline
#define MK_EXTERN
#define MK_ARTIFICIAL
#define MK_NULL
MkTimeoutE
MkErrorE
MkTypeE
const MK_PTRB * MK_MNGN
MK_PTRB * MK_PTR
const MK_STRB * MK_STRN
MK_PTRB * MK_MNG
MK_PTRB const * MK_EXP
MK_STRB * MK_STR
signed int MK_I32
#define MkLogFileC_X2obj(x)
#define MkLogFileC_type
#define MkObjectC_X2obj(x)
#define MkObjectC_type
static MK_OBJ MkObj(MK_MNG mng)
#define MkSelfNew(...)
#define MkRefDecrWithUnlinkSelf(...)
#define MkRefDecrWithoutSelf(...)
static void MkRefIncrSelf(MK_OBJ const obj, MK_PTR const self, MK_PTR const env)
MkIdSE
#define MkRuntimeC_type
#define MkRuntimeC_X2obj(x)
#define MkRtSetup_ON(o)
#define MK_RT_CALL
#define MK_RT_ARGS
tag: nhi1-release-250425
tag: nhi1-release-250425
tag: nhi1-release-250425
VALUE procCallback
VALUE procArgs
bool procNeedSelf
MK_I32 procArity
enum MkCallS::@0 procType
@ MkCallS_unbound_method
@ MkCallS_other_method
rbmkkernel_procCallF procCall
MK_PTR self