Skip to content

Commit ab26d28

Browse files
committed
Fixes for PHP 8.1
1 parent 488dd3c commit ab26d28

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

rar_stream.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,13 @@ static int _rar_get_archive_and_fragment(php_stream_wrapper *wrapper,
784784
#if PHP_MAJOR_VERSION < 7
785785
*archive = zend_resolve_path(tmp_archive, tmp_arch_len TSRMLS_CC);
786786
#else
787+
# if PHP_VERSION_ID < 80100
787788
zend_string *arc_str = zend_resolve_path(tmp_archive, tmp_arch_len);
789+
# else
790+
zend_string *tmp_archive_str = zend_string_init_fast(tmp_archive, tmp_arch_len);
791+
zend_string *arc_str = zend_resolve_path(tmp_archive_str);
792+
zend_string_free(tmp_archive_str);
793+
# endif
788794
if (arc_str != NULL) {
789795
*archive = estrndup(arc_str->val, arc_str->len);
790796
} else {

rararch.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/* $Id$ */
2929

3030
#include "zend_types.h"
31+
#include <zend_API.h>
3132
#ifdef __cplusplus
3233
extern "C" {
3334
#endif
@@ -962,6 +963,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_rararchive_setallowbroken, 0, 0, 1)
962963
ZEND_ARG_INFO(0, allow_broken)
963964
ZEND_END_ARG_INFO()
964965

966+
#if PHP_MAJOR_VERSION >= 8
967+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_rararchive_getiterator, 0, 0, Traversable, 0)
968+
ZEND_END_ARG_INFO()
969+
#endif
970+
965971
ZEND_BEGIN_ARG_INFO(arginfo_rararchive_void, 0)
966972
ZEND_END_ARG_INFO()
967973
/* }}} */
@@ -981,7 +987,7 @@ static zend_function_entry php_rararch_class_functions[] = {
981987
PHP_ME(rararch, __toString, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
982988
PHP_ME_MAPPING(__construct, rar_bogus_ctor, arginfo_rararchive_void, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
983989
#if PHP_MAJOR_VERSION >= 8
984-
PHP_ME(rararch, getIterator, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
990+
PHP_ME(rararch, getIterator, arginfo_rararchive_getiterator, ZEND_ACC_PUBLIC)
985991
#endif
986992
{NULL, NULL, NULL}
987993
};

rarentry.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727

2828
/* $Id$ */
2929

30-
#ifdef __cplusplus
31-
extern "C" {
30+
#include <zend_types.h>
31+
#ifndef _GNU_SOURCE
32+
# define _GNU_SOURCE
3233
#endif
33-
34-
#define _GNU_SOURCE
3534
#include <string.h>
3635

3736
#include <php.h>
@@ -270,8 +269,8 @@ static void _rar_dos_date_to_text(unsigned dos_time, char *date_string) /* {{{ *
270269
/* }}} */
271270

272271
/* {{{ Methods */
273-
/* {{{ proto bool RarEntry::extract(string dir [, string filepath = ''
274-
[, string password = NULL [, bool extended_data = FALSE]])
272+
/* {{{ public function extract(?string $dir, ?string $filepath = '',
273+
?string $password = null, bool $extended_data = false): void {}
275274
Extract file from the archive */
276275
PHP_METHOD(rarentry, extract)
277276
{ /* lots of variables, but no need to be intimidated */
@@ -298,7 +297,7 @@ PHP_METHOD(rarentry, extract)
298297
* password that's different from the one stored in the rar_file_t object*/
299298
rar_cb_user_data cb_udata = {NULL};
300299

301-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss!b", &dir,
300+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!|s!s!b", &dir,
302301
&dir_len, &filepath, &filepath_len, &password, &password_len,
303302
&process_ed) == FAILURE ) {
304303
return;
@@ -714,12 +713,21 @@ PHP_METHOD(rarentry, __toString)
714713
/* }}} */
715714

716715
/* {{{ arginfo */
716+
#if PHP_MAJOR_VERSION < 8
717717
ZEND_BEGIN_ARG_INFO_EX(arginfo_rarentry_extract, 0, 0, 1)
718718
ZEND_ARG_INFO(0, path)
719719
ZEND_ARG_INFO(0, filename)
720720
ZEND_ARG_INFO(0, password)
721721
ZEND_ARG_INFO(0, extended_data)
722722
ZEND_END_ARG_INFO()
723+
#else
724+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rarentry_extract, 0, 1, _IS_BOOL, 0)
725+
ZEND_ARG_TYPE_INFO(0, dir, IS_STRING, 1)
726+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filepath, IS_STRING, 1, "\'\'")
727+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
728+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extended_data, _IS_BOOL, 0, "false")
729+
ZEND_END_ARG_INFO()
730+
#endif
723731

724732
ZEND_BEGIN_ARG_INFO_EX(arginfo_rarentry_getstream, 0, 0, 0)
725733
ZEND_ARG_INFO(0, password)
@@ -829,7 +837,3 @@ void minit_rarentry(TSRMLS_D)
829837
REG_RAR_CLASS_CONST_LONG("ATTRIBUTE_UNIX_SYM_LINK", 0x0A000L);
830838
REG_RAR_CLASS_CONST_LONG("ATTRIBUTE_UNIX_SOCKET", 0x0C000L);
831839
}
832-
833-
#ifdef __cplusplus
834-
}
835-
#endif

tests/047.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ function resolve($vol) {
1010
else
1111
return null;
1212
}
13-
function int32_to_hex($value) {
14-
$value &= 0xffffffff;
15-
return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT);
13+
function int32_to_hex($value) {
14+
$value &= 0xffffffff;
15+
return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT);
1616
}
1717
echo "Fail:\n";
1818
$rar_file1 = rar_open(dirname(__FILE__).'/multi_broken.part1.rar');

0 commit comments

Comments
 (0)