Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
d441c2e5
Commit
d441c2e5
authored
9 years ago
by
Yuki Yugui Sonoda
Browse files
Options
Downloads
Patches
Plain Diff
Use TypedData for GRPC::Core::TimeSpec
parent
a87924e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ruby/ext/grpc/rb_grpc.c
+23
-14
23 additions, 14 deletions
src/ruby/ext/grpc/rb_grpc.c
with
23 additions
and
14 deletions
src/ruby/ext/grpc/rb_grpc.c
+
23
−
14
View file @
d441c2e5
...
@@ -48,6 +48,13 @@
...
@@ -48,6 +48,13 @@
VALUE
grpc_rb_cTimeVal
=
Qnil
;
VALUE
grpc_rb_cTimeVal
=
Qnil
;
static
rb_data_type_t
grpc_rb_timespec_data_type
=
{
"gpr_timespec"
,
{
GRPC_RB_GC_NOT_MARKED
,
GRPC_RB_GC_DONT_FREE
,
GRPC_RB_MEMSIZE_UNAVAILABLE
},
NULL
,
NULL
,
RUBY_TYPED_FREE_IMMEDIATELY
};
/* Alloc func that blocks allocation of a given object by raising an
/* Alloc func that blocks allocation of a given object by raising an
* exception. */
* exception. */
VALUE
grpc_rb_cannot_alloc
(
VALUE
cls
)
{
VALUE
grpc_rb_cannot_alloc
(
VALUE
cls
)
{
...
@@ -93,7 +100,8 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
...
@@ -93,7 +100,8 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
switch
(
TYPE
(
time
))
{
switch
(
TYPE
(
time
))
{
case
T_DATA
:
case
T_DATA
:
if
(
CLASS_OF
(
time
)
==
grpc_rb_cTimeVal
)
{
if
(
CLASS_OF
(
time
)
==
grpc_rb_cTimeVal
)
{
Data_Get_Struct
(
time
,
gpr_timespec
,
time_const
);
TypedData_Get_Struct
(
time
,
gpr_timespec
,
&
grpc_rb_timespec_data_type
,
time_const
);
t
=
*
time_const
;
t
=
*
time_const
;
}
else
if
(
CLASS_OF
(
time
)
==
rb_cTime
)
{
}
else
if
(
CLASS_OF
(
time
)
==
rb_cTime
)
{
t
.
tv_sec
=
NUM2INT
(
rb_funcall
(
time
,
id_tv_sec
,
0
));
t
.
tv_sec
=
NUM2INT
(
rb_funcall
(
time
,
id_tv_sec
,
0
));
...
@@ -197,7 +205,8 @@ static ID id_to_s;
...
@@ -197,7 +205,8 @@ static ID id_to_s;
/* Converts a wrapped time constant to a standard time. */
/* Converts a wrapped time constant to a standard time. */
VALUE
grpc_rb_time_val_to_time
(
VALUE
self
)
{
VALUE
grpc_rb_time_val_to_time
(
VALUE
self
)
{
gpr_timespec
*
time_const
=
NULL
;
gpr_timespec
*
time_const
=
NULL
;
Data_Get_Struct
(
self
,
gpr_timespec
,
time_const
);
TypedData_Get_Struct
(
self
,
gpr_timespec
,
&
grpc_rb_timespec_data_type
,
time_const
);
return
rb_funcall
(
rb_cTime
,
id_at
,
2
,
INT2NUM
(
time_const
->
tv_sec
),
return
rb_funcall
(
rb_cTime
,
id_at
,
2
,
INT2NUM
(
time_const
->
tv_sec
),
INT2NUM
(
time_const
->
tv_nsec
));
INT2NUM
(
time_const
->
tv_nsec
));
}
}
...
@@ -218,18 +227,18 @@ void Init_grpc_time_consts() {
...
@@ -218,18 +227,18 @@ void Init_grpc_time_consts() {
rb_define_module_under
(
grpc_rb_mGrpcCore
,
"TimeConsts"
);
rb_define_module_under
(
grpc_rb_mGrpcCore
,
"TimeConsts"
);
grpc_rb_cTimeVal
=
grpc_rb_cTimeVal
=
rb_define_class_under
(
grpc_rb_mGrpcCore
,
"TimeSpec"
,
rb_cObject
);
rb_define_class_under
(
grpc_rb_mGrpcCore
,
"TimeSpec"
,
rb_cObject
);
rb_define_const
(
grpc_rb_mTimeConsts
,
"ZERO"
,
rb_define_const
(
Data_Wrap_Struct
(
grpc_rb_
c
Time
Val
,
grpc_rb_
m
Time
Consts
,
"ZERO"
,
GRPC_RB_GC_NOT_MARKED
,
GRPC_RB_GC_DONT_FREE
,
TypedData_Wrap_Struct
(
grpc_rb_cTimeVal
,
&
grpc_rb_timespec_data_type
,
(
void
*
)
&
gpr_time_0
));
(
void
*
)
&
gpr_time_0
));
rb_define_const
(
grpc_rb_mTimeConsts
,
"INFINITE_FUTURE"
,
rb_define_const
(
Data_Wrap_Struct
(
grpc_rb_
c
Time
Val
,
grpc_rb_
m
Time
Consts
,
"INFINITE_FUTURE"
,
GRPC_RB_GC_NOT_MARKED
,
GRPC_RB_GC_DONT_FREE
,
TypedData_Wrap_Struct
(
grpc_rb_cTimeVal
,
&
grpc_rb_timespec_data_type
,
(
void
*
)
&
gpr_inf_future
));
(
void
*
)
&
gpr_inf_future
));
rb_define_const
(
grpc_rb_mTimeConsts
,
"INFINITE_PAST"
,
rb_define_const
(
Data_Wrap_Struct
(
grpc_rb_
c
Time
Val
,
grpc_rb_
m
Time
Consts
,
"INFINITE_PAST"
,
GRPC_RB_GC_NOT_MARKED
,
GRPC_RB_GC_DONT_FREE
,
TypedData_Wrap_Struct
(
grpc_rb_cTimeVal
,
&
grpc_rb_timespec_data_type
,
(
void
*
)
&
gpr_inf_past
));
(
void
*
)
&
gpr_inf_past
));
rb_define_method
(
grpc_rb_cTimeVal
,
"to_time"
,
grpc_rb_time_val_to_time
,
0
);
rb_define_method
(
grpc_rb_cTimeVal
,
"to_time"
,
grpc_rb_time_val_to_time
,
0
);
rb_define_method
(
grpc_rb_cTimeVal
,
"inspect"
,
grpc_rb_time_val_inspect
,
0
);
rb_define_method
(
grpc_rb_cTimeVal
,
"inspect"
,
grpc_rb_time_val_inspect
,
0
);
rb_define_method
(
grpc_rb_cTimeVal
,
"to_s"
,
grpc_rb_time_val_to_s
,
0
);
rb_define_method
(
grpc_rb_cTimeVal
,
"to_s"
,
grpc_rb_time_val_to_s
,
0
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment