Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
75f5535c
Commit
75f5535c
authored
Apr 04, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename DATA API: mrb_get_datatype -> mrb_data_get_ptr; mrb_check_datatype -> mrb_data_check_and_get
parent
dfb47557
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
41 deletions
+53
-41
include/mruby/data.h
include/mruby/data.h
+6
-3
mrbgems/mruby-random/src/random.c
mrbgems/mruby-random/src/random.c
+1
-1
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
+28
-28
src/etc.c
src/etc.c
+18
-9
No files found.
include/mruby/data.h
View file @
75f5535c
...
@@ -37,10 +37,13 @@ struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass, void *
...
@@ -37,10 +37,13 @@ struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass, void *
#define RDATA(obj) ((struct RData *)((obj).value.p))
#define RDATA(obj) ((struct RData *)((obj).value.p))
#define DATA_PTR(d) (RDATA(d)->data)
#define DATA_PTR(d) (RDATA(d)->data)
#define DATA_TYPE(d) (RDATA(d)->type)
#define DATA_TYPE(d) (RDATA(d)->type)
void
*
mrb_get_datatype
(
mrb_state
*
mrb
,
mrb_value
,
const
mrb_data_type
*
);
void
mrb_data_check_type
(
mrb_state
*
mrb
,
mrb_value
,
const
mrb_data_type
*
);
void
*
mrb_check_datatype
(
mrb_state
*
mrb
,
mrb_value
,
const
mrb_data_type
*
);
void
*
mrb_data_get_ptr
(
mrb_state
*
mrb
,
mrb_value
,
const
mrb_data_type
*
);
void
*
mrb_data_check_and_get
(
mrb_state
*
mrb
,
mrb_value
,
const
mrb_data_type
*
);
#define mrb_get_datatype(mrb,val,type) mrb_data_get_ptr(mrb, val, type)
#define mrb_check_datatype(mrb,val,type) mrb_data_check_and_get(mrb, val, type)
#define Data_Get_Struct(mrb,obj,type,sval) do {\
#define Data_Get_Struct(mrb,obj,type,sval) do {\
*(void**)&sval = mrb_
check_datatype
(mrb, obj, type); \
*(void**)&sval = mrb_
data_check_and_get
(mrb, obj, type); \
} while (0)
} while (0)
#if defined(__cplusplus)
#if defined(__cplusplus)
...
...
mrbgems/mruby-random/src/random.c
View file @
75f5535c
...
@@ -29,7 +29,7 @@ static mt_state *mrb_mt_get_context(mrb_state *mrb, mrb_value self)
...
@@ -29,7 +29,7 @@ static mt_state *mrb_mt_get_context(mrb_state *mrb, mrb_value self)
mrb_value
context
;
mrb_value
context
;
context
=
mrb_iv_get
(
mrb
,
self
,
mrb_intern
(
mrb
,
MT_STATE_KEY
));
context
=
mrb_iv_get
(
mrb
,
self
,
mrb_intern
(
mrb
,
MT_STATE_KEY
));
t
=
(
mt_state
*
)
mrb_check_datatype
(
mrb
,
context
,
&
mt_state_type
);
t
=
(
mt_state
*
)
mrb_data_get_ptr
(
mrb
,
context
,
&
mt_state_type
);
if
(
!
t
)
if
(
!
t
)
mrb_raise
(
mrb
,
E_RUNTIME_ERROR
,
"mt_state get from mrb_iv_get failed"
);
mrb_raise
(
mrb
,
E_RUNTIME_ERROR
,
"mt_state get from mrb_iv_get failed"
);
...
...
mrbgems/mruby-time/src/time.c
View file @
75f5535c
...
@@ -298,8 +298,8 @@ mrb_time_eq(mrb_state *mrb, mrb_value self)
...
@@ -298,8 +298,8 @@ mrb_time_eq(mrb_state *mrb, mrb_value self)
mrb_bool
eq_p
;
mrb_bool
eq_p
;
mrb_get_args
(
mrb
,
"o"
,
&
other
);
mrb_get_args
(
mrb
,
"o"
,
&
other
);
tm1
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm1
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
tm2
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
other
,
&
mrb_time_type
);
tm2
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
other
,
&
mrb_time_type
);
eq_p
=
tm1
&&
tm2
&&
tm1
->
sec
==
tm2
->
sec
&&
tm1
->
usec
==
tm2
->
usec
;
eq_p
=
tm1
&&
tm2
&&
tm1
->
sec
==
tm2
->
sec
&&
tm1
->
usec
==
tm2
->
usec
;
return
mrb_bool_value
(
eq_p
);
return
mrb_bool_value
(
eq_p
);
...
@@ -312,8 +312,8 @@ mrb_time_cmp(mrb_state *mrb, mrb_value self)
...
@@ -312,8 +312,8 @@ mrb_time_cmp(mrb_state *mrb, mrb_value self)
struct
mrb_time
*
tm1
,
*
tm2
;
struct
mrb_time
*
tm1
,
*
tm2
;
mrb_get_args
(
mrb
,
"o"
,
&
other
);
mrb_get_args
(
mrb
,
"o"
,
&
other
);
tm1
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm1
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
tm2
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
other
,
&
mrb_time_type
);
tm2
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
other
,
&
mrb_time_type
);
if
(
!
tm1
||
!
tm2
)
return
mrb_nil_value
();
if
(
!
tm1
||
!
tm2
)
return
mrb_nil_value
();
if
(
tm1
->
sec
>
tm2
->
sec
)
{
if
(
tm1
->
sec
>
tm2
->
sec
)
{
return
mrb_fixnum_value
(
1
);
return
mrb_fixnum_value
(
1
);
...
@@ -338,7 +338,7 @@ mrb_time_plus(mrb_state *mrb, mrb_value self)
...
@@ -338,7 +338,7 @@ mrb_time_plus(mrb_state *mrb, mrb_value self)
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
mrb_get_args
(
mrb
,
"f"
,
&
f
);
mrb_get_args
(
mrb
,
"f"
,
&
f
);
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_time_make
(
mrb
,
mrb_obj_class
(
mrb
,
self
),
(
double
)
tm
->
sec
+
f
,
tm
->
usec
,
tm
->
timezone
);
return
mrb_time_make
(
mrb
,
mrb_obj_class
(
mrb
,
self
),
(
double
)
tm
->
sec
+
f
,
tm
->
usec
,
tm
->
timezone
);
}
}
...
@@ -351,10 +351,10 @@ mrb_time_minus(mrb_state *mrb, mrb_value self)
...
@@ -351,10 +351,10 @@ mrb_time_minus(mrb_state *mrb, mrb_value self)
struct
mrb_time
*
tm
,
*
tm2
;
struct
mrb_time
*
tm
,
*
tm2
;
mrb_get_args
(
mrb
,
"o"
,
&
other
);
mrb_get_args
(
mrb
,
"o"
,
&
other
);
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
tm2
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
other
,
&
mrb_time_type
);
tm2
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
other
,
&
mrb_time_type
);
if
(
tm2
)
{
if
(
tm2
)
{
f
=
(
mrb_float
)(
tm
->
sec
-
tm2
->
sec
)
f
=
(
mrb_float
)(
tm
->
sec
-
tm2
->
sec
)
+
(
mrb_float
)(
tm
->
usec
-
tm2
->
usec
)
/
1.0e6
;
+
(
mrb_float
)(
tm
->
usec
-
tm2
->
usec
)
/
1.0e6
;
...
@@ -373,7 +373,7 @@ mrb_time_wday(mrb_state *mrb, mrb_value self)
...
@@ -373,7 +373,7 @@ mrb_time_wday(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_wday
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_wday
);
}
}
...
@@ -385,7 +385,7 @@ mrb_time_yday(mrb_state *mrb, mrb_value self)
...
@@ -385,7 +385,7 @@ mrb_time_yday(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_check_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_yday
+
1
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_yday
+
1
);
}
}
...
@@ -397,7 +397,7 @@ mrb_time_year(mrb_state *mrb, mrb_value self)
...
@@ -397,7 +397,7 @@ mrb_time_year(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_year
+
1900
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_year
+
1900
);
}
}
...
@@ -409,7 +409,7 @@ mrb_time_zone(mrb_state *mrb, mrb_value self)
...
@@ -409,7 +409,7 @@ mrb_time_zone(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
if
(
tm
->
timezone
<=
MRB_TIMEZONE_NONE
)
return
mrb_nil_value
();
if
(
tm
->
timezone
<=
MRB_TIMEZONE_NONE
)
return
mrb_nil_value
();
if
(
tm
->
timezone
>=
MRB_TIMEZONE_LAST
)
return
mrb_nil_value
();
if
(
tm
->
timezone
>=
MRB_TIMEZONE_LAST
)
return
mrb_nil_value
();
...
@@ -426,7 +426,7 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self)
...
@@ -426,7 +426,7 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self)
char
buf
[
256
];
char
buf
[
256
];
int
len
;
int
len
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
d
=
&
tm
->
datetime
;
d
=
&
tm
->
datetime
;
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%s %s %02d %02d:%02d:%02d %s%d"
,
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%s %s %02d %02d:%02d:%02d %s%d"
,
...
@@ -444,7 +444,7 @@ mrb_time_day(mrb_state *mrb, mrb_value self)
...
@@ -444,7 +444,7 @@ mrb_time_day(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_mday
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_mday
);
}
}
...
@@ -457,7 +457,7 @@ mrb_time_dstp(mrb_state *mrb, mrb_value self)
...
@@ -457,7 +457,7 @@ mrb_time_dstp(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_bool_value
(
tm
->
datetime
.
tm_isdst
);
return
mrb_bool_value
(
tm
->
datetime
.
tm_isdst
);
}
}
...
@@ -470,7 +470,7 @@ mrb_time_getutc(mrb_state *mrb, mrb_value self)
...
@@ -470,7 +470,7 @@ mrb_time_getutc(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
,
*
tm2
;
struct
mrb_time
*
tm
,
*
tm2
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
self
;
if
(
!
tm
)
return
self
;
tm2
=
(
struct
mrb_time
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
tm
));
tm2
=
(
struct
mrb_time
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
tm
));
*
tm2
=
*
tm
;
*
tm2
=
*
tm
;
...
@@ -486,7 +486,7 @@ mrb_time_getlocal(mrb_state *mrb, mrb_value self)
...
@@ -486,7 +486,7 @@ mrb_time_getlocal(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
,
*
tm2
;
struct
mrb_time
*
tm
,
*
tm2
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
self
;
if
(
!
tm
)
return
self
;
tm2
=
(
struct
mrb_time
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
tm
));
tm2
=
(
struct
mrb_time
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
tm
));
*
tm2
=
*
tm
;
*
tm2
=
*
tm
;
...
@@ -502,7 +502,7 @@ mrb_time_hour(mrb_state *mrb, mrb_value self)
...
@@ -502,7 +502,7 @@ mrb_time_hour(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_hour
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_hour
);
}
}
...
@@ -517,7 +517,7 @@ mrb_time_initialize(mrb_state *mrb, mrb_value self)
...
@@ -517,7 +517,7 @@ mrb_time_initialize(mrb_state *mrb, mrb_value self)
int
n
;
int
n
;
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
DATA_PTR
(
self
);
if
(
tm
)
{
if
(
tm
)
{
mrb_time_free
(
mrb
,
tm
);
mrb_time_free
(
mrb
,
tm
);
}
}
...
@@ -563,7 +563,7 @@ mrb_time_localtime(mrb_state *mrb, mrb_value self)
...
@@ -563,7 +563,7 @@ mrb_time_localtime(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
self
;
if
(
!
tm
)
return
self
;
tm
->
timezone
=
MRB_TIMEZONE_LOCAL
;
tm
->
timezone
=
MRB_TIMEZONE_LOCAL
;
mrb_time_update_datetime
(
tm
);
mrb_time_update_datetime
(
tm
);
...
@@ -577,7 +577,7 @@ mrb_time_mday(mrb_state *mrb, mrb_value self)
...
@@ -577,7 +577,7 @@ mrb_time_mday(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_mday
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_mday
);
}
}
...
@@ -589,7 +589,7 @@ mrb_time_min(mrb_state *mrb, mrb_value self)
...
@@ -589,7 +589,7 @@ mrb_time_min(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_min
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_min
);
}
}
...
@@ -601,7 +601,7 @@ mrb_time_mon(mrb_state *mrb, mrb_value self)
...
@@ -601,7 +601,7 @@ mrb_time_mon(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_mon
+
1
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_mon
+
1
);
}
}
...
@@ -613,7 +613,7 @@ mrb_time_sec(mrb_state *mrb, mrb_value self)
...
@@ -613,7 +613,7 @@ mrb_time_sec(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_sec
);
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_sec
);
}
}
...
@@ -626,7 +626,7 @@ mrb_time_to_f(mrb_state *mrb, mrb_value self)
...
@@ -626,7 +626,7 @@ mrb_time_to_f(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_float_value
((
mrb_float
)
tm
->
sec
+
(
mrb_float
)
tm
->
usec
/
1.0e6
);
return
mrb_float_value
((
mrb_float
)
tm
->
sec
+
(
mrb_float
)
tm
->
usec
/
1.0e6
);
}
}
...
@@ -638,7 +638,7 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self)
...
@@ -638,7 +638,7 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
sec
);
return
mrb_fixnum_value
(
tm
->
sec
);
}
}
...
@@ -650,7 +650,7 @@ mrb_time_usec(mrb_state *mrb, mrb_value self)
...
@@ -650,7 +650,7 @@ mrb_time_usec(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_fixnum_value
(
tm
->
usec
);
return
mrb_fixnum_value
(
tm
->
usec
);
}
}
...
@@ -662,7 +662,7 @@ mrb_time_utc(mrb_state *mrb, mrb_value self)
...
@@ -662,7 +662,7 @@ mrb_time_utc(mrb_state *mrb, mrb_value self)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
tm
)
{
if
(
tm
)
{
tm
->
timezone
=
MRB_TIMEZONE_UTC
;
tm
->
timezone
=
MRB_TIMEZONE_UTC
;
mrb_time_update_datetime
(
tm
);
mrb_time_update_datetime
(
tm
);
...
@@ -676,7 +676,7 @@ static mrb_value
...
@@ -676,7 +676,7 @@ static mrb_value
mrb_time_utcp
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_time_utcp
(
mrb_state
*
mrb
,
mrb_value
self
)
{
{
struct
mrb_time
*
tm
;
struct
mrb_time
*
tm
;
tm
=
(
struct
mrb_time
*
)
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
tm
=
(
struct
mrb_time
*
)
mrb_data_get_ptr
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
if
(
!
tm
)
return
mrb_nil_value
();
return
mrb_bool_value
(
tm
->
timezone
==
MRB_TIMEZONE_UTC
);
return
mrb_bool_value
(
tm
->
timezone
==
MRB_TIMEZONE_UTC
);
}
}
...
...
src/etc.c
View file @
75f5535c
...
@@ -22,28 +22,37 @@ mrb_data_object_alloc(mrb_state *mrb, struct RClass *klass, void *ptr, const mrb
...
@@ -22,28 +22,37 @@ mrb_data_object_alloc(mrb_state *mrb, struct RClass *klass, void *ptr, const mrb
return
data
;
return
data
;
}
}
void
*
void
mrb_
get_data
type
(
mrb_state
*
mrb
,
mrb_value
obj
,
const
mrb_data_type
*
type
)
mrb_
data_check_
type
(
mrb_state
*
mrb
,
mrb_value
obj
,
const
mrb_data_type
*
type
)
{
{
if
(
mrb_special_const_p
(
obj
)
||
(
mrb_type
(
obj
)
!=
MRB_TT_DATA
))
{
if
(
mrb_special_const_p
(
obj
)
||
(
mrb_type
(
obj
)
!=
MRB_TT_DATA
))
{
return
NULL
;
mrb_check_type
(
mrb
,
obj
,
MRB_TT_DATA
)
;
}
}
if
(
DATA_TYPE
(
obj
)
!=
type
)
{
if
(
DATA_TYPE
(
obj
)
!=
type
)
{
return
NULL
;
const
mrb_data_type
*
t2
=
DATA_TYPE
(
obj
);
if
(
t2
)
{
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"wrong argument type %S (expected %S)"
,
mrb_str_new_cstr
(
mrb
,
t2
->
struct_name
),
mrb_str_new_cstr
(
mrb
,
type
->
struct_name
));
}
}
}
}
void
*
mrb_data_check_and_get
(
mrb_state
*
mrb
,
mrb_value
obj
,
const
mrb_data_type
*
type
)
{
mrb_data_check_type
(
mrb
,
obj
,
type
);
return
DATA_PTR
(
obj
);
return
DATA_PTR
(
obj
);
}
}
void
*
void
*
mrb_
check_datatype
(
mrb_state
*
mrb
,
mrb_value
obj
,
const
mrb_data_type
*
type
)
mrb_
data_get_ptr
(
mrb_state
*
mrb
,
mrb_value
obj
,
const
mrb_data_type
*
type
)
{
{
if
(
mrb_special_const_p
(
obj
)
||
(
mrb_type
(
obj
)
!=
MRB_TT_DATA
))
{
if
(
mrb_special_const_p
(
obj
)
||
(
mrb_type
(
obj
)
!=
MRB_TT_DATA
))
{
mrb_check_type
(
mrb
,
obj
,
MRB_TT_DATA
)
;
return
NULL
;
}
}
if
(
DATA_TYPE
(
obj
)
!=
type
)
{
if
(
DATA_TYPE
(
obj
)
!=
type
)
{
const
char
*
etype
=
DATA_TYPE
(
obj
)
->
struct_name
;
return
NULL
;
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"wrong argument type %S (expected %S)"
,
mrb_str_new_cstr
(
mrb
,
etype
),
mrb_str_new_cstr
(
mrb
,
type
->
struct_name
));
}
}
return
DATA_PTR
(
obj
);
return
DATA_PTR
(
obj
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment