Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,14 @@ void phongo_throw_exception_from_bson_error_t_and_reply(bson_error_t* error, con
#endif

zend_throw_exception(php_phongo_commandexception_ce, error->message, error->code TSRMLS_CC);
php_phongo_bson_to_zval(bson_get_data(reply), reply->len, &zv);

if (php_phongo_bson_to_zval(bson_get_data(reply), reply->len, &zv)) {
#if PHP_VERSION_ID >= 70000
phongo_add_exception_prop(ZEND_STRL("resultDocument"), &zv);
phongo_add_exception_prop(ZEND_STRL("resultDocument"), &zv);
#else
phongo_add_exception_prop(ZEND_STRL("resultDocument"), zv TSRMLS_CC);
phongo_add_exception_prop(ZEND_STRL("resultDocument"), zv TSRMLS_CC);
#endif
}

zval_ptr_dtor(&zv);
} else {
zend_throw_exception(phongo_exception_from_mongoc_domain(error->domain, error->code), error->message, error->code TSRMLS_CC);
Expand Down Expand Up @@ -1186,7 +1187,10 @@ void php_phongo_server_to_zval(zval* retval, mongoc_server_description_t* sd) /*

PHONGO_BSON_INIT_DEBUG_STATE(state);
bson_iter_document(&iter, &len, &bytes);
php_phongo_bson_to_zval_ex(bytes, len, &state);
if (!php_phongo_bson_to_zval_ex(bytes, len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(retval, "tags", &state.zchild);
Expand All @@ -1199,7 +1203,11 @@ void php_phongo_server_to_zval(zval* retval, mongoc_server_description_t* sd) /*
php_phongo_bson_state state;

PHONGO_BSON_INIT_DEBUG_STATE(state);
php_phongo_bson_to_zval_ex(bson_get_data(is_master), is_master->len, &state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(is_master), is_master->len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(retval, "last_is_master", &state.zchild);
Expand Down
7 changes: 6 additions & 1 deletion src/BSON/Javascript.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ static PHP_METHOD(Javascript, getScope)
php_phongo_bson_state state;

PHONGO_BSON_INIT_STATE(state);
php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
Expand Down
7 changes: 6 additions & 1 deletion src/MongoDB/Command.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ static HashTable* php_phongo_command_get_debug_info(zval* object, int* is_temp T
zval* zv;
#endif

php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv);
if (!php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv)) {
zval_ptr_dtor(&zv);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "command", &zv);
#else
Expand All @@ -204,6 +208,7 @@ static HashTable* php_phongo_command_get_debug_info(zval* object, int* is_temp T
ADD_ASSOC_NULL_EX(&retval, "command");
}

done:
return Z_ARRVAL(retval);

} /* }}} */
Expand Down
13 changes: 11 additions & 2 deletions src/MongoDB/Monitoring/CommandFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ PHP_METHOD(CommandFailedEvent, getReply)
return;
}

php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
Expand Down Expand Up @@ -250,7 +254,11 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zval* object, int
sprintf(operation_id, "%" PRIu64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);
#else
Expand All @@ -275,6 +283,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zval* object, int
#endif
}

done:
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
Expand Down
13 changes: 11 additions & 2 deletions src/MongoDB/Monitoring/CommandStartedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ PHP_METHOD(CommandStartedEvent, getCommand)
return;
}

php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
Expand Down Expand Up @@ -214,7 +218,11 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zval* object, in
*is_temp = 1;
array_init_size(&retval, 6);

php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state)) {
zval_ptr_dtor(&command_state.zchild);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL(&retval, "command", &command_state.zchild);
#else
Expand Down Expand Up @@ -245,6 +253,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zval* object, in
#endif
}

done:
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
Expand Down
13 changes: 11 additions & 2 deletions src/MongoDB/Monitoring/CommandSucceededEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ PHP_METHOD(CommandSucceededEvent, getReply)
return;
}

php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
Expand Down Expand Up @@ -217,7 +221,11 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zval* object,
sprintf(operation_id, "%" PRIu64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state);
if (php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);
#else
Expand All @@ -242,6 +250,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zval* object,
#endif
}

done:
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
Expand Down
13 changes: 11 additions & 2 deletions src/MongoDB/Query.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR
zval* zv;
#endif

php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv);
if (!php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv)) {
zval_ptr_dtor(&zv);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "filter", &zv);
#else
Expand All @@ -472,7 +476,11 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR
zval* zv;
#endif

php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv);
if (!php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv)) {
zval_ptr_dtor(&zv);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "options", &zv);
#else
Expand All @@ -499,6 +507,7 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR
ADD_ASSOC_NULL_EX(&retval, "readConcern");
}

done:
return Z_ARRVAL(retval);

} /* }}} */
Expand Down
24 changes: 18 additions & 6 deletions src/MongoDB/ReadPreference.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ static PHP_METHOD(ReadPreference, getTagSets)
php_phongo_bson_state state;

PHONGO_BSON_INIT_DEBUG_STATE(state);
php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&state.zchild, 0, 1);
#else
Expand Down Expand Up @@ -436,15 +441,16 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zval* object, bo
PHONGO_BSON_INIT_STATE(state);
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;

php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}

#if PHP_VERSION_ID >= 70000
Z_ADDREF(state.zchild);
zend_hash_str_update(props, "tags", sizeof("tags") - 1, &state.zchild);
#else
Z_ADDREF_P(state.zchild);
zend_hash_update(props, "tags", sizeof("tags"), &state.zchild, sizeof(state.zchild), NULL);
#endif
zval_ptr_dtor(&state.zchild);
}

if (mongoc_read_prefs_get_max_staleness_seconds(intern->read_preference) != MONGOC_NO_MAX_STALENESS) {
Expand All @@ -463,6 +469,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zval* object, bo
#endif
}

done:
return props;
} /* }}} */

Expand Down Expand Up @@ -525,7 +532,12 @@ static PHP_METHOD(ReadPreference, serialize)
php_phongo_bson_state state;

PHONGO_BSON_INIT_DEBUG_STATE(state);
php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "tags", &state.zchild);
#else
Expand Down
12 changes: 10 additions & 2 deletions src/MongoDB/Session.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T

lsid = mongoc_client_session_get_lsid(intern->client_session);

php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "logicalSessionId", &state.zchild);
Expand All @@ -580,7 +583,11 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
php_phongo_bson_state state;

PHONGO_BSON_INIT_DEBUG_STATE(state);
php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "clusterTime", &state.zchild);
Expand Down Expand Up @@ -650,6 +657,7 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
ADD_ASSOC_NULL_EX(&retval, "server");
}

done:
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
Expand Down
7 changes: 6 additions & 1 deletion src/MongoDB/WriteResult.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ static HashTable* php_phongo_writeresult_get_debug_info(zval* object, int* is_te

PHONGO_BSON_INIT_DEBUG_STATE(state);
bson_iter_array(&iter, &len, &data);
php_phongo_bson_to_zval_ex(data, len, &state);
if (!php_phongo_bson_to_zval_ex(data, len, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}

#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "upsertedIds", &state.zchild);
#else
Expand Down Expand Up @@ -491,6 +495,7 @@ static HashTable* php_phongo_writeresult_get_debug_info(zval* object, int* is_te
ADD_ASSOC_NULL_EX(&retval, "writeConcern");
}

done:
return Z_ARRVAL(retval);
} /* }}} */
/* }}} */
Expand Down