Skip to content

Commit d95cab0

Browse files
committed
Support PHP 8
1 parent 7cff10a commit d95cab0

28 files changed

+378
-173
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@
4444
*.autosave
4545
/unrar/.libs
4646
/tmp-php.ini
47+
/php-rar.creator.user
48+
/compile_commands.json
49+
/.clangd

azure-pipelines.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ jobs:
22
- template: azure-template.yml
33
parameters:
44
name: php_5_3_valgrind
5-
displayName: PHP 5.3 (valgrind, clang)
5+
displayName: PHP 5.3 ZTS (valgrind, clang)
66
phpVersion: '5.3'
77
clang: true
88
valgrind: true
9-
10-
- template: azure-template.yml
11-
parameters:
12-
name: php_5_3_zts
13-
displayName: PHP 5.3 ZTS
14-
phpVersion: '5.3'
159
zts: true
1610

1711
- template: azure-template.yml
@@ -73,3 +67,18 @@ jobs:
7367
clang: true
7468
valgrind: true
7569
zts: true
70+
71+
- template: azure-template.yml
72+
parameters:
73+
name: php_8_0
74+
displayName: PHP 8.0 ZTS
75+
phpVersion: '8.0'
76+
zts: true
77+
78+
- template: azure-template.yml
79+
parameters:
80+
name: php_8_0_valgrind
81+
displayName: PHP 8.0 (valgrind, clang)
82+
phpVersion: '8.0'
83+
clang: true
84+
valgrind: true

azure-template.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ jobs:
1515
vmImage: ${{ parameters.imageName }}
1616

1717
variables:
18-
TESTOPTS: -v
19-
gem: /opt/ruby/${{ parameters.rubyVersion }}/bin/gem
20-
bundle: /opt/ruby/${{ parameters.rubyVersion }}/bin/bundle
21-
GEM_HOME: /opt/ruby/${{ parameters.rubyVersion }}/lib/ruby/gems/${{ parameters.rubyVersion }}.0
2218
${{ if eq(parameters.clang, true) }}:
2319
CC: clang
2420
CXX: clang++

php-rar.files

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
config.h
2+
php_compat.h
3+
php_compat.h
24
php_rar.h
35
rar.c
46
rar_error.c

php_compat.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include <php.h>
2+
3+
#if PHP_MAJOR_VERSION >= 8
4+
# define TSRMLS_DC
5+
# define TSRMLS_D
6+
# define TSRMLS_CC
7+
# define TSRMLS_C
8+
# define TSRMLS_FETCH()
9+
# define IS_CALLABLE_STRICT 0
10+
# define zend_qsort zend_sort
11+
# define ZV_TO_THIS_FOR_HANDLER(zv) (Z_OBJ_P(zv))
12+
typedef zend_object handler_this_t;
13+
#else
14+
# define ZV_TO_THIS_FOR_HANDLER(zv) (zv)
15+
typedef zval handler_this_t;
16+
#endif
17+
18+
#if PHP_MAJOR_VERSION >= 7
19+
typedef zend_object* rar_obj_ref;
20+
21+
#define rar_zval_add_ref(ppzv) zval_add_ref(*ppzv)
22+
23+
#define ZVAL_ALLOC_DUP(dst, src) \
24+
do { \
25+
dst = (zval*) emalloc(sizeof(zval)); \
26+
ZVAL_DUP(dst, src); \
27+
} while (0)
28+
29+
#define RAR_RETURN_STRINGL(s, l, duplicate) \
30+
do { \
31+
RETVAL_STRINGL(s, l); \
32+
if (duplicate == 0) { \
33+
efree(s); \
34+
} \
35+
return; \
36+
} while (0)
37+
38+
#define RAR_ZVAL_STRING(z, s, duplicate) \
39+
do { \
40+
ZVAL_STRING(z, s); \
41+
if (duplicate == 0) { \
42+
efree(s); \
43+
} \
44+
} while (0)
45+
46+
typedef size_t zpp_s_size_t;
47+
48+
#define MAKE_STD_ZVAL(zv_p) \
49+
do { \
50+
(zv_p) = emalloc(sizeof(zval)); \
51+
ZVAL_NULL(zv_p); \
52+
} while (0)
53+
#define INIT_ZVAL(zv) ZVAL_UNDEF(&zv)
54+
55+
#define ZEND_ACC_FINAL_CLASS ZEND_ACC_FINAL
56+
57+
#else /* PHP 5.x */
58+
typedef zend_object_handle rar_obj_ref;
59+
60+
#define rar_zval_add_ref zval_add_ref
61+
#define ZVAL_ALLOC_DUP(dst, src) \
62+
do { \
63+
zval *z_src = src; \
64+
dst = z_src; \
65+
zval_add_ref(&dst); \
66+
SEPARATE_ZVAL(&dst); \
67+
} while (0)
68+
#define RAR_ZVAL_STRING ZVAL_STRING
69+
#define RAR_RETURN_STRINGL(s, l, duplicate) RETURN_STRINGL(s, l, duplicate)
70+
typedef int zpp_s_size_t;
71+
#define zend_hash_str_del zend_hash_del
72+
#endif

