Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Remove limit propertis from V8\Isolate
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed Apr 28, 2017
1 parent ed72501 commit 04d9e6f
Show file tree
Hide file tree
Showing 46 changed files with 248 additions and 1,553 deletions.
55 changes: 39 additions & 16 deletions scripts/replace_expect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@
$tests_dir = realpath(__DIR__ . '/../tests');


if ($argc == 2) {
$mask = str_replace(['tests/', '.phpt', '.diff'], '', $argv[1]);
$mode = 'write';

$args = $argv;
unset($args[0]);

foreach ($argv as $i => $item) {
if ($item == '--pretend') {
$mode = 'pretend';
unset($args[$i]);
}
}

if (count($args) > 1) {
echo 'Invalid options', PHP_EOL;
exit(1);
}

if ($args) {
$mask = str_replace(['tests/', '.phpt', '.diff'], '', array_pop($args));
} else {
$mask = '*';
}
Expand All @@ -25,41 +42,41 @@

foreach ($iterator as $item) {
//var_dump($item);
$out_file = $iterator->key();
$out_file = $iterator->key();
$base_name = preg_replace('/\.out$/i', '', $iterator->key());
$test_file = $base_name .'.phpt';
$test_file = $base_name . '.phpt';

$test_content = file_get_contents($tests_dir . '/' . $test_file);

if (false !== ($pos = strpos($test_content, '--EXPECT--'))) {
printf("--EXPECT-- [%s]".PHP_EOL, $iterator->key());
printf("--EXPECT-- [%s]" . PHP_EOL, $iterator->key());

$test_content = substr($test_content, 0, $pos);
$test_content .= '--EXPECT--'.PHP_EOL;
$test_content .= '--EXPECT--' . PHP_EOL;
$test_content .= file_get_contents($tests_dir . '/' . $out_file);
$test_content .= PHP_EOL;
file_put_contents($tests_dir . '/' . $test_file, $test_content);

foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
@unlink($tests_dir. '/'.$base_name . $ext);
@unlink($tests_dir . '/' . $base_name . $ext);
}

continue;
//} elseif (0) {
//} elseif (0) {
} elseif (false !== ($pos = strpos($test_content, '--EXPECTF--'))) {

printf("--EXPECTF-- [%s]".PHP_EOL, $iterator->key());
printf("--EXPECTF-- [%s]" . PHP_EOL, $iterator->key());

// get replacements

$tests = substr($test_content, 0, $pos);
$tests = substr($test_content, 0, $pos);
$result = file_get_contents($tests_dir . '/' . $out_file);

preg_match_all('#// EXPECTF: \-\-\-(.+)#', $tests, $expectf_search);
preg_match_all('#// EXPECTF: \+\+\+(.+)#', $tests, $expectf_replace);

if (count($expectf_search) != count($expectf_replace)) {
printf("please, edit manually [%s]: searches and replaces count doesn't match".PHP_EOL, $iterator->key());
printf("please, edit manually [%s]: searches and replaces count doesn't match" . PHP_EOL, $iterator->key());
continue;
}

Expand All @@ -68,18 +85,24 @@
}

$test_content = $tests;
$test_content .= '--EXPECTF--'.PHP_EOL;
$test_content .= '--EXPECTF--' . PHP_EOL;
$test_content .= $result;
$test_content .= PHP_EOL;

file_put_contents($tests_dir . '/' . $test_file, $test_content);
if ($mode == 'pretend') {
echo $result, PHP_EOL;
echo PHP_EOL;

foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
@unlink($tests_dir. '/'.$base_name . $ext);
} elseif ($mode = 'write') {
file_put_contents($tests_dir . '/' . $test_file, $test_content);

foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
@unlink($tests_dir . '/' . $base_name . $ext);
}
}

continue;
}

printf("please, edit manually [%s]".PHP_EOL, $iterator->key());
printf("please, edit manually [%s]" . PHP_EOL, $iterator->key());
}
1 change: 0 additions & 1 deletion src/php_v8_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extern void php_v8_throw_try_catch_exception(php_v8_context_t *php_v8_context, v
#define PHP_V8_CATCH_END() } assert(!try_catch.HasCaught());

#define PHP_V8_MAYBE_CATCH(php_v8_context, try_catch) \
php_v8_isolate_maybe_update_limits_hit((php_v8_context)->php_v8_isolate);\
php_v8_isolate_limits_maybe_stop_timer((php_v8_context)->php_v8_isolate);\
if ((try_catch).HasCaught()) { \
php_v8_throw_try_catch_exception((php_v8_context), &(try_catch)); \
Expand Down
40 changes: 4 additions & 36 deletions src/php_v8_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,39 +236,26 @@ static PHP_METHOD(V8Isolate, SetTimeLimit) {
}

php_v8_isolate_limits_set_time_limit(php_v8_isolate, time_limit_in_seconds);

zend_update_property_double(this_ce, getThis(), ZEND_STRL("time_limit"), time_limit_in_seconds);
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("time_limit_hit"), 0);
}

static PHP_METHOD(V8Isolate, GetTimeLimit) {
zval rv;

zval *prop = NULL;
if (zend_parse_parameters_none() == FAILURE) {
return;
}

PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);

