Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for 8.0.0beta3 #108

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions ext/maxminddb.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,21 @@ typedef size_t strsize_t;
typedef zend_object free_obj_t;

/* For PHP 8 compatibility */
#ifndef TSRMLS_C
#if PHP_VERSION_ID < 80000

#define PROP_OBJ(zv) (zv)

#else

#define PROP_OBJ(zv) Z_OBJ_P(zv)

#define TSRMLS_C
#endif
#ifndef TSRMLS_CC
#define TSRMLS_CC
#endif
#ifndef TSRMLS_DC
#define TSRMLS_DC

/* End PHP 8 compatibility */
#endif

#ifndef ZEND_ACC_CTOR
#define ZEND_ACC_CTOR 0
#endif
Expand Down Expand Up @@ -334,23 +340,13 @@ PHP_METHOD(MaxMind_Db_Reader, metadata) {
return;
}
MMDB_free_entry_data_list(entry_data_list);
#if PHP_VERSION_ID >= 80000
zend_call_method_with_1_params(Z_OBJ_P(return_value),
zend_call_method_with_1_params(PROP_OBJ(return_value),
metadata_ce,
&metadata_ce->constructor,
ZEND_CONSTRUCTOR_FUNC_NAME,
NULL,
&metadata_array);
zval_ptr_dtor(&metadata_array);
#else
zend_call_method_with_1_params(return_value,
metadata_ce,
&metadata_ce->constructor,
ZEND_CONSTRUCTOR_FUNC_NAME,
NULL,
&metadata_array);
zval_ptr_dtor(&metadata_array);
#endif
}

PHP_METHOD(MaxMind_Db_Reader, close) {
Expand Down Expand Up @@ -607,7 +603,7 @@ PHP_METHOD(MaxMind_Db_Reader_Metadata, __construct) {
"binary_format_major_version",
sizeof("binary_format_major_version") - 1))) {
zend_update_property(metadata_ce,
object,
PROP_OBJ(object),
"binaryFormatMajorVersion",
sizeof("binaryFormatMajorVersion") - 1,
tmp);
Expand All @@ -617,7 +613,7 @@ PHP_METHOD(MaxMind_Db_Reader_Metadata, __construct) {
"binary_format_minor_version",
sizeof("binary_format_minor_version") - 1))) {
zend_update_property(metadata_ce,
object,
PROP_OBJ(object),
"binaryFormatMinorVersion",
sizeof("binaryFormatMinorVersion") - 1,
tmp);
Expand All @@ -627,14 +623,14 @@ PHP_METHOD(MaxMind_Db_Reader_Metadata, __construct) {
"build_epoch",
sizeof("build_epoch") - 1))) {
zend_update_property(
metadata_ce, object, "buildEpoch", sizeof("buildEpoch") - 1, tmp);
metadata_ce, PROP_OBJ(object), "buildEpoch", sizeof("buildEpoch") - 1, tmp);
}

if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
"database_type",
sizeof("database_type") - 1))) {
zend_update_property(metadata_ce,
object,
PROP_OBJ(object),
"databaseType",
sizeof("databaseType") - 1,
tmp);
Expand All @@ -644,35 +640,35 @@ PHP_METHOD(MaxMind_Db_Reader_Metadata, __construct) {
"description",
sizeof("description") - 1))) {
zend_update_property(
metadata_ce, object, "description", sizeof("description") - 1, tmp);
metadata_ce, PROP_OBJ(object), "description", sizeof("description") - 1, tmp);
}

if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
"ip_version",
sizeof("ip_version") - 1))) {
zend_update_property(
metadata_ce, object, "ipVersion", sizeof("ipVersion") - 1, tmp);
metadata_ce, PROP_OBJ(object), "ipVersion", sizeof("ipVersion") - 1, tmp);
}

if ((tmp = zend_hash_str_find(
HASH_OF(metadata_array), "languages", sizeof("languages") - 1))) {
zend_update_property(
metadata_ce, object, "languages", sizeof("languages") - 1, tmp);
metadata_ce, PROP_OBJ(object), "languages", sizeof("languages") - 1, tmp);
}

if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
"record_size",
sizeof("record_size") - 1))) {
zend_update_property(
metadata_ce, object, "recordSize", sizeof("recordSize") - 1, tmp);
metadata_ce, PROP_OBJ(object), "recordSize", sizeof("recordSize") - 1, tmp);
if (Z_TYPE_P(tmp) == IS_LONG) {
record_size = Z_LVAL_P(tmp);
}
}

if (record_size != 0) {
zend_update_property_long(metadata_ce,
object,
PROP_OBJ(object),
"nodeByteSize",
sizeof("nodeByteSize") - 1,
record_size / 4);
Expand All @@ -682,15 +678,15 @@ PHP_METHOD(MaxMind_Db_Reader_Metadata, __construct) {
"node_count",
sizeof("node_count") - 1))) {
zend_update_property(
metadata_ce, object, "nodeCount", sizeof("nodeCount") - 1, tmp);
metadata_ce, PROP_OBJ(object), "nodeCount", sizeof("nodeCount") - 1, tmp);
if (Z_TYPE_P(tmp) == IS_LONG) {
node_count = Z_LVAL_P(tmp);
}
}

if (record_size != 0) {
zend_update_property_long(metadata_ce,
object,
PROP_OBJ(object),
"searchTreeSize",
sizeof("searchTreeSize") - 1,
record_size * node_count / 4);
Expand Down