ruby-changes:31384
From: ko1 <ko1@a...>
Date: Tue, 29 Oct 2013 18:42:52 +0900 (JST)
Subject: [ruby-changes:31384] ko1:r43463 (trunk): * include/ruby/ruby.h: introduce new flags for T_TYPEDDATA.
ko1 2013-10-29 18:42:45 +0900 (Tue, 29 Oct 2013) New Revision: 43463 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43463 Log: * include/ruby/ruby.h: introduce new flags for T_TYPEDDATA. * RUBY_TYPED_FREE_IMMEDIATELY: free the data given by DATA_PTR() with dfree function immediately. Otherwise (default), the data freed at finalizaton point. * RUBY_TYPED_WB_PROTECTED: make this object with FL_WB_PROTECT (not shady). * gc.c (obj_free): support RUBY_TYPED_FREE_IMMEDIATELY. Modified files: trunk/ChangeLog trunk/gc.c trunk/include/ruby/ruby.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 43462) +++ include/ruby/ruby.h (revision 43463) @@ -1008,6 +1008,10 @@ void *rb_check_typeddata(VALUE, const rb https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1008 #define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE #define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE +/* bits for rb_data_type_struct::flags */ +#define RUBY_TYPED_FREE_IMMEDIATELY 1 /* TYPE field */ +#define RUBY_TYPED_WB_PROTECTED FL_WB_PROTECT + #define Data_Wrap_Struct(klass,mark,free,sval)\ rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free)) Index: ChangeLog =================================================================== --- ChangeLog (revision 43462) +++ ChangeLog (revision 43463) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Oct 29 18:37:33 2013 Koichi Sasada <ko1@a...> + + * include/ruby/ruby.h: introduce new flags for T_TYPEDDATA. + * RUBY_TYPED_FREE_IMMEDIATELY: free the data given by DATA_PTR() + with dfree function immediately. Otherwise (default), the data + freed at finalizaton point. + * RUBY_TYPED_WB_PROTECTED: make this object with FL_WB_PROTECT + (not shady). + + * gc.c (obj_free): support RUBY_TYPED_FREE_IMMEDIATELY. + Tue Oct 29 16:49:03 2013 Koichi Sasada <ko1@a...> * gc.c (vm_malloc_increase): decrease it more carefully. Index: gc.c =================================================================== --- gc.c (revision 43462) +++ gc.c (revision 43463) @@ -1196,7 +1196,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L1196 rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *type) { if (klass) Check_Type(klass, T_CLASS); - return newobj_of(klass, T_DATA | type->flags, (VALUE)type, (VALUE)1, (VALUE)datap); + return newobj_of(klass, T_DATA | (type->flags & ~T_MASK), (VALUE)type, (VALUE)1, (VALUE)datap); } size_t @@ -1373,15 +1373,23 @@ obj_free(rb_objspace_t *objspace, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L1373 break; case T_DATA: if (DATA_PTR(obj)) { + int free_immediately = 0; + if (RTYPEDDATA_P(obj)) { + free_immediately = RANY(obj)->as.typeddata.type->flags & RUBY_TYPED_FREE_IMMEDIATELY; RDATA(obj)->dfree = RANY(obj)->as.typeddata.type->function.dfree; } - if (RANY(obj)->as.data.dfree == (RUBY_DATA_FUNC)-1) { + if (RANY(obj)->as.data.dfree == RUBY_DEFAULT_FREE) { xfree(DATA_PTR(obj)); } else if (RANY(obj)->as.data.dfree) { - make_deferred(RANY(obj)); - return 1; + if (free_immediately) { + (RDATA(obj)->dfree)(DATA_PTR(obj)); + } + else { + make_deferred(RANY(obj)); + return 1; + } } } break; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/