From 66a5374e724612cd16f270f43102a6ed347208d7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 25 Dec 2010 00:58:03 -0800 Subject: add support for Rubinius RSTRUCT_PTR access is unlikely to ever happen for Rubinius, so we'll just make a method dispatch and leave the faster code for Ruby 1.8 and 1.9. --- ext/clogger_ext/clogger.c | 13 ++++++++++++- ext/clogger_ext/ruby_1_9_compat.h | 12 +++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index bc61f2a..4c3d93a 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -818,9 +818,17 @@ static VALUE clogger_init_copy(VALUE clone, VALUE orig) #define CONST_GLOBAL_STR(val) CONST_GLOBAL_STR2(val, #val) +#ifdef RSTRUCT_PTR +# define ToPath_clogger(tp) RSTRUCT_PTR(tp)[0] +#else +static ID clogger_id; +# define ToPath_clogger(tp) rb_funcall(tp,clogger_id,0) +#endif + static VALUE to_path(VALUE self) { - struct clogger *c = clogger_get(RSTRUCT_PTR(self)[0]); + VALUE my_clogger = ToPath_clogger(self); + struct clogger *c = clogger_get(my_clogger); VALUE path = rb_funcall(c->body, to_path_id, 0); struct stat sb; int rv; @@ -897,4 +905,7 @@ void Init_clogger_ext(void) cHeaderHash = rb_const_get(tmp, rb_intern("HeaderHash")); cToPath = rb_const_get(cClogger, rb_intern("ToPath")); rb_define_method(cToPath, "to_path", to_path, 0); +#ifndef RSTRUCT_PTR + clogger_id = rb_intern("clogger"); +#endif } diff --git a/ext/clogger_ext/ruby_1_9_compat.h b/ext/clogger_ext/ruby_1_9_compat.h index b6caa96..ef103e4 100644 --- a/ext/clogger_ext/ruby_1_9_compat.h +++ b/ext/clogger_ext/ruby_1_9_compat.h @@ -11,11 +11,13 @@ #ifndef RARRAY_LEN # define RARRAY_LEN(s) (RARRAY(s)->len) #endif -#ifndef RSTRUCT_PTR -# define RSTRUCT_PTR(s) (RSTRUCT(s)->ptr) -#endif -#ifndef RSTRUCT_LEN -# define RSTRUCT_LEN(s) (RSTRUCT(s)->len) +#ifndef RUBINIUS +# ifndef RSTRUCT_PTR +# define RSTRUCT_PTR(s) (RSTRUCT(s)->ptr) +# endif +# ifndef RSTRUCT_LEN +# define RSTRUCT_LEN(s) (RSTRUCT(s)->len) +# endif #endif #ifndef HAVE_RB_STR_SET_LEN -- cgit v1.2.3-24-ge0c7