php_rar.h

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ extern zend_module_entry rar_module_entry;
6363
#include "TSRM.h"
6464
#endif
6565

66+
#include "php_compat.h"
67+
6668
/* causes linking errors (multiple definitions) in functions
6769
that were requested inlining but were not inlined by the compiler */
6870
/* #include "unrar/rar.hpp */
@@ -87,63 +89,6 @@ enum FILE_SYSTEM_REDIRECT {
8789
/* maximum comment size if 64KB */
8890
#define RAR_MAX_COMMENT_SIZE 65536
8991

90-
/* PHP 7+ abstraction */
91-
#if PHP_MAJOR_VERSION >= 7
92-
typedef zend_object* rar_obj_ref;
93-
94-
#define rar_zval_add_ref(ppzv) zval_add_ref(*ppzv)
95-
96-
#define ZVAL_ALLOC_DUP(dst, src) \
97-
do { \
98-
dst = (zval*) emalloc(sizeof(zval)); \
99-
ZVAL_DUP(dst, src); \
100-
} while (0)
101-
102-
#define RAR_RETURN_STRINGL(s, l, duplicate) \
103-
do { \
104-
RETVAL_STRINGL(s, l); \
105-
if (duplicate == 0) { \
106-
efree(s); \
107-
} \
108-
return; \
109-
} while (0)
110-
111-
#define RAR_ZVAL_STRING(z, s, duplicate) \
112-
do { \
113-
ZVAL_STRING(z, s); \
114-
if (duplicate == 0) { \
115-
efree(s); \
116-
} \
117-
} while (0)
118-
119-
typedef size_t zpp_s_size_t;
120-
121-
#define MAKE_STD_ZVAL(zv_p) \
122-
do { \
123-
(zv_p) = emalloc(sizeof(zval)); \
124-
ZVAL_NULL(zv_p); \
125-
} while (0)
126-
#define INIT_ZVAL(zv) ZVAL_UNDEF(&zv)
127-
128-
#define ZEND_ACC_FINAL_CLASS ZEND_ACC_FINAL
129-
130-
#else /* PHP 5.x */
131-
typedef zend_object_handle rar_obj_ref;
132-
133-
#define rar_zval_add_ref zval_add_ref
134-
#define ZVAL_ALLOC_DUP(dst, src) \
135-
do { \
136-
zval *z_src = src; \
137-
dst = z_src; \
138-
zval_add_ref(&dst); \
139-
SEPARATE_ZVAL(&dst); \
140-
} while (0)
141-
#define RAR_ZVAL_STRING ZVAL_STRING
142-
#define RAR_RETURN_STRINGL(s, l, duplicate) RETURN_STRINGL(s, l, duplicate)
143-
typedef int zpp_s_size_t;
144-
#define zend_hash_str_del zend_hash_del
145-
#endif
146-
14792
typedef struct _rar_cb_user_data {
14893
char *password; /* can be NULL */
14994
zval *callable; /* can be NULL */
@@ -333,8 +278,9 @@ void _rar_close_file_resource(rar_file_t *rar);
333278
/* Fetches the rar_file_t part of the RarArchive object in order to use the
334279
* operations above and (discouraged) to have direct access to the fields
335280
* RarEntry::extract/getStream access extract_open_dat and cb_userdata */
336-
int _rar_get_file_resource(zval *zval_file, rar_file_t **rar_file TSRMLS_DC);
337-
int _rar_get_file_resource_ex(zval *zval_file, rar_file_t **rar_file, int silent TSRMLS_DC);
281+
int _rar_get_file_resource_zv(zval *zv_file, rar_file_t **rar_file TSRMLS_DC);
282+
int _rar_get_file_resource_zv_ex(zval *zv_file, rar_file_t **rar_file, int silent TSRMLS_DC);
283+
int _rar_get_file_resource_ex(rar_obj_ref objref_file, rar_file_t **rar_file, int silent TSRMLS_DC);
338284
void minit_rararch(TSRMLS_D);
339285

340286
PHP_FUNCTION(rar_open);

rar_stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ static int _rar_get_cachable_rararch(php_stream_wrapper *wrapper,
10721072
int res;
10731073
const char *err_str;
10741074

1075-
if (_rar_get_file_resource_ex(rar_obj, rar, 1 TSRMLS_CC)
1075+
if (_rar_get_file_resource_zv_ex(rar_obj, rar, 1 TSRMLS_CC)
10761076
== FAILURE) {
10771077
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC,
10781078
"Bug: could not retrieve RarArchive object from zval");
@@ -1096,7 +1096,7 @@ static int _rar_get_cachable_rararch(php_stream_wrapper *wrapper,
10961096
else { /* cache hit */
10971097
/* cache get already put the value in rar_obj and incremented the
10981098
* refcount of the object */
1099-
if (_rar_get_file_resource_ex(rar_obj, rar, 1 TSRMLS_CC) == FAILURE) {
1099+
if (_rar_get_file_resource_zv_ex(rar_obj, rar, 1 TSRMLS_CC) == FAILURE) {
11001100
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC,
11011101
"Bug: could not retrieve RarArchive object from zval");
11021102
goto cleanup;

0 commit comments

Comments
 (0)