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
37bc343e
Commit
37bc343e
authored
Feb 06, 2019
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable `Symbol.all_symbols`.
parent
06ba5905
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
9 deletions
+18
-9
include/mrbconf.h
include/mrbconf.h
+1
-0
mrbgems/mruby-symbol-ext/src/symbol.c
mrbgems/mruby-symbol-ext/src/symbol.c
+4
-5
mrbgems/mruby-symbol-ext/test/symbol.rb
mrbgems/mruby-symbol-ext/test/symbol.rb
+7
-4
src/symbol.c
src/symbol.c
+6
-0
No files found.
include/mrbconf.h
View file @
37bc343e
...
...
@@ -120,6 +120,7 @@
/* -DMRB_ENABLE_XXXX to enable following features */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
//#define MRB_ENABLE_ALL_SYMBOLS /* Symbols.all_symbols */
/* end of configuration */
...
...
mrbgems/mruby-symbol-ext/src/symbol.c
View file @
37bc343e
...
...
@@ -3,11 +3,6 @@
#include <mruby/array.h>
#include <mruby/string.h>
typedef
struct
symbol_name
{
size_t
len
;
const
char
*
name
;
}
symbol_name
;
/*
* call-seq:
* Symbol.all_symbols => array
...
...
@@ -23,6 +18,7 @@ typedef struct symbol_name {
* :Tms, :getwd, :$=, :ThreadGroup,
* :wait2, :$>]
*/
#ifdef MRB_ENABLE_ALL_SYMBOLS
static
mrb_value
mrb_sym_all_symbols
(
mrb_state
*
mrb
,
mrb_value
self
)
{
...
...
@@ -36,6 +32,7 @@ mrb_sym_all_symbols(mrb_state *mrb, mrb_value self)
return
ary
;
}
#endif
/*
* call-seq:
...
...
@@ -61,7 +58,9 @@ void
mrb_mruby_symbol_ext_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
s
=
mrb
->
symbol_class
;
#ifdef MRB_ENABLE_ALL_SYMBOLS
mrb_define_class_method
(
mrb
,
s
,
"all_symbols"
,
mrb_sym_all_symbols
,
MRB_ARGS_NONE
());
#endif
mrb_define_method
(
mrb
,
s
,
"length"
,
mrb_sym_length
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
s
,
"size"
,
mrb_sym_length
,
MRB_ARGS_NONE
());
}
...
...
mrbgems/mruby-symbol-ext/test/symbol.rb
View file @
37bc343e
# coding: utf-8
##
# Symbol(Ext) Test
assert
(
'Symbol.all_symbols'
)
do
if
Symbol
.
respond_to?
(
:all_symbols
)
assert
(
'Symbol.all_symbols'
)
do
foo
=
[
:__symbol_test_1
,
:__symbol_test_2
,
:__symbol_test_3
].
sort
symbols
=
Symbol
.
all_symbols
.
select
{
|
sym
|
sym
.
to_s
.
include?
'__symbol_test'
}.
sort
assert_equal
foo
,
symbols
end
end
%w[size length]
.
each
do
|
n
|
...
...
src/symbol.c
View file @
37bc343e
...
...
@@ -28,6 +28,7 @@ sym_validate_len(mrb_state *mrb, size_t len)
}
}
#ifndef MRB_ENABLE_ALL_SYMBOLS
static
char
pack_table
[]
=
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
static
mrb_sym
...
...
@@ -100,6 +101,7 @@ sym_inline_unpack(mrb_sym sym, char *buf)
buf
[
i
]
=
'\0'
;
return
buf
;
}
#endif
uint8_t
symhash
(
const
char
*
key
,
size_t
len
)
...
...
@@ -123,9 +125,11 @@ find_symbol(mrb_state *mrb, const char *name, uint16_t len, uint8_t hash)
mrb_sym
i
;
symbol_name
*
sname
;
#ifndef MRB_ENABLE_ALL_SYMBOLS
/* inline symbol */
i
=
sym_inline_pack
(
name
,
len
);
if
(
i
>
0
)
return
i
;
#endif
i
=
mrb
->
symhash
[
hash
];
if
(
i
==
0
)
return
0
;
...
...
@@ -247,11 +251,13 @@ mrb_check_intern_str(mrb_state *mrb, mrb_value str)
MRB_API
const
char
*
mrb_sym2name_len
(
mrb_state
*
mrb
,
mrb_sym
sym
,
mrb_int
*
lenp
)
{
#ifndef MRB_ENABLE_ALL_SYMBOLS
if
(
sym
&
1
)
{
/* inline packed symbol */
sym_inline_unpack
(
sym
,
mrb
->
symbuf
);
if
(
lenp
)
*
lenp
=
strlen
(
mrb
->
symbuf
);
return
mrb
->
symbuf
;
}
#endif
sym
>>=
1
;
if
(
sym
==
0
||
mrb
->
symidx
<
sym
)
{
...
...
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