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

Commit 04d9e6f

Browse files
committed
Remove limit propertis from V8\Isolate
1 parent ed72501 commit 04d9e6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+248
-1553
lines changed

scripts/replace_expect.php

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,25 @@
1515
$tests_dir = realpath(__DIR__ . '/../tests');
1616

1717

18-
if ($argc == 2) {
19-
$mask = str_replace(['tests/', '.phpt', '.diff'], '', $argv[1]);
18+
$mode = 'write';
19+
20+
$args = $argv;
21+
unset($args[0]);
22+
23+
foreach ($argv as $i => $item) {
24+
if ($item == '--pretend') {
25+
$mode = 'pretend';
26+
unset($args[$i]);
27+
}
28+
}
29+
30+
if (count($args) > 1) {
31+
echo 'Invalid options', PHP_EOL;
32+
exit(1);
33+
}
34+
35+
if ($args) {
36+
$mask = str_replace(['tests/', '.phpt', '.diff'], '', array_pop($args));
2037
} else {
2138
$mask = '*';
2239
}
@@ -25,41 +42,41 @@
2542

2643
foreach ($iterator as $item) {
2744
//var_dump($item);
28-
$out_file = $iterator->key();
45+
$out_file = $iterator->key();
2946
$base_name = preg_replace('/\.out$/i', '', $iterator->key());
30-
$test_file = $base_name .'.phpt';
47+
$test_file = $base_name . '.phpt';
3148

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

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

3754
$test_content = substr($test_content, 0, $pos);
38-
$test_content .= '--EXPECT--'.PHP_EOL;
55+
$test_content .= '--EXPECT--' . PHP_EOL;
3956
$test_content .= file_get_contents($tests_dir . '/' . $out_file);
4057
$test_content .= PHP_EOL;
4158
file_put_contents($tests_dir . '/' . $test_file, $test_content);
4259

4360
foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
44-
@unlink($tests_dir. '/'.$base_name . $ext);
61+
@unlink($tests_dir . '/' . $base_name . $ext);
4562
}
4663

4764
continue;
48-
//} elseif (0) {
65+
//} elseif (0) {
4966
} elseif (false !== ($pos = strpos($test_content, '--EXPECTF--'))) {
5067

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

5370
// get replacements
5471

55-
$tests = substr($test_content, 0, $pos);
72+
$tests = substr($test_content, 0, $pos);
5673
$result = file_get_contents($tests_dir . '/' . $out_file);
5774

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

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

@@ -68,18 +85,24 @@
6885
}
6986

7087
$test_content = $tests;
71-
$test_content .= '--EXPECTF--'.PHP_EOL;
88+
$test_content .= '--EXPECTF--' . PHP_EOL;
7289
$test_content .= $result;
7390
$test_content .= PHP_EOL;
7491

75-
file_put_contents($tests_dir . '/' . $test_file, $test_content);
92+
if ($mode == 'pretend') {
93+
echo $result, PHP_EOL;
94+
echo PHP_EOL;
7695

77-
foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
78-
@unlink($tests_dir. '/'.$base_name . $ext);
96+
} elseif ($mode = 'write') {
97+
file_put_contents($tests_dir . '/' . $test_file, $test_content);
98+
99+
foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) {
100+
@unlink($tests_dir . '/' . $base_name . $ext);
101+
}
79102
}
80103

81104
continue;
82105
}
83106

84-
printf("please, edit manually [%s]".PHP_EOL, $iterator->key());
107+
printf("please, edit manually [%s]" . PHP_EOL, $iterator->key());
85108
}

src/php_v8_exceptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ extern void php_v8_throw_try_catch_exception(php_v8_context_t *php_v8_context, v
5050
#define PHP_V8_CATCH_END() } assert(!try_catch.HasCaught());
5151

5252
#define PHP_V8_MAYBE_CATCH(php_v8_context, try_catch) \
53-
php_v8_isolate_maybe_update_limits_hit((php_v8_context)->php_v8_isolate);\
5453
php_v8_isolate_limits_maybe_stop_timer((php_v8_context)->php_v8_isolate);\
5554
if ((try_catch).HasCaught()) { \
5655
php_v8_throw_try_catch_exception((php_v8_context), &(try_catch)); \

src/php_v8_isolate.cc

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -236,39 +236,26 @@ static PHP_METHOD(V8Isolate, SetTimeLimit) {
236236
}
237237

238238
php_v8_isolate_limits_set_time_limit(php_v8_isolate, time_limit_in_seconds);
239-
240-
zend_update_property_double(this_ce, getThis(), ZEND_STRL("time_limit"), time_limit_in_seconds);
241-
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("time_limit_hit"), 0);
242239
}
243240

244241
static PHP_METHOD(V8Isolate, GetTimeLimit) {
245-
zval rv;
246-
247-
zval *prop = NULL;
248242
if (zend_parse_parameters_none() == FAILURE) {
249243
return;
250244
}
251245

252246
PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);
253247

254-
prop = zend_read_property(this_ce, getThis(), ZEND_STRL("time_limit"), 0, &rv);
255-
256-
RETVAL_ZVAL(prop, 1, 0);
248+
RETVAL_DOUBLE(php_v8_isolate->limits.time_limit);
257249
}
258250

