summaryrefslogtreecommitdiff
path: root/ext/win32ole
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-02 12:34:52 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-02 12:34:52 +0000
commitf9dcfb2bca3d32099c6afab065c5476e234e6dfd (patch)
tree48c2ee61956e6a855ab1a184ccc96c691b83192d /ext/win32ole
parent56891028bdc1e115e6c8f4ec7f8c7aa199974473 (diff)
* 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
Diffstat (limited to 'ext/win32ole')
-rw-r--r--ext/win32ole/win32ole.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index eee57d3..9daa855 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);