[MacRuby-devel] [macruby-changes] [5186] MacRuby/trunk/hash.h
Watson
watson1978 at gmail.com
Fri Jan 21 15:09:44 PST 2011
Hi Laurent,
There is only the extremely slight difference.
I think that I can ignore this.
How do you think?
I attached a patch and benchmark script.
** Result of r5185
$ macruby bm_hash.rb
Rehearsal ------------------------------------
13.640000 0.210000 13.850000 ( 9.114591)
-------------------------- total: 13.850000sec
user system total real
13.720000 0.240000 13.960000 ( 9.172110)
** Result of r5186
$ macruby bm_hash.rb
Rehearsal ------------------------------------
13.660000 0.210000 13.870000 ( 9.239979)
-------------------------- total: 13.870000sec
user system total real
13.850000 0.220000 14.070000 ( 9.412910)
** Result of appling attached patch
$ macruby bm_hash.rb
Rehearsal ------------------------------------
13.660000 0.200000 13.860000 ( 9.171733)
-------------------------- total: 13.860000sec
user system total real
13.790000 0.220000 14.010000 ( 9.271439)
2011/1/22 Laurent Sansonetti <lsansonetti at apple.com>:
> Hi Watson,
> This isn't good, rhash_modify() must be very fast, so calling OBJ_FROZEN and
> OBJ_UNTRUSTED is not good there.
> Can we look up the mask flag as before?
> Laurent
> On Jan 21, 2011, at 7:51 AM, source_changes at macosforge.org wrote:
>
> Revision 5186 Author watson1978 at gmail.com Date 2011-01-21 07:51:01 -0800
> (Fri, 21 Jan 2011)
>
> Log Message
>
> More method of Hash will throw a SecurityError when $SAFE is 4.
>
> Test Script:
> {{{
> h = {}
> $SAFE = 4
> h['a'] = 1.0
> }}}
>
> Modified Paths
>
> MacRuby/trunk/hash.h
>
> Diff
>
> Modified: MacRuby/trunk/hash.h (5185 => 5186)
>
> --- MacRuby/trunk/hash.h 2011-01-21 02:20:08 UTC (rev 5185)
> +++ MacRuby/trunk/hash.h 2011-01-21 15:51:01 UTC (rev 5186)
> @@ -41,14 +41,11 @@
> static inline void
> rhash_modify(VALUE hash)
> {
> - const long mask = RBASIC(hash)->flags;
> - if ((mask & FL_FREEZE) == FL_FREEZE) {
> - rb_raise(rb_eRuntimeError, "can't modify frozen/immutable hash");
> + if (OBJ_FROZEN(hash)) {
> + rb_error_frozen("hash");
> }
> - if ((mask & FL_TAINT) == FL_TAINT) {
> - if (rb_safe_level() >= 4) {
> - rb_raise(rb_eSecurityError, "Insecure: can't modify hash");
> - }
> + if (!OBJ_UNTRUSTED(hash) && rb_safe_level() >= 4) {
> + rb_raise(rb_eSecurityError, "Insecure: can't modify hash");
> }
> }
>
>
> _______________________________________________
> macruby-changes mailing list
> macruby-changes at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-changes
>
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
>
-------------- next part --------------
diff --git a/array.h b/array.h
index 4f44716..ef14aee 100644
--- a/array.h
+++ b/array.h
@@ -45,10 +45,11 @@ rb_klass_is_rary(VALUE klass)
static inline void
rary_modify(VALUE ary)
{
- if (OBJ_FROZEN(ary)) {
+ const long mask = RBASIC(ary)->flags;
+ if (mask & FL_FREEZE) {
rb_error_frozen("array");
}
- if (!OBJ_UNTRUSTED(ary) && rb_safe_level() >= 4) {
+ if (!(mask & FL_UNTRUSTED) && rb_vm_safe_level() >= 4) {
rb_raise(rb_eSecurityError, "Insecure: can't modify array");
}
}
diff --git a/hash.h b/hash.h
index 1283209..cf636fd 100644
--- a/hash.h
+++ b/hash.h
@@ -41,10 +41,11 @@ rb_klass_is_rhash(VALUE klass)
static inline void
rhash_modify(VALUE hash)
{
- if (OBJ_FROZEN(hash)) {
+ const long mask = RBASIC(hash)->flags;
+ if (mask & FL_FREEZE) {
rb_error_frozen("hash");
}
- if (!OBJ_UNTRUSTED(hash) && rb_safe_level() >= 4) {
+ if (!(mask & FL_UNTRUSTED) && rb_vm_safe_level() >= 4) {
rb_raise(rb_eSecurityError, "Insecure: can't modify hash");
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bm_hash.rb
Type: application/octet-stream
Size: 139 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110122/8286f411/attachment.obj>
More information about the MacRuby-devel
mailing list