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
606307d3
Commit
606307d3
authored
Sep 04, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2585 from cremno/get-rid-of-shadowing-variables-mrbgems
get rid of shadowing variables (mrbgems)
parents
f25d95a2
fec2c66e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
31 deletions
+37
-31
mrbgems/mruby-sprintf/src/sprintf.c
mrbgems/mruby-sprintf/src/sprintf.c
+7
-7
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+30
-24
No files found.
mrbgems/mruby-sprintf/src/sprintf.c
View file @
606307d3
...
...
@@ -664,23 +664,23 @@ retry:
case
'c'
:
{
mrb_value
val
=
GETARG
();
mrb_value
tmp
;
mrb_value
c
tmp
;
char
*
c
;
tmp
=
mrb_check_string_type
(
mrb
,
val
);
if
(
!
mrb_nil_p
(
tmp
))
{
if
(
mrb_fixnum
(
mrb_funcall
(
mrb
,
tmp
,
"size"
,
0
))
!=
1
)
{
c
tmp
=
mrb_check_string_type
(
mrb
,
val
);
if
(
!
mrb_nil_p
(
c
tmp
))
{
if
(
mrb_fixnum
(
mrb_funcall
(
mrb
,
c
tmp
,
"size"
,
0
))
!=
1
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"%c requires a character"
);
}
}
else
if
(
mrb_fixnum_p
(
val
))
{
tmp
=
mrb_funcall
(
mrb
,
val
,
"chr"
,
0
);
c
tmp
=
mrb_funcall
(
mrb
,
val
,
"chr"
,
0
);
}
else
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"invalid character"
);
}
c
=
RSTRING_PTR
(
tmp
);
n
=
RSTRING_LEN
(
tmp
);
c
=
RSTRING_PTR
(
c
tmp
);
n
=
RSTRING_LEN
(
c
tmp
);
if
(
!
(
flags
&
FWIDTH
))
{
CHECK
(
n
);
memcpy
(
buf
+
blen
,
c
,
n
);
...
...
mrbgems/mruby-struct/src/struct.c
View file @
606307d3
...
...
@@ -224,14 +224,37 @@ is_const_id(mrb_state *mrb, const char *name)
return
ISUPPER
(
name
[
0
]);
}
static
void
make_struct_define_accessors
(
mrb_state
*
mrb
,
mrb_value
members
,
struct
RClass
*
c
)
{
mrb_value
*
ptr_members
=
RARRAY_PTR
(
members
);
mrb_int
i
;
mrb_int
len
=
RARRAY_LEN
(
members
);
int
ai
=
mrb_gc_arena_save
(
mrb
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
mrb_sym
id
=
mrb_symbol
(
ptr_members
[
i
]);
const
char
*
name
=
mrb_sym2name_len
(
mrb
,
id
,
NULL
);
if
(
is_local_id
(
mrb
,
name
)
||
is_const_id
(
mrb
,
name
))
{
if
(
i
<
N_REF_FUNC
)
{
mrb_define_method_id
(
mrb
,
c
,
id
,
ref_func
[
i
],
MRB_ARGS_NONE
());
}
else
{
mrb_define_method_id
(
mrb
,
c
,
id
,
mrb_struct_ref
,
MRB_ARGS_NONE
());
}
mrb_define_method_id
(
mrb
,
c
,
mrb_id_attrset
(
mrb
,
id
),
mrb_struct_set_m
,
MRB_ARGS_REQ
(
1
));
mrb_gc_arena_restore
(
mrb
,
ai
);
}
}
}
static
mrb_value
make_struct
(
mrb_state
*
mrb
,
mrb_value
name
,
mrb_value
members
,
struct
RClass
*
klass
)
{
mrb_value
nstr
,
*
ptr_members
;
mrb_value
nstr
;
mrb_sym
id
;
mrb_int
i
,
len
;
struct
RClass
*
c
;
int
ai
;
if
(
mrb_nil_p
(
name
))
{
c
=
mrb_class_new
(
mrb
,
klass
);
...
...
@@ -257,24 +280,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
mrb_define_class_method
(
mrb
,
c
,
"[]"
,
mrb_instance_new
,
MRB_ARGS_ANY
());
mrb_define_class_method
(
mrb
,
c
,
"members"
,
mrb_struct_s_members_m
,
MRB_ARGS_NONE
());
/* RSTRUCT(nstr)->basic.c->super = c->c; */
ptr_members
=
RARRAY_PTR
(
members
);
len
=
RARRAY_LEN
(
members
);
ai
=
mrb_gc_arena_save
(
mrb
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
mrb_sym
id
=
mrb_symbol
(
ptr_members
[
i
]);
const
char
*
name
=
mrb_sym2name_len
(
mrb
,
id
,
NULL
);
if
(
is_local_id
(
mrb
,
name
)
||
is_const_id
(
mrb
,
name
))
{
if
(
i
<
N_REF_FUNC
)
{
mrb_define_method_id
(
mrb
,
c
,
id
,
ref_func
[
i
],
MRB_ARGS_NONE
());
}
else
{
mrb_define_method_id
(
mrb
,
c
,
id
,
mrb_struct_ref
,
MRB_ARGS_NONE
());
}
mrb_define_method_id
(
mrb
,
c
,
mrb_id_attrset
(
mrb
,
id
),
mrb_struct_set_m
,
MRB_ARGS_REQ
(
1
));
mrb_gc_arena_restore
(
mrb
,
ai
);
}
}
make_struct_define_accessors
(
mrb
,
members
,
c
);
return
nstr
;
}
...
...
@@ -432,7 +438,7 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur)
mrb_value
slot
;
mrb_sym
id
;
const
char
*
name
;
mrb_int
len
;
mrb_int
name
len
;
if
(
i
>
0
)
{
mrb_str_cat_lit
(
mrb
,
str
,
", "
);
...
...
@@ -442,9 +448,9 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur)
}
slot
=
ptr_members
[
i
];
id
=
mrb_symbol
(
slot
);
name
=
mrb_sym2name_len
(
mrb
,
id
,
&
len
);
name
=
mrb_sym2name_len
(
mrb
,
id
,
&
name
len
);
if
(
is_local_id
(
mrb
,
name
)
||
is_const_id
(
mrb
,
name
))
{
mrb_str_append
(
mrb
,
str
,
mrb_str_new
(
mrb
,
name
,
len
));
mrb_str_append
(
mrb
,
str
,
mrb_str_new
(
mrb
,
name
,
name
len
));
}
else
{
mrb_str_append
(
mrb
,
str
,
mrb_inspect
(
mrb
,
slot
));
...
...
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