Skip to content

Commit

Permalink
Fix for time limit constraints.
Browse files Browse the repository at this point in the history
The root bug I think has to do with conversions between integral types. I
changed the Context.max_time method to be a bit less clever which will hopefully
fix things. I also updated the test_exceeds_time to fail more gracefully as per
suggestion.

Thanks to Mike West

[#15 state:open]
  • Loading branch information
davisp committed May 16, 2009
1 parent 1fe8f08 commit 4134ea6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions THANKS
Expand Up @@ -14,3 +14,8 @@ sk89q

spahl
* Heads up on the signal hack and fix for a compiler warning.

Mike West
* Reported bug in Context.max_time
* Better test for test_exceeds_time

8 changes: 4 additions & 4 deletions spidermonkey/context.c
Expand Up @@ -509,13 +509,13 @@ PyObject*
Context_max_time(Context* self, PyObject* args, PyObject* kwargs)
{
PyObject* ret = NULL;
time_t curr_max = (time_t) -1;
time_t new_max = (time_t) -1;
int curr_max = -1;
int new_max = -1;

if(!PyArg_ParseTuple(args, "|I", &new_max)) goto done;
if(!PyArg_ParseTuple(args, "|i", &new_max)) goto done;

curr_max = self->max_time;
if(new_max != ((time_t) -1)) self->max_time = new_max;
if(new_max > 0) self->max_time = (time_t) new_max;

ret = PyLong_FromLong((long) curr_max);

Expand Down
7 changes: 6 additions & 1 deletion tests/test-context.py
Expand Up @@ -38,8 +38,13 @@ def test_get_set_limits(cx):

@t.cx()
def test_exceed_time(cx):
script = """
var time = function() {return (new Date()).getTime();};
var start = time();
while((time() - start) < 2000) {}
"""
cx.max_time(1)
t.raises(SystemError, cx.execute, "while(true) {}")
t.raises(SystemError, cx.execute, script)

@t.cx()
def test_does_not_exceed_time(cx):
Expand Down

0 comments on commit 4134ea6

Please sign in to comment.