Skip to content

Instantly share code, notes, and snippets.

@sbryant
Created March 25, 2010 21:07
Show Gist options
  • Save sbryant/344122 to your computer and use it in GitHub Desktop.
Save sbryant/344122 to your computer and use it in GitHub Desktop.
From c1b2240dde8c3bc214cc41705579f66bd97dec2b Mon Sep 17 00:00:00 2001
From: Sean Bryant <sean@hackinggibsons.com>
Date: Thu, 25 Mar 2010 17:02:46 -0400
Subject: [PATCH] finish implemented frozen semantics for capi layer
---
vm/capi/object.cpp | 23 ++++++++++++++++++++---
vm/capi/ruby.h | 6 ++++++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/vm/capi/object.cpp b/vm/capi/object.cpp
index b413e40..7a783f6 100644
--- a/vm/capi/object.cpp
+++ b/vm/capi/object.cpp
@@ -11,8 +11,27 @@ using namespace rubinius;
using namespace rubinius::capi;
extern "C" {
+
+ void rb_error_frozen(const char* what) {
+ rb_raise(rb_eTypeError, "can't modify frozen %s", what);
+ }
+
+ VALUE rb_obj_frozen_p(VALUE obj) {
+ NativeMethodEnvironment* env = NativeMethodEnvironment::get();
+ if(env->get_object(obj)->frozen_p(env->state()) == RBX_Qtrue) {
+ return Qtrue;
+ }
+
+ return Qfalse;
+ }
+
void rb_check_frozen(VALUE obj_handle) {
/* @todo implement when rbx supports frozen objects. */
+ if(rb_obj_frozen_p(obj_handle)){
+ char *class_name = rb_obj_classname(obj_handle);
+ rb_error_frozen((const char*)class_name);
+ free(class_name);
+ }
}
VALUE rb_obj_freeze(VALUE hndl) {
@@ -284,9 +303,7 @@ extern "C" {
VALUE rb_obj_taint(VALUE obj) {
if(!OBJ_TAINTED(obj)) {
- //if(OBJ_FROZEN(obj)) {
- //rb_error_frozen("object");
- //}
+ rb_check_frozen(obj);
OBJ_TAINT(obj);
}
diff --git a/vm/capi/ruby.h b/vm/capi/ruby.h
index b0bbab7..4093a51 100644
--- a/vm/capi/ruby.h
+++ b/vm/capi/ruby.h
@@ -803,6 +803,12 @@ double rb_num2dbl(VALUE);
/** Raises an exception if obj_handle is frozen. */
void rb_check_frozen(VALUE obj_handle);
+ /** check if obj_handle is frozen. */
+ int rb_obj_frozen_p(VALUE obj);
+
+ /** raise error on class */
+ void rb_error_frozen(const char* what);
+
/** Raises an exception if obj_handle is not the same type as 'type'. */
void rb_check_type(VALUE obj_handle, CApiType type);
--
1.6.1.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment