Skip to content

Commit f02b44b

Browse files
committed
make memory_limit a size_t internally
1 parent 51335bf commit f02b44b

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

v8js_class.cc

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ static void v8js_compile_script(zval *this_ptr, const zend_string *str, const ze
654654
return;
655655
}
656656

657-
static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, long memory_limit, zval **return_value)
657+
static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, size_t memory_limit, zval **return_value)
658658
{
659659
v8js_ctx *c = Z_V8JS_CTX_OBJ_P(this_ptr);
660660

@@ -702,13 +702,19 @@ static PHP_METHOD(V8Js, executeString)
702702
return;
703703
}
704704

705+
if (memory_limit < 0) {
706+
zend_throw_exception(php_ce_v8js_exception,
707+
"memory_limit must not be negative", 0);
708+
return;
709+
}
710+
705711
v8js_compile_script(getThis(), str, identifier, &res);
706712
if (!res) {
707713
RETURN_FALSE;
708714
}
709715

710716
zend_try {
711-
v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value);
717+
v8js_execute_script(getThis(), res, flags, time_limit, static_cast<size_t>(memory_limit), &return_value);
712718
v8js_script_free(res);
713719
}
714720
zend_catch {
@@ -757,11 +763,17 @@ static PHP_METHOD(V8Js, executeScript)
757763
return;
758764
}
759765

766+
if (memory_limit < 0) {
767+
zend_throw_exception(php_ce_v8js_exception,
768+
"memory_limit must not be negative", 0);
769+
return;
770+
}
771+
760772
if((res = (v8js_script *)zend_fetch_resource(Z_RES_P(zscript), PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script)) == NULL) {
761773
RETURN_FALSE;
762774
}
763775

764-
v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value);
776+
v8js_execute_script(getThis(), res, flags, time_limit, static_cast<size_t>(memory_limit), &return_value);
765777
}
766778
/* }}} */
767779

@@ -907,14 +919,20 @@ static PHP_METHOD(V8Js, setMemoryLimit)
907919
return;
908920
}
909921

922+
if (memory_limit < 0) {
923+
zend_throw_exception(php_ce_v8js_exception,
924+
"memory_limit must not be negative", 0);
925+
return;
926+
}
927+
910928
c = Z_V8JS_CTX_OBJ_P(getThis());
911-
c->memory_limit = memory_limit;
929+
c->memory_limit = static_cast<size_t>(memory_limit);
912930

913931
V8JSG(timer_mutex).lock();
914932
for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
915933
it != V8JSG(timer_stack).end(); it ++) {
916934
if((*it)->ctx == c && !(*it)->killed) {
917-
(*it)->memory_limit = memory_limit;
935+
(*it)->memory_limit = static_cast<size_t>(memory_limit);
918936
}
919937
}
920938
V8JSG(timer_mutex).unlock();

v8js_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct v8js_ctx {
4444

4545
long time_limit;
4646
bool time_limit_hit;
47-
long memory_limit;
47+
size_t memory_limit;
4848
bool memory_limit_hit;
4949
long average_object_size;
5050

v8js_timer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void v8js_timer_thread(zend_v8js_globals *globals) /* {{{ */
124124
/* }}} */
125125

126126

127-
void v8js_timer_push(long time_limit, long memory_limit, v8js_ctx *c) /* {{{ */
127+
void v8js_timer_push(long time_limit, size_t memory_limit, v8js_ctx *c) /* {{{ */
128128
{
129129
V8JSG(timer_mutex).lock();
130130

v8js_timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
struct v8js_timer_ctx
1919
{
2020
long time_limit;
21-
long memory_limit;
21+
size_t memory_limit;
2222
std::chrono::time_point<std::chrono::high_resolution_clock> time_point;
2323
v8js_ctx *ctx;
2424
bool killed;
2525
};
2626

2727
void v8js_timer_thread(zend_v8js_globals *globals);
28-
void v8js_timer_push(long time_limit, long memory_limit, v8js_ctx *c);
28+
void v8js_timer_push(long time_limit, size_t memory_limit, v8js_ctx *c);
2929

3030
#endif /* V8JS_TIMER_H */
3131

v8js_v8.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void v8js_v8_init() /* {{{ */
9595
* heap allocated memory).
9696
*/
9797
void v8js_v8_call(v8js_ctx *c, zval **return_value,
98-
long flags, long time_limit, long memory_limit,
98+
long flags, long time_limit, size_t memory_limit,
9999
std::function< v8::Local<v8::Value>(v8::Isolate *) >& v8_call) /* {{{ */
100100
{
101101
char *tz = NULL;

v8js_v8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static inline const char * ToCString(const v8::String::Utf8Value &value) /* {{{
5353

5454
void v8js_v8_init();
5555
void v8js_v8_call(v8js_ctx *c, zval **return_value,
56-
long flags, long time_limit, long memory_limit,
56+
long flags, long time_limit, size_t memory_limit,
5757
std::function< v8::Local<v8::Value>(v8::Isolate *) >& v8_call);
5858
void v8js_terminate_execution(v8::Isolate *isolate);
5959

0 commit comments

Comments
 (0)