259251
static PHP_METHOD(V8Isolate, IsTimeLimitHit) {
260-
zval rv;
261-
262-
zval *prop = NULL;
263252
if (zend_parse_parameters_none() == FAILURE) {
264253
return;
265254
}
266255

267256
PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);
268257

269-
prop = zend_read_property(this_ce, getThis(), ZEND_STRL("time_limit_hit"), 0, &rv);
270-
271-
RETVAL_ZVAL(prop, 1, 0);
258+
RETVAL_BOOL(php_v8_isolate->limits.time_limit_hit);
272259
}
273260

274261
static PHP_METHOD(V8Isolate, SetMemoryLimit) {
@@ -286,39 +273,26 @@ static PHP_METHOD(V8Isolate, SetMemoryLimit) {
286273
}
287274

288275
php_v8_isolate_limits_set_memory_limit(php_v8_isolate, static_cast<size_t>(memory_limit_in_bytes));
289-
290-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("memory_limit"), memory_limit_in_bytes);
291-
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("memory_limit_hit"), 0);
292276
}
293277

294278
static PHP_METHOD(V8Isolate, GetMemoryLimit) {
295-
zval rv;
296-
297-
zval *prop = NULL;
298279
if (zend_parse_parameters_none() == FAILURE) {
299280
return;
300281
}
301282

302283
PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);
303284

304-
prop = zend_read_property(this_ce, getThis(), ZEND_STRL("memory_limit"), 0, &rv);
305-
306-
RETVAL_ZVAL(prop, 1, 0);
285+
RETURN_LONG(php_v8_isolate->limits.memory_limit);
307286
}
308287

309288
static PHP_METHOD(V8Isolate, IsMemoryLimitHit) {
310-
zval rv;
311-
312-
zval *prop = NULL;
313289
if (zend_parse_parameters_none() == FAILURE) {
314290
return;
315291
}
316292

317293
PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);
318294

319-
prop = zend_read_property(this_ce, getThis(), ZEND_STRL("memory_limit_hit"), 0, &rv);
320-
321-
RETVAL_ZVAL(prop, 1, 0);
295+
RETVAL_BOOL(php_v8_isolate->limits.memory_limit_hit);
322296
}
323297

324298
static PHP_METHOD(V8Isolate, GetHeapStatistics) {
@@ -604,12 +578,6 @@ PHP_MINIT_FUNCTION (php_v8_isolate) {
604578
this_ce = zend_register_internal_class(&ce);
605579
this_ce->create_object = php_v8_isolate_ctor;
606580

607-
zend_declare_property_double(this_ce, ZEND_STRL("time_limit"), 0.0, ZEND_ACC_PRIVATE);
608-
zend_declare_property_bool(this_ce, ZEND_STRL("time_limit_hit"), 0, ZEND_ACC_PRIVATE);
609-
610-
zend_declare_property_long(this_ce, ZEND_STRL("memory_limit"), 0, ZEND_ACC_PRIVATE);
611-
zend_declare_property_bool(this_ce, ZEND_STRL("memory_limit_hit"), 0, ZEND_ACC_PRIVATE);
612-
613581
memcpy(&php_v8_isolate_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
614582

615583
php_v8_isolate_object_handlers.offset = XtOffsetOf(php_v8_isolate_t, std);

src/php_v8_isolate_limits.cc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,6 @@ void php_v8_isolate_limits_ctor(php_v8_isolate_t *php_v8_isolate) {
182182
limits->depth = 0;
183183
}
184184

185-
void php_v8_isolate_maybe_update_limits_hit(php_v8_isolate_t *php_v8_isolate) {
186-
zval isolate_zv;
187-
188-
ZVAL_OBJ(&isolate_zv, &php_v8_isolate->std);
189-
PHP_V8_DECLARE_LIMITS(php_v8_isolate);
190-
191-
if (limits->time_limit) {
192-
zend_update_property_bool(php_v8_isolate_class_entry, &isolate_zv, ZEND_STRL("time_limit_hit"), limits->time_limit_hit);
193-
}
194-
if (limits->memory_limit) {
195-
zend_update_property_bool(php_v8_isolate_class_entry, &isolate_zv, ZEND_STRL("memory_limit_hit"), limits->memory_limit_hit);
196-
}
197-
}
198-
199185
void php_v8_isolate_limits_set_time_limit(php_v8_isolate_t *php_v8_isolate, double time_limit_in_seconds) {
200186
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);
201187
PHP_V8_DECLARE_LIMITS(php_v8_isolate);

src/php_v8_isolate_limits.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ extern void php_v8_isolate_limits_maybe_stop_timer(php_v8_isolate_t *php_v8_isol
2929
extern void php_v8_isolate_limits_free(php_v8_isolate_t *php_v8_isolate);
3030
extern void php_v8_isolate_limits_ctor(php_v8_isolate_t *php_v8_isolate);
3131

32-
extern void php_v8_isolate_maybe_update_limits_hit(php_v8_isolate_t *php_v8_isolate);
3332
extern void php_v8_isolate_limits_set_time_limit(php_v8_isolate_t *php_v8_isolate, double time_limit_in_seconds);
3433
extern void php_v8_isolate_limits_set_memory_limit(php_v8_isolate_t *php_v8_isolate, size_t memory_limit_in_bytes);
3534

0 commit comments

Comments
 (0)