Skip to content

Commit

Permalink
fixed #12 build failure in PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Joungkyun committed Feb 15, 2022
1 parent 34eb69e commit e23919a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
58 changes: 34 additions & 24 deletions magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,50 +155,52 @@ static void magic_set_error (int type, const char * format, ...) {
va_list args;
char * buffer = NULL;
int buffer_len = 0;
size_t maxlen = 0;
#if PHP_VERSION_ID >= 80000
zend_string * zbuffer;
#endif

// php_error_cb in main.c
va_start (args, format);
buffer_len = vspprintf (&buffer, PG(log_errors_max_len), format, args);
#if PHP_VERSION_ID < 80100
maxlen = PG(log_errors_max_len);
#endif
buffer_len = vspprintf (&buffer, maxlen, format, args);
va_end (args);

#if PHP_VERSION_ID >= 80000
zbuffer = zend_string_init (buffer, buffer_len, 0);
#endif

#if PHP_VERSION_ID >= 80000
if (PG(last_error_message)) {
zend_string_release(PG(last_error_message));
PG(last_error_message) = NULL;
}
if (PG(last_error_file)) {
free(PG(last_error_file));
PG(last_error_file) = NULL;
}
#else
if ( PG (last_error_message) ) {
#if PHP_VERSION_ID >= 70200
char * s = PG(last_error_message);
PG(last_error_message) = NULL;
#if PHP_VERSION_ID >= 80000
zend_string_release (PG (last_error_message));
#elif PHP_VERSION_ID >= 70200
char * s = PG (last_error_message);
PG (last_error_message) = NULL;
free (s);
#else
#else
free (PG (last_error_message));
PG (last_error_message) = NULL;
#endif
}
if ( PG(last_error_file) ) {
#if PHP_VERSION_ID >= 70200
char * s = PG(last_error_file);
#endif
PG(last_error_file) = NULL;
}

if ( PG (last_error_file) ) {
#if PHP_VERSION_ID >= 80100
zend_string_release (PG (last_error_file));
#elif PHP_VERSION_ID >= 80000
free (PG (last_error_file));
#elif PHP_VERSION_ID >= 70200
char * s = PG (last_error_file);
PG (last_error_file) = NULL;
free (s);
#else
#else
free (PG (last_error_file));
#endif
PG (last_error_file) = NULL;
#endif
}
#endif


PG (last_error_lineno) = 0;

/*
Expand All @@ -215,10 +217,18 @@ static void magic_set_error (int type, const char * format, ...) {
PG (last_error_message) = strdup (buffer);
#endif
if ( zend_is_compiling () ) {
#if PHP_VERSION_ID >= 80100
PG (last_error_file) = zend_string_copy (zend_get_compiled_filename ());
#else
PG (last_error_file) = strdup (ZSTR_VAL (zend_get_compiled_filename ()));
#endif
PG (last_error_lineno) = zend_get_compiled_lineno ();
} else if ( zend_is_executing () ) {
#if PHP_VERSION_ID >= 80100
PG (last_error_file) = zend_string_copy (zend_get_executed_filename_ex ());
#else
PG (last_error_file) = strdup (zend_get_executed_filename ());
#endif
PG (last_error_lineno) = zend_get_executed_lineno ();
}

Expand Down
2 changes: 2 additions & 0 deletions package.xml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<license uri="https://raw.githubusercontent.com/OOPS-ORG-PHP/mod_magic/master/LICENSE">BSD 3-Clause</license>
<notes>
- #11 make test 007 failure on PHP 7.2 and after
- #12 build failure in PHP 8.1
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -66,6 +67,7 @@
<date>@curdate@</date>
<notes>
- #11 make test 007 failure on PHP 7.2 and after
- #12 build failure in PHP 8.1
</notes>
</release>
<release>
Expand Down
2 changes: 1 addition & 1 deletion tests/008-error-get-last.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ( filemagic ('modules/magic.so1') == false ) {
if ( $p['type'] == E_WARNING )
$s = 'E_WARNING';
else
$s = 'E_UNKNONW';
$s = 'E_UNKNOWN';
printf ("%s: %s\n", $s, $p['message']);
}
?>
Expand Down

0 comments on commit e23919a

Please sign in to comment.