[macruby-changes] [2277] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 11 11:16:11 PDT 2009
Revision: 2277
http://trac.macosforge.org/projects/ruby/changeset/2277
Author: pthomson at apple.com
Date: 2009-08-11 11:16:09 -0700 (Tue, 11 Aug 2009)
Log Message:
-----------
Implemented Object#trust, Object#untrust, and Object#untrusted? and enabled their specs.
Modified Paths:
--------------
MacRuby/trunk/include/ruby/ruby.h
MacRuby/trunk/object.c
Removed Paths:
-------------
MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/trust_tags.txt
MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrust_tags.txt
MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrusted_tags.txt
Modified: MacRuby/trunk/include/ruby/ruby.h
===================================================================
--- MacRuby/trunk/include/ruby/ruby.h 2009-08-11 17:29:48 UTC (rev 2276)
+++ MacRuby/trunk/include/ruby/ruby.h 2009-08-11 18:16:09 UTC (rev 2277)
@@ -823,10 +823,11 @@
#define FL_RESERVED (((VALUE)1)<<6) /* will be used in the future GC */
#define FL_FINALIZE (((VALUE)1)<<7)
#define FL_TAINT (((VALUE)1)<<8)
-#define FL_EXIVAR (((VALUE)1)<<9)
-#define FL_FREEZE (((VALUE)1)<<10)
+#define FL_UNTRUSTED (((VALUE)1)<<9)
+#define FL_EXIVAR (((VALUE)1)<<10)
+#define FL_FREEZE (((VALUE)1)<<11)
-#define FL_USHIFT 11
+#define FL_USHIFT 12
#define FL_USER0 (((VALUE)1)<<(FL_USHIFT+0))
#define FL_USER1 (((VALUE)1)<<(FL_USHIFT+1))
@@ -863,9 +864,13 @@
#if WITH_OBJC
# define OBJ_TAINTED(x) (int)(SPECIAL_CONST_P(x) || NATIVE(x) ? rb_obj_tainted((VALUE)x) == Qtrue : FL_TEST((x), FL_TAINT))
# define OBJ_TAINT(x) (rb_obj_taint((VALUE)x))
+# define OBJ_UNTRUSTED(x) (int)(SPECIAL_CONST_P(x) || NATIVE(x) ? rb_obj_tainted((VALUE)x) == Qtrue : FL_TEST((x), FL_TAINT)
+# define OBJ_UNTRUST(x) (rb_obj_untrust((VALUE)x))
#else
# define OBJ_TAINTED(x) FL_TEST((x), FL_TAINT)
# define OBJ_TAINT(x) FL_SET((x), FL_TAINT)
+# define OBJ_UNTRUSTED(x) (FL_TEST((x), FL_UNTRUSTED))
+# define OBJ_UNTRUST(x) FL_SET((x), FL_UNTRUSTED)
#endif
#define OBJ_INFECT(x,s) do {if (FL_ABLE(x) && FL_ABLE(s)) RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT;} while (0)
Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c 2009-08-11 17:29:48 UTC (rev 2276)
+++ MacRuby/trunk/object.c 2009-08-11 18:16:09 UTC (rev 2277)
@@ -906,6 +906,128 @@
return rb_obj_untaint_m(obj, 0);
}
+static VALUE
+rb_obj_untrusted_imp(VALUE obj, SEL sel)
+{
+ if (!SPECIAL_CONST_P(obj) && NATIVE(obj)) {
+ switch (TYPE(obj)) {
+ case T_ARRAY:
+ if (*(VALUE *)obj != rb_cCFArray) {
+ return RBASIC(obj)->flags & FL_UNTRUSTED ? Qtrue : Qfalse;
+ }
+// fall through
+ case T_STRING:
+ if (*(VALUE *)obj == rb_cByteString) {
+ return rb_objc_flag_check((const void *)obj, FL_UNTRUSTED)
+ ? Qtrue : Qfalse;
+ }
+// fall through
+ case T_HASH:
+#ifdef __LP64__
+ return (RCLASS_RC_FLAGS(obj) & FL_UNTRUSTED) == FL_UNTRUSTED ? Qtrue : Qfalse;
+#endif
+ default:
+ return rb_objc_flag_check((const void *)obj, FL_UNTRUSTED) ? Qtrue : Qfalse;
+ }
+ }
+ if (FL_TEST(obj, FL_UNTRUSTED)) {
+ return Qtrue;
+ }
+ return Qfalse;
+}
+
+VALUE
+rb_obj_untrusted(VALUE obj)
+{
+ return rb_obj_untrusted_imp(obj, 0);
+}
+
+static VALUE
+rb_obj_trust_imp(VALUE obj, SEL sel)
+{
+ rb_secure(4);
+ if (!SPECIAL_CONST_P(obj) && NATIVE(obj)) {
+ switch (TYPE(obj)) {
+ case T_ARRAY:
+ if (*(VALUE *)obj != rb_cCFArray) {
+ RBASIC(obj)->flags &= ~FL_UNTRUSTED;
+ break;
+ }
+ // fall through
+ case T_STRING:
+ if (*(VALUE *)obj == rb_cByteString) {
+ rb_objc_flag_set((const void *)obj, FL_UNTRUSTED, false);
+ break;
+ }
+ // fall through
+ case T_HASH:
+#ifdef __LP64__
+ RCLASS_RC_FLAGS(obj) &= ~FL_UNTRUSTED;
+ break;
+#endif
+ default:
+ rb_objc_flag_set((const void *)obj, FL_UNTRUSTED, false);
+ }
+ return obj;
+ }
+ if (!OBJ_TAINTED(obj)) {
+ if (OBJ_FROZEN(obj)) {
+ rb_error_frozen("object");
+ }
+ FL_UNSET(obj, FL_UNTRUSTED);
+ }
+ return obj;
+}
+
+VALUE
+rb_obj_trust(VALUE obj)
+{
+ return rb_obj_trust_imp(obj, 0);
+}
+
+static VALUE
+rb_obj_untrust_imp(VALUE obj, SEL sel)
+{
+ rb_secure(4);
+ if (!SPECIAL_CONST_P(obj) && NATIVE(obj)) {
+ switch (TYPE(obj)) {
+ case T_ARRAY:
+ if (*(VALUE *)obj != rb_cCFArray) {
+ RBASIC(obj)->flags |= FL_UNTRUSTED;
+ break;
+ }
+ // fall through
+ case T_STRING:
+ if (*(VALUE *)obj == rb_cByteString) {
+ rb_objc_flag_set((const void *)obj, FL_UNTRUSTED, true);
+ break;
+ }
+ // fall through
+ case T_HASH:
+#ifdef __LP64__
+ RCLASS_RC_FLAGS(obj) |= FL_UNTRUSTED;
+ break;
+#endif
+ default:
+ rb_objc_flag_set((const void *)obj, FL_UNTRUSTED, true);
+ }
+ return obj;
+ }
+ if (!OBJ_TAINTED(obj)) {
+ if (OBJ_FROZEN(obj)) {
+ rb_error_frozen("object");
+ }
+ FL_SET(obj, FL_UNTRUSTED);
+ }
+ return obj;
+}
+
+VALUE
+rb_obj_untrust(VALUE obj)
+{
+ return rb_obj_untrust_imp(obj, 0);
+}
+
void
rb_obj_infect(VALUE obj1, VALUE obj2)
{
@@ -2791,6 +2913,9 @@
rb_objc_define_method(rb_mKernel, "untaint", rb_obj_untaint_m, 0);
rb_objc_define_method(rb_mKernel, "freeze", rb_obj_freeze_m, 0);
rb_objc_define_method(rb_mKernel, "frozen?", rb_obj_frozen, 0);
+ rb_objc_define_method(rb_mKernel, "trust", rb_obj_trust_imp, 0);
+ rb_objc_define_method(rb_mKernel, "untrust", rb_obj_untrust_imp, 0);
+ rb_objc_define_method(rb_mKernel, "untrusted?", rb_obj_untrusted_imp, 0);
rb_objc_define_method(rb_mKernel, "to_s", rb_any_to_string, 0);
rb_objc_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0);
Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/trust_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/trust_tags.txt 2009-08-11 17:29:48 UTC (rev 2276)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/trust_tags.txt 2009-08-11 18:16:09 UTC (rev 2277)
@@ -1,2 +0,0 @@
-fails:Kernel#trust clears the untrusted bit from a target object
-fails:Kernel#trust can not be called on frozen object
Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrust_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrust_tags.txt 2009-08-11 17:29:48 UTC (rev 2276)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrust_tags.txt 2009-08-11 18:16:09 UTC (rev 2277)
@@ -1,2 +0,0 @@
-fails:Kernel#untrusted? sets the untrusted bit on a target object
-fails:Kernel#untrusted? can not be called on frozen object
Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrusted_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrusted_tags.txt 2009-08-11 17:29:48 UTC (rev 2276)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/kernel/untrusted_tags.txt 2009-08-11 18:16:09 UTC (rev 2277)
@@ -1,2 +0,0 @@
-fails:Kernel#untrusted? returns the untrusted status of an object
-fails:Kernel#untrusted? has no effect on immediate values
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090811/1ae90ab0/attachment.html>
More information about the macruby-changes
mailing list