Skip to content

Commit a2905fb

Browse files
committed
class name check
1 parent c0d3ca1 commit a2905fb

7 files changed

+57
-63
lines changed

codegen/gen_call_template.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
HEADER = <<EOD
66
// This file is generated from gen_template.rb
77
\#define ARG(mrb, i) Type<P##i>::get(mrb, args[i])
8-
\#define CHECK(i) {if(!Type<P##i>::check(args[i])) return RAISE(i);}
8+
\#define CHECK(i) {if(!Type<P##i>::check(mrb, args[i])) return RAISE(i);}
99
\#define RAISE(i) raise(mrb, i, Type<P##i>::TYPE_NAME, args[i])
1010
1111
EOD

codegen/gen_template.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
HEADER = <<EOD
55
// This file is generated from gen_template.rb
66
\#define ARG(mrb, i) Type<P##i>::get(mrb, args[i])
7-
\#define CHECK(i) {if(!Type<P##i>::check(args[i])) return RAISE(i);}
7+
\#define CHECK(i) {if(!Type<P##i>::check(mrb, args[i])) return RAISE(i);}
88
\#define RAISE(i) raise(mrb, i, Type<P##i>::TYPE_NAME, args[i])
99
\#define CHECKNARG(narg) {if(narg != NPARAM) RAISENARG(narg);}
1010
\#define RAISENARG(narg) raisenarg(mrb, mrb_cfunc_env_get(mrb, 1), narg, NPARAM)

