Skip to content

Commit e23919a

Browse files
committed
fixed #12 build failure in PHP 8.1
1 parent 34eb69e commit e23919a

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

magic.c

+34-24
Original file line numberDiff line numberDiff line change
@@ -155,50 +155,52 @@ static void magic_set_error (int type, const char * format, ...) {
155155
va_list args;
156156
char * buffer = NULL;
157157
int buffer_len = 0;
158+
size_t maxlen = 0;
158159
#if PHP_VERSION_ID >= 80000
159160
zend_string * zbuffer;
160161
#endif
161162

162163
// php_error_cb in main.c
163164
va_start (args, format);
164-
buffer_len = vspprintf (&buffer, PG(log_errors_max_len), format, args);
165+
#if PHP_VERSION_ID < 80100
166+
maxlen = PG(log_errors_max_len);
167+
#endif
168+
buffer_len = vspprintf (&buffer, maxlen, format, args);
165169
va_end (args);
166170

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

171-
#if PHP_VERSION_ID >= 80000
172-
if (PG(last_error_message)) {
173-
zend_string_release(PG(last_error_message));
174-
PG(last_error_message) = NULL;
175-
}
176-
if (PG(last_error_file)) {
177-
free(PG(last_error_file));
178-
PG(last_error_file) = NULL;
179-
}
180-
#else
181175
if ( PG (last_error_message) ) {
182-
#if PHP_VERSION_ID >= 70200
183-
char * s = PG(last_error_message);
184-
PG(last_error_message) = NULL;
176+
#if PHP_VERSION_ID >= 80000
177+
zend_string_release (PG (last_error_message));
178+
#elif PHP_VERSION_ID >= 70200
179+
char * s = PG (last_error_message);
180+
PG (last_error_message) = NULL;
185181
free (s);
186-
#else
182+
#else
187183
free (PG (last_error_message));
188-
PG (last_error_message) = NULL;
189-
#endif
190-
}
191-
if ( PG(last_error_file) ) {
192-
#if PHP_VERSION_ID >= 70200
193-
char * s = PG(last_error_file);
184+
#endif
194185
PG(last_error_file) = NULL;
186+
}
187+
188+
if ( PG (last_error_file) ) {
189+
#if PHP_VERSION_ID >= 80100
190+
zend_string_release (PG (last_error_file));
191+
#elif PHP_VERSION_ID >= 80000
192+
free (PG (last_error_file));
193+
#elif PHP_VERSION_ID >= 70200
194+
char * s = PG (last_error_file);
195+
PG (last_error_file) = NULL;
195196
free (s);
196-
#else
197+
#else
197198
free (PG (last_error_file));
199+
#endif
198200
PG (last_error_file) = NULL;
199-
#endif
200201
}
201-
#endif
202+
203+
202204
PG (last_error_lineno) = 0;
203205

204206
/*
@@ -215,10 +217,18 @@ static void magic_set_error (int type, const char * format, ...) {
215217
PG (last_error_message) = strdup (buffer);
216218
#endif
217219
if ( zend_is_compiling () ) {
220+
#if PHP_VERSION_ID >= 80100
221+
PG (last_error_file) = zend_string_copy (zend_get_compiled_filename ());
222+
#else
218223
PG (last_error_file) = strdup (ZSTR_VAL (zend_get_compiled_filename ()));
224+
#endif
219225
PG (last_error_lineno) = zend_get_compiled_lineno ();
220226
} else if ( zend_is_executing () ) {
227+
#if PHP_VERSION_ID >= 80100
228+
PG (last_error_file) = zend_string_copy (zend_get_executed_filename_ex ());
229+
#else
221230
PG (last_error_file) = strdup (zend_get_executed_filename ());
231+
#endif
222232
PG (last_error_lineno) = zend_get_executed_lineno ();
223233
}
224234

package.xml.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<license uri="https://raw.githubusercontent.com/OOPS-ORG-PHP/mod_magic/master/LICENSE">BSD 3-Clause</license>
2525
<notes>
2626
- #11 make test 007 failure on PHP 7.2 and after
27+
- #12 build failure in PHP 8.1
2728
</notes>
2829
<contents>
2930
<dir name="/">
@@ -66,6 +67,7 @@
6667
<date>@curdate@</date>
6768
<notes>
6869
- #11 make test 007 failure on PHP 7.2 and after
70+
- #12 build failure in PHP 8.1
6971
</notes>
7072
</release>
7173
<release>

tests/008-error-get-last.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if ( filemagic ('modules/magic.so1') == false ) {
1616
if ( $p['type'] == E_WARNING )
1717
$s = 'E_WARNING';
1818
else
19-
$s = 'E_UNKNONW';
19+
$s = 'E_UNKNOWN';
2020
printf ("%s: %s\n", $s, $p['message']);
2121
}
2222
?>

0 commit comments

Comments
 (0)