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
c778c234
Unverified
Commit
c778c234
authored
May 07, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
May 07, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4424 from shuujii/avoid-using-mrb_str_to_cstr-if-possible
Avoid using `mrb_str_to_cstr` if possible
parents
31cc8573
e2604c15
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
18 deletions
+15
-18
mrbgems/mruby-io/src/file.c
mrbgems/mruby-io/src/file.c
+10
-11
mrbgems/mruby-io/src/file_test.c
mrbgems/mruby-io/src/file_test.c
+1
-1
mrbgems/mruby-io/test/mruby_io_test.c
mrbgems/mruby-io/test/mruby_io_test.c
+2
-4
mrbgems/mruby-socket/src/socket.c
mrbgems/mruby-socket/src/socket.c
+2
-2
No files found.
mrbgems/mruby-io/src/file.c
View file @
c778c234
...
@@ -146,7 +146,7 @@ mrb_file_s_rename(mrb_state *mrb, mrb_value obj)
...
@@ -146,7 +146,7 @@ mrb_file_s_rename(mrb_state *mrb, mrb_value obj)
#endif
#endif
mrb_locale_free
(
src
);
mrb_locale_free
(
src
);
mrb_locale_free
(
dst
);
mrb_locale_free
(
dst
);
mrb_sys_fail
(
mrb
,
mrb_str_to_cstr
(
mrb
,
mrb_format
(
mrb
,
"(%S, %S)"
,
from
,
to
)));
mrb_sys_fail
(
mrb
,
RSTRING_PTR
(
mrb_format
(
mrb
,
"(%S, %S)"
,
from
,
to
)));
}
}
mrb_locale_free
(
src
);
mrb_locale_free
(
src
);
mrb_locale_free
(
dst
);
mrb_locale_free
(
dst
);
...
@@ -159,12 +159,12 @@ mrb_file_dirname(mrb_state *mrb, mrb_value klass)
...
@@ -159,12 +159,12 @@ mrb_file_dirname(mrb_state *mrb, mrb_value klass)
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64)
char
dname
[
_MAX_DIR
],
vname
[
_MAX_DRIVE
];
char
dname
[
_MAX_DIR
],
vname
[
_MAX_DRIVE
];
char
buffer
[
_MAX_DRIVE
+
_MAX_DIR
];
char
buffer
[
_MAX_DRIVE
+
_MAX_DIR
];
const
char
*
utf8_path
;
char
*
path
;
char
*
path
;
size_t
ridx
;
size_t
ridx
;
mrb_value
s
;
mrb_get_args
(
mrb
,
"z"
,
&
utf8_path
);
mrb_get_args
(
mrb
,
"S"
,
&
s
);
path
=
mrb_locale_from_utf8
(
utf8_path
,
-
1
);
path
=
mrb_locale_from_utf8
(
mrb_str_to_cstr
(
mrb
,
s
),
-
1
);
_splitpath
(
path
,
vname
,
dname
,
NULL
,
NULL
);
_splitpath
((
const
char
*
)
path
,
vname
,
dname
,
NULL
,
NULL
);
snprintf
(
buffer
,
_MAX_DRIVE
+
_MAX_DIR
,
"%s%s"
,
vname
,
dname
);
snprintf
(
buffer
,
_MAX_DRIVE
+
_MAX_DIR
,
"%s%s"
,
vname
,
dname
);
mrb_locale_free
(
path
);
mrb_locale_free
(
path
);
ridx
=
strlen
(
buffer
);
ridx
=
strlen
(
buffer
);
...
@@ -248,7 +248,7 @@ mrb_file_realpath(mrb_state *mrb, mrb_value klass)
...
@@ -248,7 +248,7 @@ mrb_file_realpath(mrb_state *mrb, mrb_value klass)
s
=
mrb_str_append
(
mrb
,
s
,
pathname
);
s
=
mrb_str_append
(
mrb
,
s
,
pathname
);
pathname
=
s
;
pathname
=
s
;
}
}
cpath
=
mrb_locale_from_utf8
(
mrb_str
_to_cstr
(
mrb
,
pathname
),
-
1
);
cpath
=
mrb_locale_from_utf8
(
mrb_str
ing_value_cstr
(
mrb
,
&
pathname
),
-
1
);
result
=
mrb_str_buf_new
(
mrb
,
PATH_MAX
);
result
=
mrb_str_buf_new
(
mrb
,
PATH_MAX
);
if
(
realpath
(
cpath
,
RSTRING_PTR
(
result
))
==
NULL
)
{
if
(
realpath
(
cpath
,
RSTRING_PTR
(
result
))
==
NULL
)
{
mrb_locale_free
(
cpath
);
mrb_locale_free
(
cpath
);
...
@@ -300,7 +300,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass)
...
@@ -300,7 +300,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass)
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"non-absolute home"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"non-absolute home"
);
}
}
}
else
{
}
else
{
const
char
*
cuser
=
mrb_str
_to_cstr
(
mrb
,
username
);
const
char
*
cuser
=
mrb_str
ing_value_cstr
(
mrb
,
&
username
);
struct
passwd
*
pwd
=
getpwnam
(
cuser
);
struct
passwd
*
pwd
=
getpwnam
(
cuser
);
if
(
pwd
==
NULL
)
{
if
(
pwd
==
NULL
)
{
return
mrb_nil_value
();
return
mrb_nil_value
();
...
@@ -393,9 +393,8 @@ mrb_file_s_symlink(mrb_state *mrb, mrb_value klass)
...
@@ -393,9 +393,8 @@ mrb_file_s_symlink(mrb_state *mrb, mrb_value klass)
int
ai
=
mrb_gc_arena_save
(
mrb
);
int
ai
=
mrb_gc_arena_save
(
mrb
);
mrb_get_args
(
mrb
,
"SS"
,
&
from
,
&
to
);
mrb_get_args
(
mrb
,
"SS"
,
&
from
,
&
to
);
src
=
mrb_locale_from_utf8
(
mrb_str_to_cstr
(
mrb
,
from
),
-
1
);
src
=
mrb_locale_from_utf8
(
mrb_string_value_cstr
(
mrb
,
&
from
),
-
1
);
dst
=
mrb_locale_from_utf8
(
mrb_str_to_cstr
(
mrb
,
to
),
-
1
);
dst
=
mrb_locale_from_utf8
(
mrb_string_value_cstr
(
mrb
,
&
to
),
-
1
);
if
(
symlink
(
src
,
dst
)
==
-
1
)
{
if
(
symlink
(
src
,
dst
)
==
-
1
)
{
mrb_locale_free
(
src
);
mrb_locale_free
(
src
);
mrb_locale_free
(
dst
);
mrb_locale_free
(
dst
);
...
@@ -417,7 +416,7 @@ mrb_file_s_chmod(mrb_state *mrb, mrb_value klass) {
...
@@ -417,7 +416,7 @@ mrb_file_s_chmod(mrb_state *mrb, mrb_value klass) {
mrb_get_args
(
mrb
,
"i*"
,
&
mode
,
&
filenames
,
&
argc
);
mrb_get_args
(
mrb
,
"i*"
,
&
mode
,
&
filenames
,
&
argc
);
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
const
char
*
utf8_path
=
mrb_str
_to_cstr
(
mrb
,
filenames
[
i
]);
const
char
*
utf8_path
=
mrb_str
ing_value_cstr
(
mrb
,
&
filenames
[
i
]);
char
*
path
=
mrb_locale_from_utf8
(
utf8_path
,
-
1
);
char
*
path
=
mrb_locale_from_utf8
(
utf8_path
,
-
1
);
if
(
CHMOD
(
path
,
mode
)
==
-
1
)
{
if
(
CHMOD
(
path
,
mode
)
==
-
1
)
{
mrb_locale_free
(
path
);
mrb_locale_free
(
path
);
...
...
mrbgems/mruby-io/src/file_test.c
View file @
c778c234
...
@@ -63,7 +63,7 @@ mrb_stat0(mrb_state *mrb, mrb_value obj, struct stat *st, int do_lstat)
...
@@ -63,7 +63,7 @@ mrb_stat0(mrb_state *mrb, mrb_value obj, struct stat *st, int do_lstat)
tmp
=
mrb_funcall
(
mrb
,
obj
,
"is_a?"
,
1
,
str_klass
);
tmp
=
mrb_funcall
(
mrb
,
obj
,
"is_a?"
,
1
,
str_klass
);
if
(
mrb_test
(
tmp
))
{
if
(
mrb_test
(
tmp
))
{
char
*
path
=
mrb_locale_from_utf8
(
mrb_str
_to_cstr
(
mrb
,
obj
),
-
1
);
char
*
path
=
mrb_locale_from_utf8
(
mrb_str
ing_value_cstr
(
mrb
,
&
obj
),
-
1
);
int
ret
;
int
ret
;
if
(
do_lstat
)
{
if
(
do_lstat
)
{
ret
=
LSTAT
(
path
,
st
);
ret
=
LSTAT
(
path
,
st
);
...
...
mrbgems/mruby-io/test/mruby_io_test.c
View file @
c778c234
...
@@ -215,11 +215,9 @@ mrb_io_test_mkdtemp(mrb_state *mrb, mrb_value klass)
...
@@ -215,11 +215,9 @@ mrb_io_test_mkdtemp(mrb_state *mrb, mrb_value klass)
static
mrb_value
static
mrb_value
mrb_io_test_rmdir
(
mrb_state
*
mrb
,
mrb_value
klass
)
mrb_io_test_rmdir
(
mrb_state
*
mrb
,
mrb_value
klass
)
{
{
mrb_value
str
;
const
char
*
cp
;
char
*
cp
;
mrb_get_args
(
mrb
,
"S"
,
&
str
);
mrb_get_args
(
mrb
,
"z"
,
&
cp
);
cp
=
mrb_str_to_cstr
(
mrb
,
str
);
if
(
rmdir
(
cp
)
==
-
1
)
{
if
(
rmdir
(
cp
)
==
-
1
)
{
mrb_sys_fail
(
mrb
,
"rmdir"
);
mrb_sys_fail
(
mrb
,
"rmdir"
);
}
}
...
...
mrbgems/mruby-socket/src/socket.c
View file @
c778c234
...
@@ -131,7 +131,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
...
@@ -131,7 +131,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
mrb_get_args
(
mrb
,
"oo|oooi"
,
&
nodename
,
&
service
,
&
family
,
&
socktype
,
&
protocol
,
&
flags
);
mrb_get_args
(
mrb
,
"oo|oooi"
,
&
nodename
,
&
service
,
&
family
,
&
socktype
,
&
protocol
,
&
flags
);
if
(
mrb_string_p
(
nodename
))
{
if
(
mrb_string_p
(
nodename
))
{
hostname
=
mrb_str
_to_cstr
(
mrb
,
nodename
);
hostname
=
mrb_str
ing_value_cstr
(
mrb
,
&
nodename
);
}
else
if
(
mrb_nil_p
(
nodename
))
{
}
else
if
(
mrb_nil_p
(
nodename
))
{
hostname
=
NULL
;
hostname
=
NULL
;
}
else
{
}
else
{
...
@@ -139,7 +139,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
...
@@ -139,7 +139,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
}
}
if
(
mrb_string_p
(
service
))
{
if
(
mrb_string_p
(
service
))
{
servname
=
mrb_str
_to_cstr
(
mrb
,
service
);
servname
=
mrb_str
ing_value_cstr
(
mrb
,
&
service
);
}
else
if
(
mrb_fixnum_p
(
service
))
{
}
else
if
(
mrb_fixnum_p
(
service
))
{
servname
=
RSTRING_PTR
(
mrb_fixnum_to_str
(
mrb
,
service
,
10
));
servname
=
RSTRING_PTR
(
mrb_fixnum_to_str
(
mrb
,
service
,
10
));
}
else
if
(
mrb_nil_p
(
service
))
{
}
else
if
(
mrb_nil_p
(
service
))
{
...
...
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