Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
From a2bd5282063ecd961145948acbaf29b0982058dd Mon Sep 17 00:00:00 2001 From: Sean Bryant <sean@hackinggibsons.com> Date: Fri, 6 Jun 2008 19:23:07 -0400 Subject: [PATCH] This gets hpricot to compile and install, though currently when it tries to call rb_define_attr it freaks out and segfaults the VM. Still trying to work through this mess. Evan pointed out to me you cannot use HNDL on an ID. This was all over the place, as well as explicit object casts, I removed them (maybe that caused this?) --- rakelib/configure.rake | 13 +++++++- shotgun/lib/subtend/ruby.c | 70 +++++++++++++++++++++++++++++++++++++------ shotgun/lib/subtend/ruby.h | 13 +++++++- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/rakelib/configure.rake b/rakelib/configure.rake index db56213..9168e6b 100644 --- a/rakelib/configure.rake +++ b/rakelib/configure.rake @@ -279,7 +279,11 @@ def write_rbconfig f.puts ' CONFIG["LIBRUBYARG_SHARED"] = "-l$(RUBY_SO_NAME)"' f.puts ' CONFIG["configure_args"] = ""' f.puts ' CONFIG["ALLOCA"] = ""' + if HOST =~ /darwin/ then f.puts ' CONFIG["DLEXT"] = "bundle"' + else + f.puts ' CONFIG["DLEXT"] = "so"' + end f.puts ' CONFIG["LIBEXT"] = "a"' f.puts ' CONFIG["LINK_SO"] = ""' f.puts ' CONFIG["LIBPATHFLAG"] = " -L%s"' @@ -296,8 +300,13 @@ def write_rbconfig f.puts ' CONFIG["PACKAGE_BUGREPORT"] = ""' # HACK: we need something equivalent, but I'm cheating for now - zenspider - f.puts ' CONFIG["LDSHARED"] = "cc -dynamic -bundle -undefined suppress -flat_namespace"' - f.puts ' CONFIG["LIBRUBY_LDSHARED"] = "cc -dynamic -bundle -undefined suppress -flat_namespace"' + if HOST =~ /darwin/ then + f.puts ' CONFIG["LDSHARED"] = "cc -dynamic -bundle -undefined suppress -flat_namespace"' + f.puts ' CONFIG["LIBRUBY_LDSHARED"] = "cc -dynamic -bundle -undefined suppress -flat_namespace"' + else + f.puts ' CONFIG["LDSHARED"] = "cc -dynamic -shared"' + f.puts ' CONFIG["LIBRUBY_LDSHARED"] = "cc -dynamic -shared"' + end f.puts f.puts <<-EOC # Adapted from MRI's' rbconfig.rb diff --git a/shotgun/lib/subtend/ruby.c b/shotgun/lib/subtend/ruby.c index 0b0917c..26a2335 100644 --- a/shotgun/lib/subtend/ruby.c +++ b/shotgun/lib/subtend/ruby.c @@ -142,6 +142,16 @@ VALUE subtend_get_global(int which) { return NEW_HANDLE(ctx, val); } +void subtend_set_tainted(VALUE val) { + CTX; + object_set_tainted(ctx->state, HNDL(val)); +} + +int subtend_check_tainted(VALUE val) { + CTX; + return object_tainted_p(ctx->state, HNDL(val)); +} + void rb_global_object(VALUE val) { handle_make_global(AS_HNDL(val)); } @@ -161,7 +171,6 @@ void rb_free_global(VALUE val) { /* Functions for calling methods or object. */ static VALUE _push_and_call(VALUE recv, ID meth, int args, VALUE *ary) { - rni_context *ctx; rni_nmc *n; int i; /* This has to be volatile so that gcc doesn't optimize @@ -169,8 +178,10 @@ static VALUE _push_and_call(VALUE recv, ID meth, int args, VALUE *ary) { properly. */ volatile int swapped; OBJECT tmp; - ctx = subtend_retrieve_context(); - + /* ctx = subtend_retrieve_context(); */ + CTX; + + if(!ctx->nmc) { printf("ERROR: tried to do rb_funcall, but there is no context!\n"); return 0; @@ -183,9 +194,8 @@ static VALUE _push_and_call(VALUE recv, ID meth, int args, VALUE *ary) { } n = ctx->nmc; - - n->value = AS_HNDL(recv); - n->symbol = (OBJECT)meth; + n->value = recv; + n->symbol = ID2SYM(meth); n->args = args; n->jump_val = CALL_METHOD; @@ -264,7 +274,7 @@ void rb_include_module(VALUE klass, VALUE module) { VALUE rb_const_get(VALUE klass, ID id) { CTX; - return NEW_HANDLE(ctx, cpu_const_get(ctx->state, ctx->cpu, (OBJECT)id, HNDL(klass))); + return NEW_HANDLE(ctx, cpu_const_get(ctx->state, ctx->cpu, (OBJECT)ID2SYM(id), HNDL(klass))); } void rb_define_const(VALUE klass, const char* key, VALUE val) { @@ -281,7 +291,7 @@ VALUE rb_ivar_get(VALUE obj, ID sym) { CTX; OBJECT val; - val = object_get_ivar(ctx->state, HNDL(obj), HNDL(sym)); + val = object_get_ivar(ctx->state, HNDL(obj), ID2SYM(sym)); return NEW_HANDLE(ctx, val); } @@ -302,7 +312,7 @@ VALUE rb_iv_get(VALUE obj, char *name) { VALUE rb_ivar_set(VALUE obj, ID sym, VALUE val) { CTX; - object_set_ivar(ctx->state, HNDL(obj), HNDL(sym), HNDL(val)); + object_set_ivar(ctx->state, HNDL(obj), ID2SYM(sym), HNDL(val)); return val; } @@ -311,6 +321,20 @@ VALUE rb_iv_set(VALUE obj, char *name, VALUE val) { return rb_ivar_set(obj, rb_intern(name), val); } + +VALUE rb_ivar_defined(VALUE obj, ID sym) { + CTX; + + if(object_has_ivars(ctx->state, HNDL(obj))) { + if (object_get_ivar(ctx->state, HNDL(obj), ID2SYM(sym)) != Qundef) { + return Qtrue; + } + } + + return Qfalse; +} + + void rb_define_method_(const char *file, VALUE vmod, const char *name, void *func, int args, int kind) { OBJECT meth, sym, mod; CTX; @@ -349,7 +373,7 @@ const char *rb_id2name(ID sym) { OBJECT obj; CTX; - obj = (OBJECT)sym; + obj = (OBJECT)ID2SYM(sym); if(!RBX_SYMBOL_P(obj)) return NULL; return rbs_symbol_to_cstring(ctx->state, obj); } @@ -469,6 +493,14 @@ VALUE rb_class_new_instance(int nargs, VALUE *args, VALUE klass) { return obj; } +VALUE rb_singleton_class(VALUE obj) { + OBJECT val; + CTX; + + val = object_metaclass(ctx->state, HNDL(obj)); + return NEW_HANDLE(ctx, val); +} + void rb_thread_schedule() { rb_funcall2(rb_const_get(rb_cObject, rb_intern("Thread")), rb_intern("pass"), 0, NULL); } @@ -526,6 +558,24 @@ VALUE rb_ary_new2(long length) { return NEW_HANDLE(ctx, ary); } +VALUE rb_ary_new3(long length, ...) { + OBJECT ary; + CTX; + + va_list ar; + long i; + + ary = array_new(ctx->state, length); + + va_start(ar, length); + for(i = 0; i < length; i++) { + array_append(ctx->state, ary, HNDL(va_arg(ar, VALUE))); + } + va_end(ar); + + return NEW_HANDLE(ctx, ary); +} + VALUE rb_ary_push(VALUE array, VALUE val) { CTX; OBJECT ary = HNDL(array); diff --git a/shotgun/lib/subtend/ruby.h b/shotgun/lib/subtend/ruby.h index eb9eea6..5587a1e 100644 --- a/shotgun/lib/subtend/ruby.h +++ b/shotgun/lib/subtend/ruby.h @@ -28,6 +28,10 @@ #define Qnil ((VALUE)14L) #define Qundef ((VALUE)18L) +/* NOOP for OBJ_TAINT and OBJ_TAINTED */ +#define OBJ_TAINT(val) (subtend_set_tainted(val)) +#define OBJ_TAINTED(val) (subtend_check_tainted(val)) + #undef RTEST #undef NIL_P #define RTEST(v) (((uintptr_t)(v) & 0x7) != 0x6) @@ -45,10 +49,12 @@ int SYMBOL_P(VALUE obj); extern VALUE rb_funcall(VALUE, ID, int cnt, ...); extern VALUE rb_funcall2(VALUE, ID, int cnt, VALUE*); - extern VALUE subtend_get_global(int which); extern VALUE subtend_get_exception(int which); +void subtend_set_tainted(VALUE val); +int subtend_check_tainted(VALUE val); + void rb_global_variable(VALUE* address); void rb_define_method_(const char *file, VALUE vmod, const char *name, void *func, int args, int kind); @@ -76,6 +82,8 @@ VALUE rb_ivar_get(VALUE obj, ID sym); VALUE rb_iv_get(VALUE obj, char *name); VALUE rb_ivar_set(VALUE obj, ID sym, VALUE val); VALUE rb_iv_set(VALUE obj, char *name, VALUE val); +VALUE rb_ivar_defined(VALUE obj, ID sym); + void rb_define_attr(VALUE klass, const char* id, int read, int write); VALUE rb_attr_get(VALUE obj, ID sym); @@ -168,6 +176,8 @@ VALUE rb_convert_type(VALUE val, int type, const char* tname, const char* method VALUE rb_class_new_instance(int nargs, VALUE *args, VALUE klass); +VALUE rb_singleton_class(VALUE obj); + void rb_thread_schedule(); #define CHECK_INTS void rb_secure(int); @@ -184,6 +194,7 @@ VALUE INT2NUM(int num); VALUE rb_Array(VALUE val); VALUE rb_ary_new(void); VALUE rb_ary_new2(long length); +VALUE rb_ary_new3(long length, ...); int rb_ary_size(VALUE self); VALUE rb_ary_push(VALUE array, VALUE val); VALUE rb_ary_pop(VALUE array); -- 1.5.4.3
This paste will be private.
From the Design Piracy series on my blog: