Skip to content

PHPC-2146: Refactor typemap struct and BSON encoding/decoding of zvals #1369

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

Merged
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
8 changes: 4 additions & 4 deletions src/BSON/Javascript.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ HashTable* php_phongo_javascript_get_properties_hash(phongo_compat_object_handle
php_phongo_bson_state state;

PHONGO_BSON_INIT_STATE(state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->scope, &state)) {
zval_ptr_dtor(&state.zchild);
goto failure;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ static PHP_METHOD(MongoDB_BSON_Javascript, getScope)

PHONGO_BSON_INIT_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->scope, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand All @@ -220,7 +220,7 @@ static PHP_METHOD(MongoDB_BSON_Javascript, jsonSerialize)
php_phongo_bson_state state;

PHONGO_BSON_INIT_STATE(state);
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->scope, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand All @@ -244,7 +244,7 @@ static PHP_METHOD(MongoDB_BSON_Javascript, serialize)
PHONGO_PARSE_PARAMETERS_NONE();

if (intern->scope && intern->scope->len) {
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->scope, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PHP_FUNCTION(toPHP)
return;
}

if (!php_phongo_bson_to_zval_ex((const unsigned char*) data, data_len, &state)) {
if (!php_phongo_bson_data_to_zval_ex((const unsigned char*) data, data_len, &state)) {
zval_ptr_dtor(&state.zchild);
php_phongo_bson_typemap_dtor(&state.map);
RETURN_NULL();
Expand Down
6 changes: 3 additions & 3 deletions src/MongoDB/BulkWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ static void php_phongo_bulkwrite_extract_id(bson_t* doc, zval** return_value)
php_phongo_bson_state state;

PHONGO_BSON_INIT_STATE(state);
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
state.map.root.type = PHONGO_TYPEMAP_NATIVE_ARRAY;

if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &state)) {
if (!php_phongo_bson_to_zval_ex(doc, &state)) {
goto cleanup;
}

Expand Down Expand Up @@ -632,7 +632,7 @@ static HashTable* php_phongo_bulkwrite_get_debug_info(phongo_compat_object_handl
if (intern->let) {
zval zv;

if (!php_phongo_bson_to_zval(bson_get_data(intern->let), intern->let->len, &zv)) {
if (!php_phongo_bson_to_zval(intern->let, &zv)) {
zval_ptr_dtor(&zv);
goto done;
}
Expand Down
18 changes: 9 additions & 9 deletions src/MongoDB/ClientEncryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ static void phongo_clientencryption_create_datakey(php_phongo_clientencryption_t
static void phongo_clientencryption_encrypt(php_phongo_clientencryption_t* clientencryption, zval* zvalue, zval* zciphertext, zval* options);
static void phongo_clientencryption_decrypt(php_phongo_clientencryption_t* clientencryption, zval* zciphertext, zval* zvalue);

#define RETVAL_BSON_T(reply) \
do { \
php_phongo_bson_state state; \
PHONGO_BSON_INIT_STATE(state); \
if (!php_phongo_bson_to_zval_ex(bson_get_data(&(reply)), (reply).len, &state)) { \
zval_ptr_dtor(&state.zchild); \
goto cleanup; \
} \
RETVAL_ZVAL(&state.zchild, 0, 1); \
#define RETVAL_BSON_T(reply) \
do { \
php_phongo_bson_state state; \
PHONGO_BSON_INIT_STATE(state); \
if (!php_phongo_bson_to_zval_ex(&(reply), &state)) { \
zval_ptr_dtor(&state.zchild); \
goto cleanup; \
} \
RETVAL_ZVAL(&state.zchild, 0, 1); \
} while (0)

#define RETVAL_OPTIONAL_BSON_T(reply) \
Expand Down
2 changes: 1 addition & 1 deletion src/MongoDB/Command.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static HashTable* php_phongo_command_get_debug_info(phongo_compat_object_handler
if (intern->bson) {
zval zv;

if (!php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv)) {
if (!php_phongo_bson_to_zval(intern->bson, &zv)) {
zval_ptr_dtor(&zv);
goto done;
}
Expand Down
6 changes: 3 additions & 3 deletions src/MongoDB/Cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static PHP_METHOD(MongoDB_Driver_Cursor, setTypeMap)
if (restore_current_element && mongoc_cursor_current(intern->cursor)) {
const bson_t* doc = mongoc_cursor_current(intern->cursor);

if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &intern->visitor_data)) {
if (!php_phongo_bson_to_zval_ex(doc, &intern->visitor_data)) {
php_phongo_cursor_free_current(intern);
}
}
Expand Down Expand Up @@ -223,7 +223,7 @@ static PHP_METHOD(MongoDB_Driver_Cursor, next)
}

if (mongoc_cursor_next(intern->cursor, &doc)) {
if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &intern->visitor_data)) {
if (!php_phongo_bson_to_zval_ex(doc, &intern->visitor_data)) {
/* Free invalid result, but don't return as we want to free the
* session if the intern is exhausted. */
php_phongo_cursor_free_current(intern);
Expand Down Expand Up @@ -278,7 +278,7 @@ static PHP_METHOD(MongoDB_Driver_Cursor, rewind)
doc = mongoc_cursor_current(intern->cursor);

if (doc) {
if (!php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &intern->visitor_data)) {
if (!php_phongo_bson_to_zval_ex(doc, &intern->visitor_data)) {
/* Free invalid result, but don't return as we want to free the
* session if the intern is exhausted. */
php_phongo_cursor_free_current(intern);
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Monitoring/CommandFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)

PHONGO_PARSE_PARAMETERS_NONE();

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->reply, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(phongo_compat_obj
sprintf(operation_id, "%" PRIu64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Monitoring/CommandStartedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand)

PHONGO_PARSE_PARAMETERS_NONE();

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->command, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob
*is_temp = 1;
array_init_size(&retval, 6);

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state)) {
if (!php_phongo_bson_to_zval_ex(intern->command, &command_state)) {
zval_ptr_dtor(&command_state.zchild);
goto done;
}
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Monitoring/CommandSucceededEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getReply)

PHONGO_PARSE_PARAMETERS_NONE();

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->reply, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down Expand Up @@ -204,7 +204,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(phongo_compat_
sprintf(operation_id, "%" PRIu64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_ServerHeartbeatSucceededEvent, getRe

PHONGO_PARSE_PARAMETERS_NONE();

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) {
if (!php_phongo_bson_to_zval_ex(intern->reply, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ static HashTable* php_phongo_serverheartbeatsucceededevent_get_debug_info(phongo
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_BOOL_EX(&retval, "awaited", intern->awaited);

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Query.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static HashTable* php_phongo_query_get_debug_info(phongo_compat_object_handler_t
if (intern->filter) {
zval zv;

if (!php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv)) {
if (!php_phongo_bson_to_zval(intern->filter, &zv)) {
zval_ptr_dtor(&zv);
goto done;
}
Expand All @@ -484,7 +484,7 @@ static HashTable* php_phongo_query_get_debug_info(phongo_compat_object_handler_t
if (intern->opts) {
zval zv;

if (!php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv)) {
if (!php_phongo_bson_to_zval(intern->opts, &zv)) {
zval_ptr_dtor(&zv);
goto done;
}
Expand Down
14 changes: 7 additions & 7 deletions src/MongoDB/ReadPreference.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, getHedge)

PHONGO_BSON_INIT_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(hedge), hedge->len, &state)) {
if (!php_phongo_bson_to_zval_ex(hedge, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down Expand Up @@ -412,7 +412,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, getTagSets)

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
if (!php_phongo_bson_to_zval_ex(tags, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down Expand Up @@ -458,9 +458,9 @@ static HashTable* php_phongo_readpreference_get_properties_hash(phongo_compat_ob
/* Use PHONGO_TYPEMAP_NATIVE_ARRAY for the root type since tags is an
* array; however, inner documents and arrays can use the default. */
PHONGO_BSON_INIT_STATE(state);
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
state.map.root.type = PHONGO_TYPEMAP_NATIVE_ARRAY;

if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
if (!php_phongo_bson_to_zval_ex(tags, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}
Expand All @@ -483,7 +483,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(phongo_compat_ob

PHONGO_BSON_INIT_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(hedge), hedge->len, &state)) {
if (!php_phongo_bson_to_zval_ex(hedge, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}
Expand Down Expand Up @@ -540,7 +540,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, serialize)

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
if (!php_phongo_bson_to_zval_ex(tags, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand All @@ -557,7 +557,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, serialize)

PHONGO_BSON_INIT_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(hedge), hedge->len, &state)) {
if (!php_phongo_bson_to_zval_ex(hedge, &state)) {
zval_ptr_dtor(&state.zchild);
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/MongoDB/Server.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static PHP_METHOD(MongoDB_Driver_Server, getTags)
PHONGO_BSON_INIT_DEBUG_STATE(state);
bson_iter_document(&iter, &len, &bytes);

if (!php_phongo_bson_to_zval_ex(bytes, len, &state)) {
if (!php_phongo_bson_data_to_zval_ex(bytes, len, &state)) {
/* Exception should already have been thrown */
zval_ptr_dtor(&state.zchild);
mongoc_server_description_destroy(sd);
Expand Down Expand Up @@ -316,7 +316,7 @@ static PHP_METHOD(MongoDB_Driver_Server, getInfo)

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(hello_response), hello_response->len, &state)) {
if (!php_phongo_bson_to_zval_ex(hello_response, &state)) {
/* Exception should already have been thrown */
zval_ptr_dtor(&state.zchild);
goto cleanup;
Expand Down Expand Up @@ -640,7 +640,7 @@ bool php_phongo_server_to_zval(zval* retval, mongoc_client_t* client, mongoc_ser

PHONGO_BSON_INIT_DEBUG_STATE(state);
bson_iter_document(&iter, &len, &bytes);
if (!php_phongo_bson_to_zval_ex(bytes, len, &state)) {
if (!php_phongo_bson_data_to_zval_ex(bytes, len, &state)) {
/* Exception already thrown */
zval_ptr_dtor(&state.zchild);
return false;
Expand All @@ -666,7 +666,7 @@ bool php_phongo_server_to_zval(zval* retval, mongoc_client_t* client, mongoc_ser
PHONGO_BSON_INIT_DEBUG_STATE(state);
handshake_response = mongoc_server_description_hello_response(handshake_sd);

if (!php_phongo_bson_to_zval_ex(bson_get_data(handshake_response), handshake_response->len, &state)) {
if (!php_phongo_bson_to_zval_ex(handshake_response, &state)) {
/* Exception already thrown */
mongoc_server_description_destroy(handshake_sd);
zval_ptr_dtor(&state.zchild);
Expand All @@ -680,7 +680,7 @@ bool php_phongo_server_to_zval(zval* retval, mongoc_client_t* client, mongoc_ser

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(hello_response), hello_response->len, &state)) {
if (!php_phongo_bson_to_zval_ex(hello_response, &state)) {
/* Exception already thrown */
zval_ptr_dtor(&state.zchild);
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/ServerDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static PHP_METHOD(MongoDB_Driver_ServerDescription, getHelloResponse)

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(helloResponse), helloResponse->len, &state)) {
if (!php_phongo_bson_to_zval_ex(helloResponse, &state)) {
/* Exception should already have been thrown */
zval_ptr_dtor(&state.zchild);
return;
Expand Down Expand Up @@ -214,7 +214,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(phongo_compat_object

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(hello_response), hello_response->len, &state)) {
if (!php_phongo_bson_to_zval_ex(hello_response, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}
Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Session.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static PHP_METHOD(MongoDB_Driver_Session, getClusterTime)
RETURN_NULL();
}

if (!php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state)) {
if (!php_phongo_bson_to_zval_ex(cluster_time, &state)) {
/* Exception should already have been thrown */
zval_ptr_dtor(&state.zchild);
return;
Expand All @@ -251,7 +251,7 @@ static PHP_METHOD(MongoDB_Driver_Session, getLogicalSessionId)

lsid = mongoc_client_session_get_lsid(intern->client_session);

if (!php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state)) {
if (!php_phongo_bson_to_zval_ex(lsid, &state)) {
/* Exception should already have been thrown */
zval_ptr_dtor(&state.zchild);
return;
Expand Down Expand Up @@ -602,7 +602,7 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state)) {
if (!php_phongo_bson_to_zval_ex(lsid, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}
Expand All @@ -618,7 +618,7 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler

PHONGO_BSON_INIT_DEBUG_STATE(state);

if (!php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state)) {
if (!php_phongo_bson_to_zval_ex(cluster_time, &state)) {
zval_ptr_dtor(&state.zchild);
goto done;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MongoDB/WriteConcernError.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ zend_bool phongo_writeconcernerror_init(zval* return_value, bson_t* bson)

bson_iter_document(&iter, &len, &data);

if (!php_phongo_bson_to_zval(data, len, &intern->info)) {
if (!php_phongo_bson_data_to_zval(data, len, &intern->info)) {
zval_ptr_dtor(&intern->info);
ZVAL_UNDEF(&intern->info);

Expand Down
2 changes: 1 addition & 1 deletion src/MongoDB/WriteError.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ zend_bool phongo_writeerror_init(zval* return_value, bson_t* bson)

bson_iter_document(&iter, &len, &data);

if (!php_phongo_bson_to_zval(data, len, &intern->info)) {
if (!php_phongo_bson_data_to_zval(data, len, &intern->info)) {
zval_ptr_dtor(&intern->info);
ZVAL_UNDEF(&intern->info);

Expand Down
Loading