codegen/gen_types_template.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
HEADER = <<EOD
55
// This file is generated from gen_template.rb
66
\#define ARG(mrb, i) Type<P##i>::get(mrb, args[i])
7-
\#define CHECK(i) {if(!Type<P##i>::check(args[i])) return RAISE(i);}
7+
\#define CHECK(i) {if(!Type<P##i>::check(mrb, args[i])) return RAISE(i);}
88
\#define RAISE(i) raise(mrb, i, Type<P##i>::TYPE_NAME, args[i])
99
1010
EOD
@@ -14,7 +14,7 @@
1414
// callback R(%PARAMS%)
1515
template<class R, %CLASSES%>
1616
struct Type<FuncPtr<R(%PARAMS%)> > : public TypeFuncBase {
17-
static int check(mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
17+
static int check(mrb_state*, mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
1818
static FuncPtr<R(%PARAMS%)> get(mrb_state* mrb, mrb_value v) {
1919
Deleter<std::function<R(%PARAMS%)> > d = set_avoid_gc<std::function<R(%PARAMS%)> >(mrb, v);
2020
return make_FuncPtr<R(%PARAMS%)>(d, [=](%ARGS%){
@@ -33,7 +33,7 @@
3333
// callback void(%PARAMS%)
3434
template<%CLASSES%>
3535
struct Type<FuncPtr<void(%PARAMS%)> > : public TypeFuncBase {
36-
static int check(mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
36+
static int check(mrb_state*, mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
3737
static FuncPtr<void(%PARAMS%)> get(mrb_state* mrb, mrb_value v) {
3838
Deleter<std::function<void(%PARAMS%)> > d = set_avoid_gc<std::function<void(%PARAMS%)> >(mrb, v);
3939
return make_FuncPtr<void(%PARAMS%)>(d, [=](%ARGS%){

codegen/mrubybind_types.1.h

+14-20
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ struct Type {
260260
template<>
261261
struct Type<int> {
262262
static const char TYPE_NAME[];
263-
static int check(mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
263+
static int check(mrb_state*, mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
264264
static int get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_fixnum_p(v) ? mrb_fixnum(v) : mrb_float(v); }
265265
static mrb_value ret(mrb_state*, int i) { return mrb_fixnum_value(i); }
266266
};
267267

268268
template<>
269269
struct Type<unsigned int> {
270270
static const char TYPE_NAME[];
271-
static int check(mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
271+
static int check(mrb_state*, mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
272272
static unsigned int get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_fixnum_p(v) ? mrb_fixnum(v) : mrb_float(v); }
273273
static mrb_value ret(mrb_state*, unsigned int i) { return mrb_fixnum_value(i); }
274274
};
@@ -277,7 +277,7 @@ struct Type<unsigned int> {
277277
template<>
278278
struct Type<float> {
279279
static const char TYPE_NAME[];
280-
static int check(mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
280+
static int check(mrb_state*, mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
281281
static float get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_float_p(v) ? mrb_float(v) : mrb_fixnum(v); }
282282
static mrb_value ret(mrb_state* mrb, float f) { return mrb_float_value(mrb, f); }
283283
};
@@ -286,7 +286,7 @@ struct Type<float> {
286286
template<>
287287
struct Type<double> {
288288
static const char TYPE_NAME[];
289-
static int check(mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
289+
static int check(mrb_state*, mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
290290
static double get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_float_p(v) ? mrb_float(v) : mrb_fixnum(v); }
291291
static mrb_value ret(mrb_state* mrb, double f) { return mrb_float_value(mrb, f); }
292292
};
@@ -295,31 +295,31 @@ struct Type<double> {
295295
template<>
296296
struct Type<const char*> {
297297
static const char TYPE_NAME[];
298-
static int check(mrb_value v) { return mrb_string_p(v); }
298+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
299299
static const char* get(mrb_state* mrb, mrb_value v) { (void)mrb; return RSTRING_PTR(v); }
300300
static mrb_value ret(mrb_state* mrb, const char* s) { return mrb_str_new_cstr(mrb, s); }
301301
};
302302

303303
template<>
304304
struct Type<std::string> {
305305
static const char TYPE_NAME[];
306-
static int check(mrb_value v) { return mrb_string_p(v); }
306+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
307307
static const std::string get(mrb_state* mrb, mrb_value v) { (void)mrb; return std::string(RSTRING_PTR(v), RSTRING_LEN(v)); }
308308
static mrb_value ret(mrb_state* mrb, const std::string& s) { return mrb_str_new(mrb, s.c_str(), s.size()); }
309309
};
310310

311311
template<>
312312
struct Type<const std::string> {
313313
static const char TYPE_NAME[];
314-
static int check(mrb_value v) { return mrb_string_p(v); }
314+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
315315
static const std::string get(mrb_state* mrb, mrb_value v) { (void)mrb; return std::string(RSTRING_PTR(v), RSTRING_LEN(v)); }
316316
static mrb_value ret(mrb_state* mrb, const std::string& s) { return mrb_str_new(mrb, s.c_str(), s.size()); }
317317
};
318318

319319
template<>
320320
struct Type<const std::string&> {
321321
static const char TYPE_NAME[];
322-
static int check(mrb_value v) { return mrb_string_p(v); }
322+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
323323
static const std::string get(mrb_state* mrb, mrb_value v) { (void)mrb; return std::string(RSTRING_PTR(v), RSTRING_LEN(v)); }
324324
static mrb_value ret(mrb_state* mrb, const std::string& s) { return mrb_str_new(mrb, s.c_str(), s.size()); }
325325
};
@@ -328,7 +328,7 @@ struct Type<const std::string&> {
328328
template<>
329329
struct Type<bool> {
330330
static const char TYPE_NAME[];
331-
static int check(mrb_value /*v*/) { return 1; }
331+
static int check(mrb_state*, mrb_value /*v*/) { return 1; }
332332
static bool get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_test(v); }
333333
static mrb_value ret(mrb_state* /*mrb*/, bool b) { return b ? mrb_true_value() : mrb_false_value(); }
334334
};
@@ -337,15 +337,9 @@ struct Type<bool> {
337337
template<>
338338
struct Type<void*> {
339339
static const char TYPE_NAME[];
340-
<<<<<<< HEAD
341340
static int check(mrb_value v) { return mrb_cptr_p(v); }
342341
static void* get(mrb_value v) { return mrb_cptr(v); }
343342
static mrb_value ret(mrb_state* mrb, void* p) { return mrb_cptr_value(mrb, p); }
344-
=======
345-
static int check(mrb_value v) { return mrb_voidp_p(v); }
346-
static void* get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_voidp(v); }
347-
static mrb_value ret(mrb_state* mrb, void* p) { return mrb_voidp_value(mrb, p); }
348-
>>>>>>> call back.
349343
};
350344

351345
// Function
@@ -355,7 +349,7 @@ struct TypeFuncBase{
355349

356350
template<class R>
357351
struct Type<FuncPtr<R()> > :public TypeFuncBase {
358-
static int check(mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
352+
static int check(mrb_state*, mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
359353
static FuncPtr<R()> get(mrb_state* mrb, mrb_value v) {
360354
Deleter<std::function<R()> > d = set_avoid_gc<std::function<R()> >(mrb, v);
361355
return make_FuncPtr<R()>(d, [=](){
@@ -372,7 +366,7 @@ struct Type<FuncPtr<R()> > :public TypeFuncBase {
372366

373367
template<>
374368
struct Type<FuncPtr<void()> > :public TypeFuncBase {
375-
static int check(mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
369+
static int check(mrb_state*, mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
376370
static FuncPtr<void()> get(mrb_state* mrb, mrb_value v) {
377371
Deleter<std::function<void()> > d = set_avoid_gc<std::function<void()> >(mrb, v);
378372
return make_FuncPtr<void()>(d, [=](){
@@ -391,7 +385,7 @@ struct Type<FuncPtr<void()> > :public TypeFuncBase {
391385
template<>
392386
struct Type<MrubyRef> {
393387
static const char TYPE_NAME[];
394-
static int check(mrb_value) { return 1; }
388+
static int check(mrb_state*, mrb_value) { return 1; }
395389
static MrubyRef get(mrb_state* mrb, mrb_value v) { (void)mrb; return MrubyRef(mrb, v); }
396390
static mrb_value ret(mrb_state*, MrubyRef r) { return r.get_v(); }
397391
};
@@ -433,8 +427,8 @@ struct TypeClassBase{
433427

434428
template<class T> struct Type :public TypeClassBase {
435429
static std::string class_name;
436-
static int check(mrb_value v) {
437-
return mrb_type(v) == MRB_TT_DATA;
430+
static int check(mrb_state* mrb, mrb_value v) {
431+
return mrb_type(v) == MRB_TT_DATA && strcmp(mrb_obj_classname(mrb, v), class_name.c_str()) == 0;
438432
}
439433
static T get(mrb_state* mrb, mrb_value v) {
440434
(void)mrb; return *(T*)DATA_PTR(v);

mrubybind.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,15 @@ class MrubyRef{
284284
template<>
285285
struct Type<int> {
286286
static const char TYPE_NAME[];
287-
static int check(mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
287+
static int check(mrb_state*, mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
288288
static int get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_fixnum_p(v) ? mrb_fixnum(v) : mrb_float(v); }
289289
static mrb_value ret(mrb_state*, int i) { return mrb_fixnum_value(i); }
290290
};
291291

292292
template<>
293293
struct Type<unsigned int> {
294294
static const char TYPE_NAME[];
295-
static int check(mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
295+
static int check(mrb_state*, mrb_value v) { return mrb_fixnum_p(v) || mrb_float_p(v); }
296296
static unsigned int get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_fixnum_p(v) ? mrb_fixnum(v) : mrb_float(v); }
297297
static mrb_value ret(mrb_state*, unsigned int i) { return mrb_fixnum_value(i); }
298298
};
@@ -301,7 +301,7 @@ struct Type<unsigned int> {
301301
template<>
302302
struct Type<float> {
303303
static const char TYPE_NAME[];
304-
static int check(mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
304+
static int check(mrb_state*, mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
305305
static float get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_float_p(v) ? mrb_float(v) : mrb_fixnum(v); }
306306
static mrb_value ret(mrb_state* mrb, float f) { return mrb_float_value(mrb, f); }
307307
};
@@ -310,7 +310,7 @@ struct Type<float> {
310310
template<>
311311
struct Type<double> {
312312
static const char TYPE_NAME[];
313-
static int check(mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
313+
static int check(mrb_state*, mrb_value v) { return mrb_float_p(v) || mrb_fixnum_p(v); }
314314
static double get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_float_p(v) ? mrb_float(v) : mrb_fixnum(v); }
315315
static mrb_value ret(mrb_state* mrb, double f) { return mrb_float_value(mrb, f); }
316316
};
@@ -319,31 +319,31 @@ struct Type<double> {
319319
template<>
320320
struct Type<const char*> {
321321
static const char TYPE_NAME[];
322-
static int check(mrb_value v) { return mrb_string_p(v); }
322+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
323323
static const char* get(mrb_state* mrb, mrb_value v) { (void)mrb; return RSTRING_PTR(v); }
324324
static mrb_value ret(mrb_state* mrb, const char* s) { return mrb_str_new_cstr(mrb, s); }
325325
};
326326

327327
template<>
328328
struct Type<std::string> {
329329
static const char TYPE_NAME[];
330-
static int check(mrb_value v) { return mrb_string_p(v); }
330+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
331331
static const std::string get(mrb_state* mrb, mrb_value v) { (void)mrb; return std::string(RSTRING_PTR(v), RSTRING_LEN(v)); }
332332
static mrb_value ret(mrb_state* mrb, const std::string& s) { return mrb_str_new(mrb, s.c_str(), s.size()); }
333333
};
334334

335335
template<>
336336
struct Type<const std::string> {
337337
static const char TYPE_NAME[];
338-
static int check(mrb_value v) { return mrb_string_p(v); }
338+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
339339
static const std::string get(mrb_state* mrb, mrb_value v) { (void)mrb; return std::string(RSTRING_PTR(v), RSTRING_LEN(v)); }
340340
static mrb_value ret(mrb_state* mrb, const std::string& s) { return mrb_str_new(mrb, s.c_str(), s.size()); }
341341
};
342342

343343
template<>
344344
struct Type<const std::string&> {
345345
static const char TYPE_NAME[];
346-
static int check(mrb_value v) { return mrb_string_p(v); }
346+
static int check(mrb_state*, mrb_value v) { return mrb_string_p(v); }
347347
static const std::string get(mrb_state* mrb, mrb_value v) { (void)mrb; return std::string(RSTRING_PTR(v), RSTRING_LEN(v)); }
348348
static mrb_value ret(mrb_state* mrb, const std::string& s) { return mrb_str_new(mrb, s.c_str(), s.size()); }
349349
};
@@ -352,7 +352,7 @@ struct Type<const std::string&> {
352352
template<>
353353
struct Type<bool> {
354354
static const char TYPE_NAME[];
355-
static int check(mrb_value /*v*/) { return 1; }
355+
static int check(mrb_state*, mrb_value /*v*/) { return 1; }
356356
static bool get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_test(v); }
357357
static mrb_value ret(mrb_state* /*mrb*/, bool b) { return b ? mrb_true_value() : mrb_false_value(); }
358358
};
@@ -361,7 +361,7 @@ struct Type<bool> {
361361
template<>
362362
struct Type<void*> {
363363
static const char TYPE_NAME[];
364-
static int check(mrb_value v) { return mrb_voidp_p(v); }
364+
static int check(mrb_state*, mrb_value v) { return mrb_voidp_p(v); }
365365
static void* get(mrb_state* mrb, mrb_value v) { (void)mrb; return mrb_voidp(v); }
366366
static mrb_value ret(mrb_state* mrb, void* p) { return mrb_voidp_value(mrb, p); }
367367
};
@@ -373,7 +373,7 @@ struct TypeFuncBase{
373373

374374
template<class R>
375375
struct Type<FuncPtr<R()> > :public TypeFuncBase {
376-
static int check(mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
376+
static int check(mrb_state*, mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
377377
static FuncPtr<R()> get(mrb_state* mrb, mrb_value v) {
378378
Deleter<std::function<R()> > d = set_avoid_gc<std::function<R()> >(mrb, v);
379379
return make_FuncPtr<R()>(d, [=](){
@@ -390,7 +390,7 @@ struct Type<FuncPtr<R()> > :public TypeFuncBase {
390390

391391
template<>
392392
struct Type<FuncPtr<void()> > :public TypeFuncBase {
393-
static int check(mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
393+
static int check(mrb_state*, mrb_value v) { return mrb_type(v) == MRB_TT_PROC; }
394394
static FuncPtr<void()> get(mrb_state* mrb, mrb_value v) {
395395
Deleter<std::function<void()> > d = set_avoid_gc<std::function<void()> >(mrb, v);
396396
return make_FuncPtr<void()>(d, [=](){
@@ -409,7 +409,7 @@ struct Type<FuncPtr<void()> > :public TypeFuncBase {
409409
template<>
410410
struct Type<MrubyRef> {
411411
static const char TYPE_NAME[];
412-
static int check(mrb_value) { return 1; }
412+
static int check(mrb_state*, mrb_value) { return 1; }
413413
static MrubyRef get(mrb_state* mrb, mrb_value v) { (void)mrb; return MrubyRef(mrb, v); }
414414
static mrb_value ret(mrb_state*, MrubyRef r) { return r.get_v(); }
415415
};
@@ -451,8 +451,8 @@ struct TypeClassBase{
451451

452452
template<class T> struct Type :public TypeClassBase {
453453
static std::string class_name;
454-
static int check(mrb_value v) {
455-
return mrb_type(v) == MRB_TT_DATA;
454+
static int check(mrb_state* mrb, mrb_value v) {
455+
return mrb_type(v) == MRB_TT_DATA && strcmp(mrb_obj_classname(mrb, v), class_name.c_str()) == 0;
456456
}
457457
static T get(mrb_state* mrb, mrb_value v) {
458458
(void)mrb; return *(T*)DATA_PTR(v);
@@ -480,7 +480,7 @@ mrb_value raise(mrb_state *mrb, int parameter_index,
480480
//#include "mrubybind.inc"
481481
// This file is generated from gen_template.rb
482482
#define ARG(mrb, i) Type<P##i>::get(mrb, args[i])
483-
#define CHECK(i) {if(!Type<P##i>::check(args[i])) return RAISE(i);}
483+
#define CHECK(i) {if(!Type<P##i>::check(mrb, args[i])) return RAISE(i);}
484484
#define RAISE(i) raise(mrb, i, Type<P##i>::TYPE_NAME, args[i])
485485

486486
// void f(void);

mrubybind_call_generated.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is generated from gen_template.rb
22
#define ARG(mrb, i) Type<P##i>::get(mrb, args[i])
3-
#define CHECK(i) {if(!Type<P##i>::check(args[i])) return RAISE(i);}
3+
#define CHECK(i) {if(!Type<P##i>::check(mrb, args[i])) return RAISE(i);}
44
#define RAISE(i) raise(mrb, i, Type<P##i>::TYPE_NAME, args[i])
55

66

0 commit comments

Comments
 (0)