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
21f2e536
Commit
21f2e536
authored
Jun 22, 2012
by
Masaki Muranaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use mrb_str_new() instead of mrb_str_new2() as possible.
parent
8946ad2c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
16 deletions
+31
-16
src/array.c
src/array.c
+2
-2
src/numeric.c
src/numeric.c
+15
-8
src/range.c
src/range.c
+6
-1
src/sprintf.c
src/sprintf.c
+1
-1
src/string.c
src/string.c
+5
-2
src/struct.c
src/struct.c
+2
-2
No files found.
src/array.c
View file @
21f2e536
...
...
@@ -887,7 +887,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
/* check recursive */
for
(
i
=
0
;
i
<
RARRAY_LEN
(
list
);
i
++
)
{
if
(
mrb_obj_equal
(
mrb
,
ary
,
RARRAY_PTR
(
list
)[
i
]))
{
return
mrb_str_new
2
(
mrb
,
"[...]"
);
return
mrb_str_new
(
mrb
,
"[...]"
,
5
);
}
}
...
...
@@ -929,7 +929,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
static
mrb_value
mrb_ary_inspect
(
mrb_state
*
mrb
,
mrb_value
ary
)
{
if
(
RARRAY_LEN
(
ary
)
==
0
)
return
mrb_str_new
2
(
mrb
,
"[]"
);
if
(
RARRAY_LEN
(
ary
)
==
0
)
return
mrb_str_new
(
mrb
,
"[]"
,
2
);
#if 0 /* THREAD */
return mrb_exec_recursive(inspect_ary_r, ary, 0);
#else
...
...
src/numeric.c
View file @
21f2e536
...
...
@@ -15,6 +15,7 @@
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <assert.h>
#if defined(__FreeBSD__) && __FreeBSD__ < 4
#include <floatingpoint.h>
...
...
@@ -186,15 +187,21 @@ static mrb_value
flo_to_s
(
mrb_state
*
mrb
,
mrb_value
flt
)
{
char
buf
[
32
];
int
n
;
mrb_float
value
=
mrb_float
(
flt
);
if
(
isinf
(
value
))
return
mrb_str_new2
(
mrb
,
value
<
0
?
"-inf"
:
"inf"
);
else
if
(
isnan
(
value
))
return
mrb_str_new2
(
mrb
,
"NaN"
);
sprintf
(
buf
,
"%.14g"
,
value
);
return
mrb_str_new2
(
mrb
,
buf
);
if
(
isinf
(
value
))
{
static
const
char
s
[
2
][
5
]
=
{
"-inf"
,
"inf"
};
static
const
int
n
[]
=
{
4
,
3
};
int
idx
;
idx
=
(
value
<
0
)
?
0
:
1
;
return
mrb_str_new
(
mrb
,
s
[
idx
],
n
[
idx
]);
}
else
if
(
isnan
(
value
))
return
mrb_str_new
(
mrb
,
"NaN"
,
3
);
n
=
sprintf
(
buf
,
"%.14g"
,
value
);
assert
(
n
>=
0
);
return
mrb_str_new
(
mrb
,
buf
,
n
);
}
/* 15.2.9.3.2 */
...
...
@@ -1158,7 +1165,7 @@ mrb_fix2str(mrb_state *mrb, mrb_value x, int base)
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"invalid radix %d"
,
base
);
}
if
(
val
==
0
)
{
return
mrb_str_new
2
(
mrb
,
"0"
);
return
mrb_str_new
(
mrb
,
"0"
,
1
);
}
if
(
val
<
0
)
{
val
=
-
val
;
...
...
src/range.c
View file @
21f2e536
...
...
@@ -343,7 +343,12 @@ inspect_range(mrb_state *mrb, mrb_value range, mrb_value dummy, int recur)
struct
RRange
*
r
=
mrb_range_ptr
(
range
);
if
(
recur
)
{
return
mrb_str_new2
(
mrb
,
r
->
excl
?
"(... ... ...)"
:
"(... .. ...)"
);
static
const
char
s
[
2
][
14
]
=
{
"(... ... ...)"
,
"(... .. ...)"
};
static
const
int
n
[]
=
{
13
,
12
};
int
idx
;
idx
=
(
r
->
excl
)
?
0
:
1
;
return
mrb_str_new
(
mrb
,
s
[
idx
],
n
[
idx
]);
}
str
=
mrb_inspect
(
mrb
,
r
->
edges
->
beg
);
str2
=
mrb_inspect
(
mrb
,
r
->
edges
->
end
);
...
...
src/sprintf.c
View file @
21f2e536
...
...
@@ -89,7 +89,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
val
&=
0x3ff
;
if
(
val
==
0
)
{
return
mrb_str_new
2
(
mrb
,
"0"
);
return
mrb_str_new
(
mrb
,
"0"
,
1
);
}
*--
b
=
'\0'
;
do
{
...
...
src/string.c
View file @
21f2e536
...
...
@@ -21,6 +21,7 @@
#include "regex.h"
#include "st.h"
#endif //ENABLE_REGEXP
#include <assert.h>
const
char
mrb_digitmap
[]
=
"0123456789abcdefghijklmnopqrstuvwxyz"
;
...
...
@@ -220,7 +221,9 @@ mrb_str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, int len)
mrb_value
mrb_str_new
(
mrb_state
*
mrb
,
const
char
*
p
,
int
len
)
{
struct
RString
*
s
=
str_new
(
mrb
,
p
,
len
);
struct
RString
*
s
;
assert
(
!
(
!
p
&&
len
));
s
=
str_new
(
mrb
,
p
,
len
);
return
mrb_obj_value
(
s
);
}
...
...
@@ -1969,7 +1972,7 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start)
if
(
regs
->
num_regs
==
1
)
{
return
mrb_reg_nth_match
(
mrb
,
0
,
match
);
}
result
=
mrb_ary_new_capa
(
mrb
,
regs
->
num_regs
);
//mrb_ary_new2(regs->num_regs);
result
=
mrb_ary_new_capa
(
mrb
,
regs
->
num_regs
);
for
(
i
=
1
;
i
<
regs
->
num_regs
;
i
++
)
{
mrb_ary_push
(
mrb
,
result
,
mrb_reg_nth_match
(
mrb
,
i
,
match
));
}
...
...
src/struct.c
View file @
21f2e536
...
...
@@ -93,7 +93,7 @@ mrb_struct_s_members_m(mrb_state *mrb, mrb_value klass)
mrb_value
*
p
,
*
pend
;
members
=
mrb_struct_s_members
(
mrb
,
klass
);
ary
=
mrb_ary_new_capa
(
mrb
,
RARRAY_LEN
(
members
));
//mrb_ary_new2(RARRAY_LEN(members));
ary
=
mrb_ary_new_capa
(
mrb
,
RARRAY_LEN
(
members
));
p
=
RARRAY_PTR
(
members
);
pend
=
p
+
RARRAY_LEN
(
members
);
while
(
p
<
pend
)
{
mrb_ary_push
(
mrb
,
ary
,
*
p
);
...
...
@@ -493,7 +493,7 @@ static mrb_value
inspect_struct
(
mrb_state
*
mrb
,
mrb_value
s
,
mrb_value
dummy
,
int
recur
)
{
const
char
*
cn
=
mrb_class_name
(
mrb
,
mrb_obj_class
(
mrb
,
s
));
mrb_value
members
,
str
=
mrb_str_new
2
(
mrb
,
"#<struct "
);
mrb_value
members
,
str
=
mrb_str_new
(
mrb
,
"#<struct "
,
9
);
mrb_value
*
ptr
,
*
ptr_members
;
long
i
,
len
;
...
...
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