ruby-changes:36137
From: suke <ko1@a...>
Date: Sat, 1 Nov 2014 06:34:37 +0900 (JST)
Subject: [ruby-changes:36137] suke:r48218 (trunk): ext/win32ole/win32ole_variant.c: use typed data.
suke 2014-11-01 06:33:51 +0900 (Sat, 01 Nov 2014) New Revision: 48218 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48218 Log: ext/win32ole/win32ole_variant.c: use typed data. Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole_variant.c Index: ChangeLog =================================================================== --- ChangeLog (revision 48217) +++ ChangeLog (revision 48218) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Nov 1 06:31:41 2014 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole_variant.c: use typed data. + Fri Oct 31 13:55:28 2014 Aaron Patterson <aaron@t...> * ext/dl/*: remove DL as it is replaced by Fiddle. Index: ext/win32ole/win32ole_variant.c =================================================================== --- ext/win32ole/win32ole_variant.c (revision 48217) +++ ext/win32ole/win32ole_variant.c (revision 48218) @@ -5,7 +5,8 @@ struct olevariantdata { https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L5 VARIANT var; }; -static void olevariant_free(struct olevariantdata *pvar); +static void olevariant_free(void *ptr); +static size_t olevariant_size(const void *ptr); static void ole_val2olevariantdata(VALUE val, VARTYPE vt, struct olevariantdata *pvar); static void ole_val2variant_err(VALUE val, VARIANT *var); static void ole_set_byref(VARIANT *realvar, VARIANT *var, VARTYPE vt); @@ -22,14 +23,27 @@ static VALUE folevariant_value(VALUE sel https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L23 static VALUE folevariant_vartype(VALUE self); static VALUE folevariant_set_value(VALUE self, VALUE val); +static const rb_data_type_t olevariant_datatype = { + "win32ole_variant", + {NULL, olevariant_free, olevariant_size,}, + NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY +}; + static void -olevariant_free(struct olevariantdata *pvar) +olevariant_free(void *ptr) { + struct olevariantdata *pvar = ptr; VariantClear(&(pvar->realvar)); VariantClear(&(pvar->var)); free(pvar); } +static size_t +olevariant_size(const void *ptr) +{ + return ptr ? sizeof(struct olevariantdata) : 0; +} + static void ole_val2olevariantdata(VALUE val, VARTYPE vt, struct olevariantdata *pvar) { @@ -245,7 +259,7 @@ folevariant_s_allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L259 struct olevariantdata *pvar; VALUE obj; ole_initialize(); - obj = Data_Make_Struct(klass,struct olevariantdata,0,olevariant_free,pvar); + obj = TypedData_Make_Struct(klass, struct olevariantdata, &olevariant_datatype, pvar); VariantInit(&(pvar->var)); VariantInit(&(pvar->realvar)); return obj; @@ -285,7 +299,7 @@ folevariant_s_array(VALUE klass, VALUE e https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L299 Check_Type(elems, T_ARRAY); obj = folevariant_s_allocate(klass); - Data_Get_Struct(obj, struct olevariantdata, pvar); + TypedData_Get_Struct(obj, struct olevariantdata, &olevariant_datatype, pvar); dim = RARRAY_LEN(elems); psab = ALLOC_N(SAFEARRAYBOUND, dim); @@ -403,7 +417,7 @@ folevariant_initialize(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L417 check_type_val2variant(val); - Data_Get_Struct(self, struct olevariantdata, pvar); + TypedData_Get_Struct(self, struct olevariantdata, &olevariant_datatype, pvar); if (len == 1) { ole_val2variant(val, &(pvar->var)); } else { @@ -423,7 +437,7 @@ get_locked_safe_array(VALUE val) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L437 struct olevariantdata *pvar; SAFEARRAY *psa = NULL; HRESULT hr; - Data_Get_Struct(val, struct olevariantdata, pvar); + TypedData_Get_Struct(val, struct olevariantdata, &olevariant_datatype, pvar); if (!(V_VT(&(pvar->var)) & VT_ARRAY)) { rb_raise(rb_eTypeError, "variant type is not VT_ARRAY."); } @@ -498,7 +512,7 @@ folevariant_ary_aref(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L512 LONG *pid; HRESULT hr; - Data_Get_Struct(self, struct olevariantdata, pvar); + TypedData_Get_Struct(self, struct olevariantdata, &olevariant_datatype, pvar); if (!V_ISARRAY(&(pvar->var))) { rb_raise(eWIN32OLERuntimeError, "`[]' is not available for this variant type object"); @@ -555,7 +569,7 @@ folevariant_ary_aset(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L569 HRESULT hr; VOID *p = NULL; - Data_Get_Struct(self, struct olevariantdata, pvar); + TypedData_Get_Struct(self, struct olevariantdata, &olevariant_datatype, pvar); if (!V_ISARRAY(&(pvar->var))) { rb_raise(eWIN32OLERuntimeError, "`[]' is not available for this variant type object"); @@ -601,7 +615,7 @@ folevariant_value(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L615 VARTYPE vt; int dim; SAFEARRAY *psa; - Data_Get_Struct(self, struct olevariantdata, pvar); + TypedData_Get_Struct(self, struct olevariantdata, &olevariant_datatype, pvar); val = ole_variant2val(&(pvar->var)); vt = V_VT(&(pvar->var)); @@ -636,7 +650,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L650 folevariant_vartype(VALUE self) { struct olevariantdata *pvar; - Data_Get_Struct(self, struct olevariantdata, pvar); + TypedData_Get_Struct(self, struct olevariantdata, &olevariant_datatype, pvar); return INT2FIX(V_VT(&pvar->var)); } @@ -659,7 +673,7 @@ folevariant_set_value(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L673 { struct olevariantdata *pvar; VARTYPE vt; - Data_Get_Struct(self, struct olevariantdata, pvar); + TypedData_Get_Struct(self, struct olevariantdata, &olevariant_datatype, pvar); vt = V_VT(&(pvar->var)); if (V_ISARRAY(&(pvar->var)) && ((vt & ~VT_BYREF) != (VT_UI1|VT_ARRAY) || !RB_TYPE_P(val, T_STRING))) { rb_raise(eWIN32OLERuntimeError, @@ -673,7 +687,7 @@ void https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L687 ole_variant2variant(VALUE val, VARIANT *var) { struct olevariantdata *pvar; - Data_Get_Struct(val, struct olevariantdata, pvar); + TypedData_Get_Struct(val, struct olevariantdata, &olevariant_datatype, pvar); VariantCopy(var, &(pvar->var)); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/