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
b3d0585f
Commit
b3d0585f
authored
Aug 20, 2014
by
take_cheeze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API `mrb_data_init` to initialize `MRB_TT_DATA` tagged instance.
parent
f6f31a8e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
9 deletions
+13
-9
include/mruby/data.h
include/mruby/data.h
+8
-0
mrbgems/mruby-random/src/random.c
mrbgems/mruby-random/src/random.c
+2
-4
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
+3
-5
No files found.
include/mruby/data.h
View file @
b3d0585f
...
...
@@ -51,6 +51,14 @@ MRB_API void *mrb_data_check_get_ptr(mrb_state *mrb, mrb_value, const mrb_data_t
*(void**)&sval = mrb_data_get_ptr(mrb, obj, type); \
} while (0)
static
inline
void
mrb_data_init
(
mrb_value
v
,
void
*
ptr
,
const
mrb_data_type
*
type
)
{
mrb_assert
(
mrb_type
(
v
)
==
MRB_TT_DATA
);
DATA_PTR
(
v
)
=
ptr
;
DATA_TYPE
(
v
)
=
type
;
}
#if defined(__cplusplus)
}
/* extern "C" { */
#endif
...
...
mrbgems/mruby-random/src/random.c
View file @
b3d0585f
...
...
@@ -129,9 +129,7 @@ mrb_random_init(mrb_state *mrb, mrb_value self)
if
(
t
)
{
mrb_free
(
mrb
,
t
);
}
DATA_TYPE
(
self
)
=
&
mt_state_type
;
DATA_PTR
(
self
)
=
NULL
;
mrb_data_init
(
self
,
NULL
,
&
mt_state_type
);
t
=
(
mt_state
*
)
mrb_malloc
(
mrb
,
sizeof
(
mt_state
));
t
->
mti
=
N
+
1
;
...
...
@@ -147,7 +145,7 @@ mrb_random_init(mrb_state *mrb, mrb_value self)
t
->
seed
=
mrb_fixnum
(
seed
);
}
DATA_PTR
(
self
)
=
t
;
mrb_data_init
(
self
,
t
,
&
mt_state_type
)
;
return
self
;
}
...
...
mrbgems/mruby-time/src/time.c
View file @
b3d0585f
...
...
@@ -561,8 +561,7 @@ mrb_time_initialize(mrb_state *mrb, mrb_value self)
if
(
tm
)
{
mrb_free
(
mrb
,
tm
);
}
DATA_TYPE
(
self
)
=
&
mrb_time_type
;
DATA_PTR
(
self
)
=
NULL
;
mrb_data_init
(
self
,
NULL
,
&
mrb_time_type
);
n
=
mrb_get_args
(
mrb
,
"|iiiiiii"
,
&
ayear
,
&
amonth
,
&
aday
,
&
ahour
,
&
amin
,
&
asec
,
&
ausec
);
...
...
@@ -572,7 +571,7 @@ mrb_time_initialize(mrb_state *mrb, mrb_value self)
else
{
tm
=
time_mktime
(
mrb
,
ayear
,
amonth
,
aday
,
ahour
,
amin
,
asec
,
ausec
,
MRB_TIMEZONE_LOCAL
);
}
DATA_PTR
(
self
)
=
tm
;
mrb_data_init
(
self
,
tm
,
&
mrb_time_type
)
;
return
self
;
}
...
...
@@ -589,8 +588,7 @@ mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy)
mrb_raise
(
mrb
,
E_TYPE_ERROR
,
"wrong argument class"
);
}
if
(
!
DATA_PTR
(
copy
))
{
DATA_PTR
(
copy
)
=
mrb_malloc
(
mrb
,
sizeof
(
struct
mrb_time
));
DATA_TYPE
(
copy
)
=
&
mrb_time_type
;
mrb_data_init
(
copy
,
mrb_malloc
(
mrb
,
sizeof
(
struct
mrb_time
)),
&
mrb_time_type
);
}
*
(
struct
mrb_time
*
)
DATA_PTR
(
copy
)
=
*
(
struct
mrb_time
*
)
DATA_PTR
(
src
);
return
copy
;
...
...
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