summaryrefslogtreecommitdiff
path: root/ext/win32ole
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-06 14:35:43 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-06 14:35:43 +0000
commita60c5a1945e13f536197f8fd171c9c1d59bb880b (patch)
treede02d922964d1f970db01cf043042971b27277d8 /ext/win32ole
parent0ca714fa1aa3fbe4fb60ae1e5b730e544dabc27b (diff)
ext/win32ole/win32ole_param.c: use typed data.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/win32ole')
-rw-r--r--ext/win32ole/win32ole_param.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/ext/win32ole/win32ole_param.c b/ext/win32ole/win32ole_param.c
index 9d28a89..c268a85 100644
--- a/ext/win32ole/win32ole_param.c
+++ b/ext/win32ole/win32ole_param.c
@@ -8,7 +8,8 @@ struct oleparamdata {
UINT index;
};
-static void oleparam_free(struct oleparamdata *pole);
+static void oleparam_free(void *ptr);
+static size_t oleparam_size(const void *ptr);
static VALUE foleparam_s_allocate(VALUE klass);
static VALUE oleparam_ole_param_from_index(VALUE self, ITypeInfo *pTypeInfo, UINT method_index, int param_index);
static VALUE oleparam_ole_param(VALUE self, VALUE olemethod, int n);
@@ -27,19 +28,32 @@ static VALUE ole_param_default(ITypeInfo *pTypeInfo, UINT method_index, UINT ind
static VALUE foleparam_default(VALUE self);
static VALUE foleparam_inspect(VALUE self);
+static const rb_data_type_t oleparam_datatype = {
+ "win32ole_param",
+ {NULL, oleparam_free, oleparam_size,},
+ NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
static void
-oleparam_free(struct oleparamdata *pole)
+oleparam_free(void *ptr)
{
+ struct oleparamdata *pole = ptr;
OLE_FREE(pole->pTypeInfo);
free(pole);
}
+static size_t
+oleparam_size(const void *ptr)
+{
+ return ptr ? sizeof(struct oleparamdata) : 0;
+}
+
VALUE
create_win32ole_param(ITypeInfo *pTypeInfo, UINT method_index, UINT index, VALUE name)
{
struct oleparamdata *pparam;
VALUE obj = foleparam_s_allocate(cWIN32OLE_PARAM);
- Data_Get_Struct(obj, struct oleparamdata, pparam);
+ TypedData_Get_Struct(obj, struct oleparamdata, &oleparam_datatype, pparam);
pparam->pTypeInfo = pTypeInfo;
OLE_ADDREF(pTypeInfo);
@@ -60,9 +74,9 @@ foleparam_s_allocate(VALUE klass)
{
struct oleparamdata *pparam;
VALUE obj;
- obj = Data_Make_Struct(klass,
- struct oleparamdata,
- 0, oleparam_free, pparam);
+ obj = TypedData_Make_Struct(klass,
+ struct oleparamdata,
+ &oleparam_datatype, pparam);
pparam->pTypeInfo = NULL;
pparam->method_index = 0;
pparam->index = 0;
@@ -97,7 +111,7 @@ oleparam_ole_param_from_index(VALUE self, ITypeInfo *pTypeInfo, UINT method_inde
rb_raise(rb_eIndexError, "index of param must be in 1..%d", len);
}
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
pparam->pTypeInfo = pTypeInfo;
OLE_ADDREF(pTypeInfo);
pparam->method_index = method_index;
@@ -183,7 +197,7 @@ static VALUE
foleparam_ole_type(VALUE self)
{
struct oleparamdata *pparam;
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
return ole_param_ole_type(pparam->pTypeInfo, pparam->method_index,
pparam->index);
}
@@ -217,7 +231,7 @@ static VALUE
foleparam_ole_type_detail(VALUE self)
{
struct oleparamdata *pparam;
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
return ole_param_ole_type_detail(pparam->pTypeInfo, pparam->method_index,
pparam->index);
}
@@ -250,7 +264,7 @@ ole_param_flag_mask(ITypeInfo *pTypeInfo, UINT method_index, UINT index, USHORT
static VALUE foleparam_input(VALUE self)
{
struct oleparamdata *pparam;
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
pparam->index, PARAMFLAG_FIN);
}
@@ -277,7 +291,7 @@ static VALUE foleparam_input(VALUE self)
static VALUE foleparam_output(VALUE self)
{
struct oleparamdata *pparam;
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
pparam->index, PARAMFLAG_FOUT);
}
@@ -295,7 +309,7 @@ static VALUE foleparam_output(VALUE self)
static VALUE foleparam_optional(VALUE self)
{
struct oleparamdata *pparam;
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
pparam->index, PARAMFLAG_FOPT);
}
@@ -314,7 +328,7 @@ static VALUE foleparam_optional(VALUE self)
static VALUE foleparam_retval(VALUE self)
{
struct oleparamdata *pparam;
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
pparam->index, PARAMFLAG_FRETVAL);
}
@@ -374,7 +388,7 @@ ole_param_default(ITypeInfo *pTypeInfo, UINT method_index, UINT index)
static VALUE foleparam_default(VALUE self)
{
struct oleparamdata *pparam;
- Data_Get_Struct(self, struct oleparamdata, pparam);
+ TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
return ole_param_default(pparam->pTypeInfo, pparam->method_index,
pparam->index);
}