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
b7031e8b
Unverified
Commit
b7031e8b
authored
Jun 12, 2020
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable NUL (`\0`) again.
parent
52507b10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
17 deletions
+26
-17
mrbgems/mruby-symbol-ext/test/symbol.rb
mrbgems/mruby-symbol-ext/test/symbol.rb
+3
-3
src/symbol.c
src/symbol.c
+23
-14
No files found.
mrbgems/mruby-symbol-ext/test/symbol.rb
View file @
b7031e8b
...
...
@@ -13,13 +13,13 @@ end
%w[size length]
.
each
do
|
n
|
assert
(
"Symbol#
#{
n
}
"
)
do
assert_equal
5
,
:hello
.
__send__
(
n
)
assert_equal
4
,
:"aA
b"
.
__send__
(
n
)
assert_equal
4
,
:"aA
\0
b"
.
__send__
(
n
)
if
__ENCODING__
==
"UTF-8"
assert_equal
8
,
:"こんにちは世界!"
.
__send__
(
n
)
assert_equal
4
,
:"aあ
b"
.
__send__
(
n
)
assert_equal
4
,
:"aあ
\0
b"
.
__send__
(
n
)
else
assert_equal
22
,
:"こんにちは世界!"
.
__send__
(
n
)
assert_equal
6
,
:"aあ
b"
.
__send__
(
n
)
assert_equal
6
,
:"aあ
\0
b"
.
__send__
(
n
)
end
end
end
...
...
src/symbol.c
View file @
b7031e8b
...
...
@@ -16,13 +16,16 @@
#undef MRB_PRESYM_CSYM
#undef MRB_PRESYM_QSYM
#undef MRB_PRESYM_SYM
#define MRB_PRESYM_CSYM(sym, num)
#sym
,
#define MRB_PRESYM_QSYM(str, name, num)
str
,
#define MRB_PRESYM_SYM(str, num)
str
,
#define MRB_PRESYM_CSYM(sym, num)
{#sym,sizeof(#sym)-1}
,
#define MRB_PRESYM_QSYM(str, name, num)
{str,sizeof(str)-1}
,
#define MRB_PRESYM_SYM(str, num)
{str,sizeof(str)-1}
,
static
const
char
*
presym_table
[]
=
{
static
const
struct
{
const
char
*
name
;
uint16_t
len
;
}
presym_table
[]
=
{
#include <../build/presym.inc>
NULL
{
0
,
0
}
};
static
mrb_sym
...
...
@@ -33,9 +36,17 @@ presym_find(const char *name, size_t len)
while
(
start
<=
end
)
{
int
mid
=
(
start
+
end
)
/
2
;
int
cmp
=
strncmp
(
name
,
presym_table
[
mid
],
len
);
size_t
plen
=
presym_table
[
mid
].
len
;
size_t
tlen
=
(
plen
>
len
)
?
len
:
plen
;
int
cmp
;
cmp
=
memcmp
(
name
,
presym_table
[
mid
].
name
,
tlen
);
if
(
cmp
==
0
)
{
if
(
len
>
plen
)
cmp
=
1
;
else
if
(
len
<
plen
)
cmp
=
-
1
;
}
if
(
cmp
==
0
&&
presym_table
[
mid
][
len
]
==
'\0'
)
{
if
(
cmp
==
0
)
{
return
mid
+
1
;
}
else
if
(
cmp
>
0
)
{
start
=
mid
+
1
;
...
...
@@ -47,10 +58,11 @@ presym_find(const char *name, size_t len)
}
static
const
char
*
presym_sym2name
(
mrb_sym
sym
)
presym_sym2name
(
mrb_sym
sym
,
mrb_int
*
lenp
)
{
if
(
sym
>
MRB_PRESYM_MAX
)
return
NULL
;
return
presym_table
[
sym
-
1
];
if
(
lenp
)
*
lenp
=
presym_table
[
sym
-
1
].
len
;
return
presym_table
[
sym
-
1
].
name
;
}
/* ------------------------------------------------------ */
...
...
@@ -307,11 +319,8 @@ sym2name_len(mrb_state *mrb, mrb_sym sym, char *buf, mrb_int *lenp)
sym
>>=
SYMBOL_NORMAL_SHIFT
;
{
const
char
*
name
=
presym_sym2name
(
sym
);
if
(
name
)
{
if
(
lenp
)
*
lenp
=
strlen
(
name
);
return
name
;
}
const
char
*
name
=
presym_sym2name
(
sym
,
lenp
);
if
(
name
)
return
name
;
}
sym
-=
MRB_PRESYM_MAX
;
...
...
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