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
466ed80b
Commit
466ed80b
authored
Dec 06, 2012
by
Daniel Bovensiepen
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'mruby/master' into mrbgems
parents
be99d87c
40daee12
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
7 deletions
+53
-7
src/parse.y
src/parse.y
+1
-1
src/vm.c
src/vm.c
+29
-6
test/t/exception.rb
test/t/exception.rb
+23
-0
No files found.
src/parse.y
View file @
466ed80b
...
@@ -3316,7 +3316,7 @@ read_escape(parser_state *p)
...
@@ -3316,7 +3316,7 @@ read_escape(parser_state *p)
break;
break;
}
}
}
}
c = scan_oct(buf, i
+1
, &i);
c = scan_oct(buf, i, &i);
}
}
return c;
return c;
...
...
src/vm.c
View file @
466ed80b
...
@@ -38,6 +38,19 @@
...
@@ -38,6 +38,19 @@
#define STACK_INIT_SIZE 128
#define STACK_INIT_SIZE 128
#define CALLINFO_INIT_SIZE 32
#define CALLINFO_INIT_SIZE 32
/* Define amount of linear stack growth. */
#ifndef MRB_STACK_GROWTH
#define MRB_STACK_GROWTH 128
#endif
/* Maximum stack depth. Should be set lower on memory constrained systems.
The value below allows about 60000 recursive calls in the simplest case. */
#ifndef MRB_STACK_MAX
#define MRB_STACK_MAX ((1<<18) - MRB_STACK_GROWTH)
#endif
static
inline
void
static
inline
void
stack_copy
(
mrb_value
*
dst
,
const
mrb_value
*
src
,
size_t
size
)
stack_copy
(
mrb_value
*
dst
,
const
mrb_value
*
src
,
size_t
size
)
{
{
...
@@ -79,29 +92,39 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase)
...
@@ -79,29 +92,39 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase)
}
}
}
}
/** def rec ; $deep =+ 1 ; if $deep > 1000 ; return 0 ; end ; rec ; end */
static
void
static
void
stack_extend
(
mrb_state
*
mrb
,
int
room
,
int
keep
)
stack_extend
(
mrb_state
*
mrb
,
int
room
,
int
keep
)
{
{
int
size
,
off
;
int
size
,
off
;
if
(
mrb
->
stack
+
room
>=
mrb
->
stend
)
{
if
(
mrb
->
stack
+
room
>=
mrb
->
stend
)
{
mrb_value
*
oldbase
=
mrb
->
stbase
;
mrb_value
*
oldbase
=
mrb
->
stbase
;
size
=
mrb
->
stend
-
mrb
->
stbase
;
size
=
mrb
->
stend
-
mrb
->
stbase
;
off
=
mrb
->
stack
-
mrb
->
stbase
;
off
=
mrb
->
stack
-
mrb
->
stbase
;
if
(
room
<=
size
)
/* double size is enough? */
/* Use linear stack growth.
size
*=
2
;
It is slightly slower than doubling thestack space,
but it saves memory on small devices. */
if
(
room
<=
size
)
size
+=
MRB_STACK_GROWTH
;
else
else
size
+=
room
;
size
+=
room
;
mrb
->
stbase
=
(
mrb_value
*
)
mrb_realloc
(
mrb
,
mrb
->
stbase
,
sizeof
(
mrb_value
)
*
size
);
mrb
->
stbase
=
(
mrb_value
*
)
mrb_realloc
(
mrb
,
mrb
->
stbase
,
sizeof
(
mrb_value
)
*
size
);
mrb
->
stack
=
mrb
->
stbase
+
off
;
mrb
->
stack
=
mrb
->
stbase
+
off
;
mrb
->
stend
=
mrb
->
stbase
+
size
;
mrb
->
stend
=
mrb
->
stbase
+
size
;
envadjust
(
mrb
,
oldbase
,
mrb
->
stbase
);
envadjust
(
mrb
,
oldbase
,
mrb
->
stbase
);
/* Raise an exception if the new stack size will be too large,
to prevent infinite recursion. However, do this only after resizing the stack, so mrb_raisef has stack space to work with. */
if
(
size
>
MRB_STACK_MAX
)
{
mrb_raisef
(
mrb
,
E_RUNTIME_ERROR
,
"stack level too deep. (limit=%d)"
,
MRB_STACK_MAX
);
}
}
}
if
(
room
>
keep
)
{
if
(
room
>
keep
)
{
int
i
;
int
i
;
for
(
i
=
keep
;
i
<
room
;
i
++
)
{
for
(
i
=
keep
;
i
<
room
;
i
++
)
{
#ifndef MRB_NAN_BOXING
#ifndef MRB_NAN_BOXING
static
const
mrb_value
mrb_value_zero
=
{
{
0
}
};
static
const
mrb_value
mrb_value_zero
=
{
{
0
}
};
...
...
test/t/exception.rb
View file @
466ed80b
...
@@ -290,3 +290,26 @@ end
...
@@ -290,3 +290,26 @@ end
assert
(
'Exception#inspect without message'
)
do
assert
(
'Exception#inspect without message'
)
do
Exception
.
new
.
inspect
Exception
.
new
.
inspect
end
end
# very deeply recursive function that stil returns albeit very deeply so
$test_infinite_recursion
=
0
TEST_INFINITE_RECURSION_MAX
=
100000
def
test_infinite_recursion
$test_infinite_recursion
+=
1
if
$test_infinite_recursion
>
TEST_INFINITE_RECURSION_MAX
return
$test_infinite_recursion
end
test_infinite_recursion
end
assert
(
'Infinite recursion should result in an exception being raised'
)
do
a
=
begin
test_infinite_recursion
rescue
:ok
end
# OK if an exception was caught, otherwise a number will be stored in a
a
==
:ok
end
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