prop = zend_read_property(this_ce, getThis(), ZEND_STRL("time_limit"), 0, &rv);

RETVAL_ZVAL(prop, 1, 0);
RETVAL_DOUBLE(php_v8_isolate->limits.time_limit);
}

static PHP_METHOD(V8Isolate, IsTimeLimitHit) {
zval rv;

zval *prop = NULL;
if (zend_parse_parameters_none() == FAILURE) {
return;
}

PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);

prop = zend_read_property(this_ce, getThis(), ZEND_STRL("time_limit_hit"), 0, &rv);

RETVAL_ZVAL(prop, 1, 0);
RETVAL_BOOL(php_v8_isolate->limits.time_limit_hit);
}

static PHP_METHOD(V8Isolate, SetMemoryLimit) {
Expand All @@ -286,39 +273,26 @@ static PHP_METHOD(V8Isolate, SetMemoryLimit) {
}

php_v8_isolate_limits_set_memory_limit(php_v8_isolate, static_cast<size_t>(memory_limit_in_bytes));

zend_update_property_long(this_ce, getThis(), ZEND_STRL("memory_limit"), memory_limit_in_bytes);
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("memory_limit_hit"), 0);
}

static PHP_METHOD(V8Isolate, GetMemoryLimit) {
zval rv;

zval *prop = NULL;
if (zend_parse_parameters_none() == FAILURE) {
return;
}

PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);

prop = zend_read_property(this_ce, getThis(), ZEND_STRL("memory_limit"), 0, &rv);

RETVAL_ZVAL(prop, 1, 0);
RETURN_LONG(php_v8_isolate->limits.memory_limit);
}

static PHP_METHOD(V8Isolate, IsMemoryLimitHit) {
zval rv;

zval *prop = NULL;
if (zend_parse_parameters_none() == FAILURE) {
return;
}

PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);

prop = zend_read_property(this_ce, getThis(), ZEND_STRL("memory_limit_hit"), 0, &rv);

RETVAL_ZVAL(prop, 1, 0);
RETVAL_BOOL(php_v8_isolate->limits.memory_limit_hit);
}

static PHP_METHOD(V8Isolate, GetHeapStatistics) {
Expand Down Expand Up @@ -604,12 +578,6 @@ PHP_MINIT_FUNCTION (php_v8_isolate) {
this_ce = zend_register_internal_class(&ce);
this_ce->create_object = php_v8_isolate_ctor;

zend_declare_property_double(this_ce, ZEND_STRL("time_limit"), 0.0, ZEND_ACC_PRIVATE);
zend_declare_property_bool(this_ce, ZEND_STRL("time_limit_hit"), 0, ZEND_ACC_PRIVATE);

zend_declare_property_long(this_ce, ZEND_STRL("memory_limit"), 0, ZEND_ACC_PRIVATE);
zend_declare_property_bool(this_ce, ZEND_STRL("memory_limit_hit"), 0, ZEND_ACC_PRIVATE);

memcpy(&php_v8_isolate_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));

php_v8_isolate_object_handlers.offset = XtOffsetOf(php_v8_isolate_t, std);
Expand Down
14 changes: 0 additions & 14 deletions src/php_v8_isolate_limits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,6 @@ void php_v8_isolate_limits_ctor(php_v8_isolate_t *php_v8_isolate) {
limits->depth = 0;
}

void php_v8_isolate_maybe_update_limits_hit(php_v8_isolate_t *php_v8_isolate) {
zval isolate_zv;

ZVAL_OBJ(&isolate_zv, &php_v8_isolate->std);
PHP_V8_DECLARE_LIMITS(php_v8_isolate);

if (limits->time_limit) {
zend_update_property_bool(php_v8_isolate_class_entry, &isolate_zv, ZEND_STRL("time_limit_hit"), limits->time_limit_hit);
}
if (limits->memory_limit) {
zend_update_property_bool(php_v8_isolate_class_entry, &isolate_zv, ZEND_STRL("memory_limit_hit"), limits->memory_limit_hit);
}
}

void php_v8_isolate_limits_set_time_limit(php_v8_isolate_t *php_v8_isolate, double time_limit_in_seconds) {
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);
PHP_V8_DECLARE_LIMITS(php_v8_isolate);
Expand Down
1 change: 0 additions & 1 deletion src/php_v8_isolate_limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern void php_v8_isolate_limits_maybe_stop_timer(php_v8_isolate_t *php_v8_isol
extern void php_v8_isolate_limits_free(php_v8_isolate_t *php_v8_isolate);
extern void php_v8_isolate_limits_ctor(php_v8_isolate_t *php_v8_isolate);

extern void php_v8_isolate_maybe_update_limits_hit(php_v8_isolate_t *php_v8_isolate);
extern void php_v8_isolate_limits_set_time_limit(php_v8_isolate_t *php_v8_isolate, double time_limit_in_seconds);
extern void php_v8_isolate_limits_set_memory_limit(php_v8_isolate_t *php_v8_isolate, size_t memory_limit_in_bytes);

Expand Down
Loading

0 comments on commit 04d9e6f

Please sign in to comment.