@@ -299,9 +299,16 @@ static HashTable* php_phongo_binary_get_debug_info(zend_object* object, int* is_
299
299
300
300
zend_hash_str_update (props , "vector" , sizeof ("vector" ) - 1 , & vector );
301
301
302
- zval vector_type ;
302
+ zval vector_type ;
303
+ zend_object * vector_type_case = phongo_bson_vector_type_to_case (phongo_binary_get_vector_type (intern ));
303
304
304
- ZVAL_LONG (& vector_type , phongo_binary_get_vector_type (intern ));
305
+ // The vector should always be valid by this point, but check for an error
306
+ if (!vector_type_case ) {
307
+ phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Binary vector data is invalid" );
308
+ return props ;
309
+ }
310
+
311
+ ZVAL_OBJ_COPY (& vector_type , vector_type_case );
305
312
zend_hash_str_update (props , "vectorType" , sizeof ("vectorType" ) - 1 , & vector_type );
306
313
}
307
314
@@ -496,7 +503,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, fromVector)
496
503
Z_PARAM_OBJ_OF_CLASS (type , php_phongo_vectortype_ce )
497
504
PHONGO_PARSE_PARAMETERS_END ();
498
505
499
- switch (phongo_bson_vector_type_from_name ( Z_STRVAL_P ( zend_enum_fetch_case_name ( type )) )) {
506
+ switch (phongo_bson_vector_type_from_case ( type )) {
500
507
case PHONGO_BSON_VECTOR_TYPE_FLOAT32 :
501
508
phongo_binary_init_vector_from_float32_array (intern , vector );
502
509
return ;
@@ -545,7 +552,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, getVectorType)
545
552
RETURN_THROWS ();
546
553
}
547
554
548
- const char * type_case = phongo_bson_vector_type_to_name (phongo_binary_get_vector_type (Z_BINARY_OBJ_P ( getThis ()) ));
555
+ const char * type_case = phongo_bson_vector_type_to_name (phongo_binary_get_vector_type (intern ));
549
556
550
557
// The vector should always be valid by this point, but check for an error
551
558
if (!type_case ) {
@@ -558,43 +565,48 @@ static PHP_METHOD(MongoDB_BSON_Binary, getVectorType)
558
565
559
566
static void phongo_binary_get_vector_as_array (const php_phongo_binary_t * intern , zval * return_value )
560
567
{
561
- phongo_bson_vector_type_t type = phongo_binary_get_vector_type (intern );
562
-
563
- // The vector should always be valid by this point, but check for an error
564
- if (type == PHONGO_BSON_VECTOR_TYPE_UNKNOWN ) {
565
- phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Binary vector data is invalid" );
566
- RETURN_THROWS ();
567
- }
568
-
569
568
bson_t tmp_doc = BSON_INITIALIZER ;
570
569
571
- if (type == PHONGO_BSON_VECTOR_TYPE_INT8 ) {
572
- bson_vector_int8_const_view_t view ;
570
+ switch (phongo_binary_get_vector_type (intern )) {
571
+ case PHONGO_BSON_VECTOR_TYPE_INT8 : {
572
+ bson_vector_int8_const_view_t view ;
573
573
574
- if (!bson_vector_int8_const_view_init (& view , (const uint8_t * ) intern -> data , intern -> data_len ) ||
575
- !BSON_APPEND_ARRAY_FROM_VECTOR_INT8 (& tmp_doc , "vector" , view )) {
576
- phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Failed to convert binary vector data to an array" );
577
- bson_destroy (& tmp_doc );
578
- RETURN_THROWS ();
574
+ if (!bson_vector_int8_const_view_init (& view , (const uint8_t * ) intern -> data , intern -> data_len ) ||
575
+ !BSON_APPEND_ARRAY_FROM_VECTOR_INT8 (& tmp_doc , "vector" , view )) {
576
+ phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Failed to convert binary vector data to an array" );
577
+ bson_destroy (& tmp_doc );
578
+ RETURN_THROWS ();
579
+ }
580
+
581
+ break ;
579
582
}
580
- } else if ( type == PHONGO_BSON_VECTOR_TYPE_FLOAT32 ) {
581
- bson_vector_float32_const_view_t view ;
583
+ case PHONGO_BSON_VECTOR_TYPE_FLOAT32 : {
584
+ bson_vector_float32_const_view_t view ;
582
585
583
- if (!bson_vector_float32_const_view_init (& view , (const uint8_t * ) intern -> data , intern -> data_len ) ||
584
- !BSON_APPEND_ARRAY_FROM_VECTOR_FLOAT32 (& tmp_doc , "vector" , view )) {
585
- phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Failed to convert binary vector data to an array" );
586
- bson_destroy (& tmp_doc );
587
- RETURN_THROWS ();
586
+ if (!bson_vector_float32_const_view_init (& view , (const uint8_t * ) intern -> data , intern -> data_len ) ||
587
+ !BSON_APPEND_ARRAY_FROM_VECTOR_FLOAT32 (& tmp_doc , "vector" , view )) {
588
+ phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Failed to convert binary vector data to an array" );
589
+ bson_destroy (& tmp_doc );
590
+ RETURN_THROWS ();
591
+ }
592
+
593
+ break ;
588
594
}
589
- } else if ( type == PHONGO_BSON_VECTOR_TYPE_PACKED_BIT ) {
590
- bson_vector_packed_bit_const_view_t view ;
595
+ case PHONGO_BSON_VECTOR_TYPE_PACKED_BIT : {
596
+ bson_vector_packed_bit_const_view_t view ;
591
597
592
- if (!bson_vector_packed_bit_const_view_init (& view , (const uint8_t * ) intern -> data , intern -> data_len ) ||
593
- !BSON_APPEND_ARRAY_FROM_VECTOR_PACKED_BIT (& tmp_doc , "vector" , view )) {
594
- phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Failed to convert binary vector data to an array" );
595
- bson_destroy (& tmp_doc );
596
- RETURN_THROWS ();
598
+ if (!bson_vector_packed_bit_const_view_init (& view , (const uint8_t * ) intern -> data , intern -> data_len ) ||
599
+ !BSON_APPEND_ARRAY_FROM_VECTOR_PACKED_BIT (& tmp_doc , "vector" , view )) {
600
+ phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Failed to convert binary vector data to an array" );
601
+ bson_destroy (& tmp_doc );
602
+ RETURN_THROWS ();
603
+ }
604
+
605
+ break ;
597
606
}
607
+ default :
608
+ phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Binary vector data is invalid" );
609
+ RETURN_THROWS ();
598
610
}
599
611
600
612
bson_iter_t iter ;
@@ -647,5 +659,5 @@ static PHP_METHOD(MongoDB_BSON_Binary, toArray)
647
659
RETURN_THROWS ();
648
660
}
649
661
650
- phongo_binary_get_vector_as_array (Z_BINARY_OBJ_P ( getThis ()) , return_value );
662
+ phongo_binary_get_vector_as_array (intern , return_value );
651
663
}
0 commit comments