From dc23d7fffe6f3b3a6581a88040833aa540d77e79 Mon Sep 17 00:00:00 2001 From: Bence Monus Date: Wed, 6 Feb 2019 20:46:02 +0000 Subject: [PATCH 1/3] mrb_ary_len was replaced with a macro that needs a wrapper --- array.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/array.go b/array.go index 60e3a56..f6a0116 100644 --- a/array.go +++ b/array.go @@ -1,6 +1,7 @@ package mruby // #include "gomruby.h" +// mrb_int _mrb_ary_len(mrb_value ary) { return RARRAY_LEN(ary); } import "C" // Array represents an MrbValue that is a Array in Ruby. @@ -12,7 +13,7 @@ type Array struct { // Len returns the length of the array. func (v *Array) Len() int { - return int(C.mrb_ary_len(v.state, v.value)) + return int(C._mrb_ary_len(v.value)) } // Get gets an element form the Array by index. From 964cfb0c28d7e8e96ed1e77f4aa4f63d092ae209 Mon Sep 17 00:00:00 2001 From: Bence Monus Date: Wed, 6 Feb 2019 21:30:33 +0000 Subject: [PATCH 2/3] update code with RProc struct changes proc.e is now a union type and the only way to assign values to it is by converting the raw data to a fixed size byte array. --- func.go | 2 +- value.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/func.go b/func.go index 57991ef..dac1aa4 100644 --- a/func.go +++ b/func.go @@ -63,7 +63,7 @@ func goMRBFuncCall(s *C.mrb_state, v C.mrb_value) C.mrb_value { // Lookup the class itself classTable.Mutex.Lock() - methodTable := classTable.Map[ci.proc.target_class] + methodTable := classTable.Map[ci.target_class] classTable.Mutex.Unlock() if methodTable == nil { panic(fmt.Sprintf("func call on unknown class")) diff --git a/value.go b/value.go index dd6af23..7a4d3d7 100644 --- a/value.go +++ b/value.go @@ -139,7 +139,7 @@ func (v *MrbValue) GCProtect() { // when this value is a proc. func (v *MrbValue) SetProcTargetClass(c *Class) { proc := C._go_mrb_proc_ptr(v.value) - proc.target_class = c.class + proc.e = *(*[8]byte)(unsafe.Pointer(&c.class)) } // Type returns the ValueType of the MrbValue. See the constants table. From 993c7a2b2dc1a4269d7c650b85764379ed1015fd Mon Sep 17 00:00:00 2001 From: Bence Monus Date: Thu, 7 Feb 2019 10:09:27 +0000 Subject: [PATCH 3/3] C code in go files is bad. --- array.go | 1 - gomruby.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/array.go b/array.go index f6a0116..bdc02fa 100644 --- a/array.go +++ b/array.go @@ -1,7 +1,6 @@ package mruby // #include "gomruby.h" -// mrb_int _mrb_ary_len(mrb_value ary) { return RARRAY_LEN(ary); } import "C" // Array represents an MrbValue that is a Array in Ruby. diff --git a/gomruby.h b/gomruby.h index 2319a93..3272957 100644 --- a/gomruby.h +++ b/gomruby.h @@ -268,4 +268,8 @@ static inline mrb_value _go_mrb_gv_get(mrb_state *m, mrb_sym sym) { return mrb_gv_get(m, sym); } +static inline mrb_int _mrb_ary_len(mrb_value ary) { + return RARRAY_LEN(ary); +} + #endif