diff options
| author | jvoisin | 2022-06-27 20:12:47 +0200 |
|---|---|---|
| committer | jvoisin | 2022-06-27 20:12:47 +0200 |
| commit | 30f1270c26edb6ced469eb302de2fa27befbdbec (patch) | |
| tree | bd6cc9e15a81c607b8751a36673a99d17f555e07 /src | |
| parent | aef97b6b5cb130984ead1a0c3fbc3cdc2037320e (diff) | |
Move compile_file and compile_string to sp_execute.c
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_execute.c | 39 | ||||
| -rw-r--r-- | src/sp_sloppy.c | 41 | ||||
| -rw-r--r-- | src/sp_sloppy.h | 1 |
3 files changed, 41 insertions, 40 deletions
diff --git a/src/sp_execute.c b/src/sp_execute.c index f1ed8d0..b81f408 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c | |||
| @@ -286,6 +286,34 @@ static zend_result sp_stream_open(zend_file_handle *handle) { | |||
| 286 | 286 | ||
| 287 | #endif | 287 | #endif |
| 288 | 288 | ||
| 289 | ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle, | ||
| 290 | int type) = NULL; | ||
| 291 | #if PHP_VERSION_ID >= 80000 | ||
| 292 | ZEND_API zend_op_array* (*orig_zend_compile_string)( | ||
| 293 | zend_string* source_string, const char* filename) = NULL; | ||
| 294 | #else | ||
| 295 | ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string, | ||
| 296 | char* filename) = NULL; | ||
| 297 | #endif | ||
| 298 | |||
| 299 | #if PHP_VERSION_ID >= 80000 | ||
| 300 | ZEND_API zend_op_array* sp_compile_string(zend_string* source_string, | ||
| 301 | const char* filename) { | ||
| 302 | #else | ||
| 303 | ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) { | ||
| 304 | #endif | ||
| 305 | zend_op_array* opline = orig_zend_compile_string(source_string, filename); | ||
| 306 | sp_sloppy_modify_opcode(opline); | ||
| 307 | return opline; | ||
| 308 | } | ||
| 309 | |||
| 310 | ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle, | ||
| 311 | int type) { | ||
| 312 | zend_op_array* opline = orig_zend_compile_file(file_handle, type); | ||
| 313 | sp_sloppy_modify_opcode(opline); | ||
| 314 | return opline; | ||
| 315 | } | ||
| 316 | |||
| 289 | int hook_execute(void) { | 317 | int hook_execute(void) { |
| 290 | TSRMLS_FETCH(); | 318 | TSRMLS_FETCH(); |
| 291 | 319 | ||
| @@ -309,5 +337,16 @@ int hook_execute(void) { | |||
| 309 | } | 337 | } |
| 310 | } | 338 | } |
| 311 | 339 | ||
| 340 | if (NULL == orig_zend_compile_file && zend_compile_file != sp_compile_file) { | ||
| 341 | orig_zend_compile_file = zend_compile_file; | ||
| 342 | zend_compile_file = sp_compile_file; | ||
| 343 | } | ||
| 344 | |||
| 345 | if (NULL == orig_zend_compile_string && | ||
| 346 | zend_compile_string != sp_compile_string) { | ||
| 347 | orig_zend_compile_string = zend_compile_string; | ||
| 348 | zend_compile_string = sp_compile_string; | ||
| 349 | } | ||
| 350 | |||
| 312 | return SUCCESS; | 351 | return SUCCESS; |
| 313 | } | 352 | } |
diff --git a/src/sp_sloppy.c b/src/sp_sloppy.c index fca4be5..2c6ef6a 100644 --- a/src/sp_sloppy.c +++ b/src/sp_sloppy.c | |||
| @@ -1,16 +1,6 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle, | 3 | void sp_sloppy_modify_opcode(zend_op_array* opline) { |
| 4 | int type) = NULL; | ||
| 5 | #if PHP_VERSION_ID >= 80000 | ||
| 6 | ZEND_API zend_op_array* (*orig_zend_compile_string)( | ||
| 7 | zend_string* source_string, const char* filename) = NULL; | ||
| 8 | #else | ||
| 9 | ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string, | ||
| 10 | char* filename) = NULL; | ||
| 11 | #endif | ||
| 12 | |||
| 13 | static void modify_opcode(zend_op_array* opline) { | ||
| 14 | if (NULL != opline) { | 4 | if (NULL != opline) { |
| 15 | for (size_t i = 0; i < opline->last; i++) { | 5 | for (size_t i = 0; i < opline->last; i++) { |
| 16 | zend_op* orig_opline = &(opline->opcodes[i]); | 6 | zend_op* orig_opline = &(opline->opcodes[i]); |
| @@ -25,24 +15,6 @@ static void modify_opcode(zend_op_array* opline) { | |||
| 25 | } | 15 | } |
| 26 | } | 16 | } |
| 27 | 17 | ||
| 28 | #if PHP_VERSION_ID >= 80000 | ||
| 29 | ZEND_API zend_op_array* sp_compile_string(zend_string* source_string, | ||
| 30 | const char* filename) { | ||
| 31 | #else | ||
| 32 | ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) { | ||
| 33 | #endif | ||
| 34 | zend_op_array* opline = orig_zend_compile_string(source_string, filename); | ||
| 35 | modify_opcode(opline); | ||
| 36 | return opline; | ||
| 37 | } | ||
| 38 | |||
| 39 | ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle, | ||
| 40 | int type) { | ||
| 41 | zend_op_array* opline = orig_zend_compile_file(file_handle, type); | ||
| 42 | modify_opcode(opline); | ||
| 43 | return opline; | ||
| 44 | } | ||
| 45 | |||
| 46 | static void array_handler(INTERNAL_FUNCTION_PARAMETERS, const char* name, | 18 | static void array_handler(INTERNAL_FUNCTION_PARAMETERS, const char* name, |
| 47 | size_t size, zif_handler orig_handler, | 19 | size_t size, zif_handler orig_handler, |
| 48 | const char* spec) { | 20 | const char* spec) { |
| @@ -99,17 +71,6 @@ PHP_FUNCTION(sp_array_keys) { | |||
| 99 | void hook_sloppy() { | 71 | void hook_sloppy() { |
| 100 | TSRMLS_FETCH(); | 72 | TSRMLS_FETCH(); |
| 101 | 73 | ||
| 102 | if (NULL == orig_zend_compile_file && zend_compile_file != sp_compile_file) { | ||
| 103 | orig_zend_compile_file = zend_compile_file; | ||
| 104 | zend_compile_file = sp_compile_file; | ||
| 105 | } | ||
| 106 | |||
| 107 | if (NULL == orig_zend_compile_string && | ||
| 108 | zend_compile_string != sp_compile_string) { | ||
| 109 | orig_zend_compile_string = zend_compile_string; | ||
| 110 | zend_compile_string = sp_compile_string; | ||
| 111 | } | ||
| 112 | |||
| 113 | HOOK_FUNCTION("in_array", sp_internal_functions_hook, PHP_FN(sp_in_array)); | 74 | HOOK_FUNCTION("in_array", sp_internal_functions_hook, PHP_FN(sp_in_array)); |
| 114 | HOOK_FUNCTION("array_search", sp_internal_functions_hook, | 75 | HOOK_FUNCTION("array_search", sp_internal_functions_hook, |
| 115 | PHP_FN(sp_array_search)); | 76 | PHP_FN(sp_array_search)); |
diff --git a/src/sp_sloppy.h b/src/sp_sloppy.h index cd9f304..4c5d121 100644 --- a/src/sp_sloppy.h +++ b/src/sp_sloppy.h | |||
| @@ -4,5 +4,6 @@ | |||
| 4 | #include "zend_vm.h" | 4 | #include "zend_vm.h" |
| 5 | 5 | ||
| 6 | void hook_sloppy(void); | 6 | void hook_sloppy(void); |
| 7 | void sp_sloppy_modify_opcode(zend_op_array* opline); | ||
| 7 | 8 | ||
| 8 | #endif | 9 | #endif |
