Skip to content

Commit

Permalink
Merge pull request #4 from illuusio/fix-php-8.0
Browse files Browse the repository at this point in the history
Fix building on PHP 7.4, 8.0, 8.1 and 8.2
  • Loading branch information
illuusio committed Jan 11, 2023
2 parents 02d9d9b + 821df1b commit 51356f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 38 deletions.
48 changes: 25 additions & 23 deletions blenc.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7.4 - 8.1 |
| PHP Version 7.4 - 8.2 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
| Copyright (c) 2022 Tuukka Pasanen |
| Copyright (c) 2022-2023 Tuukka Pasanen |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
Expand Down Expand Up @@ -587,14 +587,13 @@ zend_op_array *blenc_compile(zend_file_handle *file_handle, int type)
size_t script_len = 0;
zend_op_array *retval = NULL;
blenc_header *header;
zval code;
zend_string *decoded_code = NULL;
zend_bool validated = FALSE;
char *file_name = NULL;
#ifdef PHP_ZEND_ENGINE_7_0
file_name = file_handle->filename;
#endif
#ifdef PHP_ZEND_ENGINE_8_0
file_name = ZSTR_VAL(file_handle->filename);
const char *file_name = NULL;
#if PHP_MAJOR_VERSION == 7 || (PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION < 1)
file_name = file_handle->filename;
#else
file_name = ZSTR_VAL(file_handle->filename);
#endif

/*
Expand Down Expand Up @@ -679,25 +678,28 @@ zend_op_array *blenc_compile(zend_file_handle *file_handle, int type)

}

if(validated && decoded != NULL)
{

ZVAL_STRINGL(&code, (char *)decoded, decoded_len);
#ifdef PHP_ZEND_ENGINE_7_0
retval = zend_compile_string(&code, file_name);
#endif
/* File was not decoded, use standard compiler */
if (!validated || !decoded) {
return zend_compile_file_old(file_handle, type);
}

#ifdef PHP_ZEND_ENGINE_8_0
retval = zend_compile_string(Z_STR(code), file_name);
#endif
decoded_code = zend_string_init((char *)decoded, decoded_len, 0);

} else
{
#if PHP_MAJOR_VERSION == 7
zval code;
ZVAL_STR(&code, decoded_code);
retval = zend_compile_string(&code, (char *)file_name);
#else

retval = zend_compile_file_old(file_handle, type);
#if PHP_MINOR_VERSION < 2
retval = zend_compile_string(decoded_code, file_name);
#else
retval = zend_compile_string(decoded_code, file_name, ZEND_COMPILE_POSITION_AFTER_OPEN_TAG);
#endif

}
#endif

zend_string_release(decoded_code);
return retval;
}

Expand Down
17 changes: 2 additions & 15 deletions php_blenc.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
| PHP Version 7.4 - 8.2 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
| Copyright (c) 2022-2023 Tuukka Pasanen |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
Expand All @@ -26,15 +27,6 @@
#error "PHP version lower than 7.0 is not supported. Please use older release for PHP 5.6"
#endif

#if ZEND_MODULE_API_NO >= 20151012 && ZEND_MODULE_API_NO < 20200930
#define PHP_ZEND_ENGINE_7_0
#endif

#if ZEND_MODULE_API_NO >= 20200930
#define PHP_ZEND_ENGINE_8_0
#endif


#define PHP_BLENC_VERSION "1.1.4b"
#define BLENC_IDENT "BLENC"
#define BLENC_BUFSIZE 4092
Expand Down Expand Up @@ -83,12 +75,7 @@ ZEND_END_MODULE_GLOBALS(blenc)

size_t (*old_stream_reader)(void *, char *, size_t);
void (*old_stream_closer)(void *);
#ifdef PHP_ZEND_ENGINE_7_0
zend_op_array *(*zend_compile_file_old)(zend_file_handle *, int);
#endif
#ifdef PHP_ZEND_ENGINE_8_0
zend_op_array *(*zend_compile_file_old)(zend_file_handle *, int);
#endif
zend_op_array *blenc_compile(zend_file_handle *, int);

static void php_blenc_make_md5(char *, void *, size_t);
Expand Down

0 comments on commit 51356f1

Please sign in to comment.