From f9dcfb2bca3d32099c6afab065c5476e234e6dfd Mon Sep 17 00:00:00 2001 From: suke Date: Tue, 2 Dec 2014 12:34:52 +0000 Subject: [PATCH] * ext/win32ole/win32ole.c: use typed data for com_hash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ ext/win32ole/win32ole.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b5f6b918b..8c34d19004 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Dec 2 21:33:56 2014 Masaki Suketa + + * ext/win32ole/win32ole.c: use typed data for com_hash. + Tue Dec 2 15:30:30 2014 Martin Duerst * array.c (rb_ary_plus): in documentation, added note about diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index eee57d3cc1..9daa8554ba 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -169,12 +169,22 @@ static VALUE fole_activex_initialize(VALUE self); static void init_enc2cp(void); static void free_enc2cp(void); +static void com_hash_free(void *ptr); +static void com_hash_mark(void *ptr); +static size_t com_hash_size(const void *ptr); + static const rb_data_type_t ole_datatype = { "win32ole", {NULL, ole_free, ole_size,}, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY }; +static const rb_data_type_t com_hash_datatype = { + "com_hash", + {com_hash_mark, com_hash_free, com_hash_size,}, + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY +}; + static HRESULT (STDMETHODCALLTYPE mf_QueryInterface)( IMessageFilter __RPC_FAR * This, /* [in] */ REFIID riid, @@ -393,7 +403,6 @@ val2dispatch(VALUE val) struct st_table *tbl = DATA_PTR(com_hash); Win32OLEIDispatch* pdisp; st_data_t data; - if (st_lookup(tbl, val, &data)) { pdisp = (Win32OLEIDispatch *)(data & ~FIXNUM_FLAG); pdisp->refcount++; @@ -3866,6 +3875,27 @@ free_enc2cp(void) st_free_table(enc2cp_table); } +static void +com_hash_free(void *ptr) +{ + st_table *tbl = ptr; + st_free_table(tbl); +} + +static void +com_hash_mark(void *ptr) +{ + st_table *tbl = ptr; + rb_mark_hash(tbl); +} + +static size_t +com_hash_size(const void *ptr) +{ + const st_table *tbl = ptr; + return tbl ? st_memsize(tbl) : 0; +} + void Init_win32ole(void) { @@ -3887,7 +3917,7 @@ Init_win32ole(void) message_filter.RetryRejectedCall = mf_RetryRejectedCall; message_filter.MessagePending = mf_MessagePending; - com_hash = Data_Wrap_Struct(rb_cData, rb_mark_hash, st_free_table, st_init_numtable()); + com_hash = TypedData_Wrap_Struct(rb_cData, &com_hash_datatype, st_init_numtable()); rb_gc_register_mark_object(com_hash); cWIN32OLE = rb_define_class("WIN32OLE", rb_cObject);