@ -45,16 +45,18 @@ static void CheckUpbStatus(const upb_Status* status, const char* msg) {
}
}
static void FieldDescriptor_FromFieldDef ( zval * val , const upb_FieldDef * f ) ;
static void FieldDescriptor_FromFieldDef ( zval * val , const upb_FieldDef * f ) ;
// We use this for objects that should not be created directly from PHP.
static zend_object * CreateHandler_ReturnNull ( zend_class_entry * class_type ) {
static zend_object * CreateHandler_ReturnNull ( zend_class_entry * class_type ) {
return NULL ; // Nobody should call this.
}
// clang-format off
ZEND_BEGIN_ARG_INFO_EX ( arginfo_getByIndex , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , index )
ZEND_END_ARG_INFO ( )
// clang-format on
// -----------------------------------------------------------------------------
// EnumValueDescriptor
@ -62,11 +64,11 @@ ZEND_END_ARG_INFO()
typedef struct {
zend_object std ;
const char * name ;
const char * name ;
int32_t number ;
} EnumValueDescriptor ;
zend_class_entry * EnumValueDescriptor_class_entry ;
zend_class_entry * EnumValueDescriptor_class_entry ;
static zend_object_handlers EnumValueDescriptor_object_handlers ;
/*
@ -74,9 +76,9 @@ static zend_object_handlers EnumValueDescriptor_object_handlers;
*
* Function to create an EnumValueDescriptor object from C .
*/
static void EnumValueDescriptor_Make ( zval * val , const char * name ,
static void EnumValueDescriptor_Make ( zval * val , const char * name ,
int32_t number ) {
EnumValueDescriptor * intern = emalloc ( sizeof ( EnumValueDescriptor ) ) ;
EnumValueDescriptor * intern = emalloc ( sizeof ( EnumValueDescriptor ) ) ;
zend_object_std_init ( & intern - > std , EnumValueDescriptor_class_entry ) ;
intern - > std . handlers = & EnumValueDescriptor_object_handlers ;
intern - > name = name ;
@ -91,7 +93,7 @@ static void EnumValueDescriptor_Make(zval *val, const char *name,
* Returns the name for this enum value .
*/
PHP_METHOD ( EnumValueDescriptor , getName ) {
EnumValueDescriptor * intern = ( EnumValueDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
EnumValueDescriptor * intern = ( EnumValueDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_STRING ( intern - > name ) ;
}
@ -101,15 +103,17 @@ PHP_METHOD(EnumValueDescriptor, getName) {
* Returns the number for this enum value .
*/
PHP_METHOD ( EnumValueDescriptor , getNumber ) {
EnumValueDescriptor * intern = ( EnumValueDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
EnumValueDescriptor * intern = ( EnumValueDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( intern - > number ) ;
}
// clang-format off
static zend_function_entry EnumValueDescriptor_methods [ ] = {
PHP_ME ( EnumValueDescriptor , getName , arginfo_void , ZEND_ACC_PUBLIC )
PHP_ME ( EnumValueDescriptor , getNumber , arginfo_void , ZEND_ACC_PUBLIC )
ZEND_FE_END
} ;
// clang-format on
// -----------------------------------------------------------------------------
// EnumDescriptor
@ -117,20 +121,20 @@ static zend_function_entry EnumValueDescriptor_methods[] = {
typedef struct {
zend_object std ;
const upb_EnumDef * enumdef ;
void * cache_key ;
const upb_EnumDef * enumdef ;
void * cache_key ;
} EnumDescriptor ;
zend_class_entry * EnumDescriptor_class_entry ;
zend_class_entry * EnumDescriptor_class_entry ;
static zend_object_handlers EnumDescriptor_object_handlers ;
static void EnumDescriptor_destructor ( zend_object * obj ) {
EnumDescriptor * intern = ( EnumDescriptor * ) obj ;
EnumDescriptor * intern = ( EnumDescriptor * ) obj ;
ObjCache_Delete ( intern - > cache_key ) ;
}
// Caller owns a ref on the returned zval.
static void EnumDescriptor_FromClassEntry ( zval * val , zend_class_entry * ce ) {
static void EnumDescriptor_FromClassEntry ( zval * val , zend_class_entry * ce ) {
// To differentiate enums from classes, we pointer-tag the class entry.
void * key = ( void * ) ( ( uintptr_t ) ce | 1 ) ;
PBPHP_ASSERT ( key ! = ce ) ;
@ -141,7 +145,7 @@ static void EnumDescriptor_FromClassEntry(zval *val, zend_class_entry *ce) {
}
if ( ! ObjCache_Get ( key , val ) ) {
const upb_EnumDef * e = NameMap_GetEnum ( ce ) ;
const upb_EnumDef * e = NameMap_GetEnum ( ce ) ;
if ( ! e ) {
ZVAL_NULL ( val ) ;
return ;
@ -157,16 +161,16 @@ static void EnumDescriptor_FromClassEntry(zval *val, zend_class_entry *ce) {
}
// Caller owns a ref on the returned zval.
static void EnumDescriptor_FromEnumDef ( zval * val , const upb_EnumDef * m ) {
static void EnumDescriptor_FromEnumDef ( zval * val , const upb_EnumDef * m ) {
if ( ! m ) {
ZVAL_NULL ( val ) ;
} else {
char * classname =
char * classname =
GetPhpClassname ( upb_EnumDef_File ( m ) , upb_EnumDef_FullName ( m ) , false ) ;
zend_string * str = zend_string_init ( classname , strlen ( classname ) , 0 ) ;
zend_class_entry * ce = zend_lookup_class ( str ) ; // May autoload the class.
zend_string * str = zend_string_init ( classname , strlen ( classname ) , 0 ) ;
zend_class_entry * ce = zend_lookup_class ( str ) ; // May autoload the class.
zend_string_release ( str ) ;
zend_string_release ( str ) ;
if ( ! ce ) {
zend_error ( E_ERROR , " Couldn't load generated class %s " , classname ) ;
@ -184,7 +188,7 @@ static void EnumDescriptor_FromEnumDef(zval *val, const upb_EnumDef *m) {
* up by numeric enum value , but by the index in the list of enum values .
*/
PHP_METHOD ( EnumDescriptor , getValue ) {
EnumDescriptor * intern = ( EnumDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
EnumDescriptor * intern = ( EnumDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
zend_long index ;
zval ret ;
@ -210,7 +214,7 @@ PHP_METHOD(EnumDescriptor, getValue) {
* Returns the number of values in this enum .
*/
PHP_METHOD ( EnumDescriptor , getValueCount ) {
EnumDescriptor * intern = ( EnumDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
EnumDescriptor * intern = ( EnumDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( upb_EnumDef_ValueCount ( intern - > enumdef ) ) ;
}
@ -221,16 +225,16 @@ PHP_METHOD(EnumDescriptor, getValueCount) {
* have two separate EnumDescriptor classes . We use a single class for both
* the public and private descriptor .
*/
PHP_METHOD ( EnumDescriptor , getPublicDescriptor ) {
RETURN_COPY ( getThis ( ) ) ;
}
PHP_METHOD ( EnumDescriptor , getPublicDescriptor ) { RETURN_COPY ( getThis ( ) ) ; }
// clang-format off
static zend_function_entry EnumDescriptor_methods [ ] = {
PHP_ME ( EnumDescriptor , getPublicDescriptor , arginfo_void , ZEND_ACC_PUBLIC )
PHP_ME ( EnumDescriptor , getValueCount , arginfo_void , ZEND_ACC_PUBLIC )
PHP_ME ( EnumDescriptor , getValue , arginfo_getByIndex , ZEND_ACC_PUBLIC )
ZEND_FE_END
} ;
// clang-format on
// -----------------------------------------------------------------------------
// Oneof
@ -238,18 +242,18 @@ static zend_function_entry EnumDescriptor_methods[] = {
typedef struct {
zend_object std ;
const upb_OneofDef * oneofdef ;
const upb_OneofDef * oneofdef ;
} OneofDescriptor ;
zend_class_entry * OneofDescriptor_class_entry ;
zend_class_entry * OneofDescriptor_class_entry ;
static zend_object_handlers OneofDescriptor_object_handlers ;
static void OneofDescriptor_destructor ( zend_object * obj ) {
OneofDescriptor * intern = ( OneofDescriptor * ) obj ;
OneofDescriptor * intern = ( OneofDescriptor * ) obj ;
ObjCache_Delete ( intern - > oneofdef ) ;
}
static void OneofDescriptor_FromOneofDef ( zval * val , const upb_OneofDef * o ) {
static void OneofDescriptor_FromOneofDef ( zval * val , const upb_OneofDef * o ) {
if ( o = = NULL ) {
ZVAL_NULL ( val ) ;
return ;
@ -271,7 +275,7 @@ static void OneofDescriptor_FromOneofDef(zval *val, const upb_OneofDef *o) {
* Returns the name of this oneof .
*/
PHP_METHOD ( OneofDescriptor , getName ) {
OneofDescriptor * intern = ( OneofDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
OneofDescriptor * intern = ( OneofDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_STRING ( upb_OneofDef_Name ( intern - > oneofdef ) ) ;
}
@ -282,7 +286,7 @@ PHP_METHOD(OneofDescriptor, getName) {
* [ 0 , getFieldCount ( ) - 1 ] .
*/
PHP_METHOD ( OneofDescriptor , getField ) {
OneofDescriptor * intern = ( OneofDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
OneofDescriptor * intern = ( OneofDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
zend_long index ;
zval ret ;
@ -307,16 +311,18 @@ PHP_METHOD(OneofDescriptor, getField) {
* Returns the number of fields in this oneof .
*/
PHP_METHOD ( OneofDescriptor , getFieldCount ) {
OneofDescriptor * intern = ( OneofDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
OneofDescriptor * intern = ( OneofDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( upb_OneofDef_FieldCount ( intern - > oneofdef ) ) ;
}
// clang-format off
static zend_function_entry OneofDescriptor_methods [ ] = {
PHP_ME ( OneofDescriptor , getName , arginfo_void , ZEND_ACC_PUBLIC )
PHP_ME ( OneofDescriptor , getField , arginfo_getByIndex , ZEND_ACC_PUBLIC )
PHP_ME ( OneofDescriptor , getFieldCount , arginfo_void , ZEND_ACC_PUBLIC )
ZEND_FE_END
} ;
// clang-format on
// -----------------------------------------------------------------------------
// FieldDescriptor
@ -324,19 +330,19 @@ static zend_function_entry OneofDescriptor_methods[] = {
typedef struct {
zend_object std ;
const upb_FieldDef * fielddef ;
const upb_FieldDef * fielddef ;
} FieldDescriptor ;
zend_class_entry * FieldDescriptor_class_entry ;
zend_class_entry * FieldDescriptor_class_entry ;
static zend_object_handlers FieldDescriptor_object_handlers ;
static void FieldDescriptor_destructor ( zend_object * obj ) {
FieldDescriptor * intern = ( FieldDescriptor * ) obj ;
FieldDescriptor * intern = ( FieldDescriptor * ) obj ;
ObjCache_Delete ( intern - > fielddef ) ;
}
// Caller owns a ref on the returned zval.
static void FieldDescriptor_FromFieldDef ( zval * val , const upb_FieldDef * f ) {
static void FieldDescriptor_FromFieldDef ( zval * val , const upb_FieldDef * f ) {
if ( f = = NULL ) {
ZVAL_NULL ( val ) ;
return ;
@ -354,31 +360,30 @@ static void FieldDescriptor_FromFieldDef(zval *val, const upb_FieldDef *f) {
upb_CType to_fieldtype ( upb_FieldType type ) {
switch ( type ) {
# define CASE(descriptor_type, type) \
# define CASE(descriptor_type, type) \
case kUpb_FieldType_ # # descriptor_type : \
return kUpb_CType_ # # type ;
CASE ( Float , Float ) ;
CASE ( Double , Double ) ;
CASE ( Bool , Bool ) ;
CASE ( String , String ) ;
CASE ( Bytes , Bytes ) ;
CASE ( Message , Message ) ;
CASE ( Group , Message ) ;
CASE ( Enum , Enum ) ;
CASE ( Int32 , Int32 ) ;
CASE ( Int64 , Int64 ) ;
CASE ( UInt32 , UInt32 ) ;
CASE ( UInt64 , UInt64 ) ;
CASE ( SInt32 , Int32 ) ;
CASE ( SInt64 , Int64 ) ;
CASE ( Fixed32 , UInt32 ) ;
CASE ( Fixed64 , UInt64 ) ;
CASE ( SFixed32 , Int32 ) ;
CASE ( SFixed64 , Int64 ) ;
CASE ( Float , Float ) ;
CASE ( Double , Double ) ;
CASE ( Bool , Bool ) ;
CASE ( String , String ) ;
CASE ( Bytes , Bytes ) ;
CASE ( Message , Message ) ;
CASE ( Group , Message ) ;
CASE ( Enum , Enum ) ;
CASE ( Int32 , Int32 ) ;
CASE ( Int64 , Int64 ) ;
CASE ( UInt32 , UInt32 ) ;
CASE ( UInt64 , UInt64 ) ;
CASE ( SInt32 , Int32 ) ;
CASE ( SInt64 , Int64 ) ;
CASE ( Fixed32 , UInt32 ) ;
CASE ( Fixed64 , UInt64 ) ;
CASE ( SFixed32 , Int32 ) ;
CASE ( SFixed64 , Int64 ) ;
# undef CONVERT
}
zend_error ( E_ERROR , " Unknown field type. " ) ;
@ -391,7 +396,7 @@ upb_CType to_fieldtype(upb_FieldType type) {
* Returns the name of this field .
*/
PHP_METHOD ( FieldDescriptor , getName ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_STRING ( upb_FieldDef_Name ( intern - > fielddef ) ) ;
}
@ -401,7 +406,7 @@ PHP_METHOD(FieldDescriptor, getName) {
* Returns the number of this field .
*/
PHP_METHOD ( FieldDescriptor , getNumber ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( upb_FieldDef_Number ( intern - > fielddef ) ) ;
}
@ -411,7 +416,7 @@ PHP_METHOD(FieldDescriptor, getNumber) {
* Returns the label of this field as an integer .
*/
PHP_METHOD ( FieldDescriptor , getLabel ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( upb_FieldDef_Label ( intern - > fielddef ) ) ;
}
@ -421,7 +426,7 @@ PHP_METHOD(FieldDescriptor, getLabel) {
* Returns the type of this field as an integer .
*/
PHP_METHOD ( FieldDescriptor , getType ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( upb_FieldDef_Type ( intern - > fielddef ) ) ;
}
@ -431,7 +436,7 @@ PHP_METHOD(FieldDescriptor, getType) {
* Returns true if this field is a map .
*/
PHP_METHOD ( FieldDescriptor , isMap ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_BOOL ( upb_FieldDef_IsMap ( intern - > fielddef ) ) ;
}
@ -441,8 +446,8 @@ PHP_METHOD(FieldDescriptor, isMap) {
* Returns the EnumDescriptor for this field , which must be an enum .
*/
PHP_METHOD ( FieldDescriptor , getEnumType ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
const upb_EnumDef * e = upb_FieldDef_EnumSubDef ( intern - > fielddef ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
const upb_EnumDef * e = upb_FieldDef_EnumSubDef ( intern - > fielddef ) ;
zval ret ;
if ( ! e ) {
@ -463,8 +468,8 @@ PHP_METHOD(FieldDescriptor, getEnumType) {
* a oneof .
*/
PHP_METHOD ( FieldDescriptor , getContainingOneof ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
const upb_OneofDef * o = upb_FieldDef_ContainingOneof ( intern - > fielddef ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
const upb_OneofDef * o = upb_FieldDef_ContainingOneof ( intern - > fielddef ) ;
zval ret ;
if ( ! o ) {
@ -482,8 +487,8 @@ PHP_METHOD(FieldDescriptor, getContainingOneof) {
* not inside a oneof .
*/
PHP_METHOD ( FieldDescriptor , getRealContainingOneof ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
const upb_OneofDef * o = upb_FieldDef_RealContainingOneof ( intern - > fielddef ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
const upb_OneofDef * o = upb_FieldDef_RealContainingOneof ( intern - > fielddef ) ;
zval ret ;
if ( ! o ) {
@ -500,7 +505,7 @@ PHP_METHOD(FieldDescriptor, getRealContainingOneof) {
* Returns the Descriptor for this field , which must be a message .
*/
PHP_METHOD ( FieldDescriptor , getMessageType ) {
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
FieldDescriptor * intern = ( FieldDescriptor * ) Z_OBJ_P ( getThis ( ) ) ;
Descriptor * desc = Descriptor_GetFromFieldDef ( intern - > fielddef ) ;
if ( ! desc ) {
@ -513,6 +518,7 @@ PHP_METHOD(FieldDescriptor, getMessageType) {
RETURN_OBJ_COPY ( & desc - > std ) ;
}
// clang-format off
static zend_function_entry FieldDescriptor_methods [ ] = {
PHP_ME ( FieldDescriptor , getName , arginfo_void , ZEND_ACC_PUBLIC )
PHP_ME ( FieldDescriptor , getNumber , arginfo_void , ZEND_ACC_PUBLIC )
@ -525,12 +531,13 @@ static zend_function_entry FieldDescriptor_methods[] = {
PHP_ME ( FieldDescriptor , getMessageType , arginfo_void , ZEND_ACC_PUBLIC )
ZEND_FE_END
} ;
// clang-format on
// -----------------------------------------------------------------------------
// Descriptor
// -----------------------------------------------------------------------------
zend_class_entry * Descriptor_class_entry ;
zend_class_entry * Descriptor_class_entry ;
static zend_object_handlers Descriptor_object_handlers ;
static void Descriptor_destructor ( zend_object * obj ) {
@ -538,14 +545,14 @@ static void Descriptor_destructor(zend_object* obj) {
// collected before the end of the request.
}
static zend_class_entry * Descriptor_GetGeneratedClass ( const upb_MessageDef * m ) {
static zend_class_entry * Descriptor_GetGeneratedClass ( const upb_MessageDef * m ) {
for ( int i = 0 ; i < 2 ; + + i ) {
char * classname =
GetPhpClassname ( upb_MessageDef_File ( m ) , upb_MessageDef_FullName ( m ) , ( bool ) i ) ;
zend_string * str = zend_string_init ( classname , strlen ( classname ) , 0 ) ;
zend_class_entry * ce = zend_lookup_class ( str ) ; // May autoload the class.
char * classname = GetPhpClassname ( upb_MessageDef_File ( m ) ,
upb_MessageDef_FullName ( m ) , ( bool ) i ) ;
zend_string * str = zend_string_init ( classname , strlen ( classname ) , 0 ) ;
zend_class_entry * ce = zend_lookup_class ( str ) ; // May autoload the class.
zend_string_release ( str ) ;
zend_string_release ( str ) ;
free ( classname ) ;
if ( ce ) {
@ -553,20 +560,20 @@ static zend_class_entry *Descriptor_GetGeneratedClass(const upb_MessageDef *m) {
}
}
char * classname =
GetPhpClassname ( upb_MessageDef_File ( m ) , upb_MessageDef_FullName ( m ) , false ) ;
char * classname = GetPhpClassname ( upb_MessageDef_File ( m ) ,
upb_MessageDef_FullName ( m ) , false ) ;
zend_error ( E_ERROR , " Couldn't load generated class %s " , classname ) ;
return NULL ;
}
void Descriptor_FromMessageDef ( zval * val , const upb_MessageDef * m ) {
void Descriptor_FromMessageDef ( zval * val , const upb_MessageDef * m ) {
if ( m = = NULL ) {
ZVAL_NULL ( val ) ;
return ;
}
if ( ! ObjCache_Get ( m , val ) ) {
zend_class_entry * ce = NULL ;
zend_class_entry * ce = NULL ;
if ( ! upb_MessageDef_IsMapEntry ( m ) ) { // Map entries don't have a class.
ce = Descriptor_GetGeneratedClass ( m ) ;
if ( ! ce ) {
@ -585,7 +592,7 @@ void Descriptor_FromMessageDef(zval *val, const upb_MessageDef *m) {
}
}
static void Descriptor_FromClassEntry ( zval * val , zend_class_entry * ce ) {
static void Descriptor_FromClassEntry ( zval * val , zend_class_entry * ce ) {
if ( ce ) {
Descriptor_FromMessageDef ( val , NameMap_GetMessage ( ce ) ) ;
} else {
@ -593,7 +600,7 @@ static void Descriptor_FromClassEntry(zval *val, zend_class_entry *ce) {
}
}
static Descriptor * Descriptor_GetFromZval ( zval * val ) {
static Descriptor * Descriptor_GetFromZval ( zval * val ) {
if ( Z_TYPE_P ( val ) = = IS_NULL ) {
return NULL ;
} else {
@ -607,19 +614,19 @@ static Descriptor* Descriptor_GetFromZval(zval *val) {
// These are documented in the header file.
Descriptor * Descriptor_GetFromClassEntry ( zend_class_entry * ce ) {
Descriptor * Descriptor_GetFromClassEntry ( zend_class_entry * ce ) {
zval desc ;
Descriptor_FromClassEntry ( & desc , ce ) ;
return Descriptor_GetFromZval ( & desc ) ;
}
Descriptor * Descriptor_GetFromMessageDef ( const upb_MessageDef * m ) {
Descriptor * Descriptor_GetFromMessageDef ( const upb_MessageDef * m ) {
zval desc ;
Descriptor_FromMessageDef ( & desc , m ) ;
return Descriptor_GetFromZval ( & desc ) ;
}
Descriptor * Descriptor_GetFromFieldDef ( const upb_FieldDef * f ) {
Descriptor * Descriptor_GetFromFieldDef ( const upb_FieldDef * f ) {
return Descriptor_GetFromMessageDef ( upb_FieldDef_MessageSubDef ( f ) ) ;
}
@ -630,9 +637,7 @@ Descriptor* Descriptor_GetFromFieldDef(const upb_FieldDef *f) {
* have two separate EnumDescriptor classes . We use a single class for both
* the public and private descriptor .
*/
PHP_METHOD ( Descriptor , getPublicDescriptor ) {
RETURN_COPY ( getThis ( ) ) ;
}
PHP_METHOD ( Descriptor , getPublicDescriptor ) { RETURN_COPY ( getThis ( ) ) ; }
/*
* Descriptor : : getFullName ( )
@ -640,7 +645,7 @@ PHP_METHOD(Descriptor, getPublicDescriptor) {
* Returns the full name for this message type .
*/
PHP_METHOD ( Descriptor , getFullName ) {
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_STRING ( upb_MessageDef_FullName ( intern - > msgdef ) ) ;
}
@ -651,7 +656,7 @@ PHP_METHOD(Descriptor, getFullName) {
* [ 0 , getFieldCount ( ) - 1 ] .
*/
PHP_METHOD ( Descriptor , getField ) {
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
int count = upb_MessageDef_FieldCount ( intern - > msgdef ) ;
zval ret ;
zend_long index ;
@ -666,7 +671,8 @@ PHP_METHOD(Descriptor, getField) {
return ;
}
FieldDescriptor_FromFieldDef ( & ret , upb_MessageDef_Field ( intern - > msgdef , index ) ) ;
FieldDescriptor_FromFieldDef ( & ret ,
upb_MessageDef_Field ( intern - > msgdef , index ) ) ;
RETURN_COPY_VALUE ( & ret ) ;
}
@ -676,7 +682,7 @@ PHP_METHOD(Descriptor, getField) {
* Returns the number of fields in this message .
*/
PHP_METHOD ( Descriptor , getFieldCount ) {
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( upb_MessageDef_FieldCount ( intern - > msgdef ) ) ;
}
@ -687,7 +693,7 @@ PHP_METHOD(Descriptor, getFieldCount) {
* [ 0 , getOneofDeclCount ( ) ] .
*/
PHP_METHOD ( Descriptor , getOneofDecl ) {
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
zend_long index ;
zval ret ;
@ -701,7 +707,8 @@ PHP_METHOD(Descriptor, getOneofDecl) {
return ;
}
OneofDescriptor_FromOneofDef ( & ret , upb_MessageDef_Oneof ( intern - > msgdef , index ) ) ;
OneofDescriptor_FromOneofDef ( & ret ,
upb_MessageDef_Oneof ( intern - > msgdef , index ) ) ;
RETURN_COPY_VALUE ( & ret ) ;
}
@ -711,7 +718,7 @@ PHP_METHOD(Descriptor, getOneofDecl) {
* Returns the number of oneofs in this message .
*/
PHP_METHOD ( Descriptor , getOneofDeclCount ) {
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
RETURN_LONG ( upb_MessageDef_OneofCount ( intern - > msgdef ) ) ;
}
@ -721,12 +728,12 @@ PHP_METHOD(Descriptor, getOneofDeclCount) {
* Returns the name of the PHP class for this message .
*/
PHP_METHOD ( Descriptor , getClass ) {
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
Descriptor * intern = ( Descriptor * ) Z_OBJ_P ( getThis ( ) ) ;
const char * classname = ZSTR_VAL ( intern - > class_entry - > name ) ;
RETURN_STRING ( classname ) ;
}
// clang-format off
static zend_function_entry Descriptor_methods [ ] = {
PHP_ME ( Descriptor , getClass , arginfo_void , ZEND_ACC_PUBLIC )
PHP_ME ( Descriptor , getFullName , arginfo_void , ZEND_ACC_PUBLIC )
@ -737,6 +744,7 @@ static zend_function_entry Descriptor_methods[] = {
PHP_ME ( Descriptor , getPublicDescriptor , arginfo_void , ZEND_ACC_PUBLIC )
ZEND_FE_END
} ;
// clang-format on
// -----------------------------------------------------------------------------
// DescriptorPool
@ -744,13 +752,13 @@ static zend_function_entry Descriptor_methods[] = {
typedef struct DescriptorPool {
zend_object std ;
upb_DefPool * symtab ;
upb_DefPool * symtab ;
} DescriptorPool ;
zend_class_entry * DescriptorPool_class_entry ;
zend_class_entry * DescriptorPool_class_entry ;
static zend_object_handlers DescriptorPool_object_handlers ;
static DescriptorPool * GetPool ( const zval * this_ptr ) {
static DescriptorPool * GetPool ( const zval * this_ptr ) {
return ( DescriptorPool * ) Z_OBJ_P ( this_ptr ) ;
}
@ -767,8 +775,8 @@ static void DescriptorPool_destructor(zend_object* obj) {
zend_object_std_dtor ( & intern - > std ) ;
}
void DescriptorPool_CreateWithSymbolTable ( zval * zv , upb_DefPool * symtab ) {
DescriptorPool * intern = emalloc ( sizeof ( DescriptorPool ) ) ;
void DescriptorPool_CreateWithSymbolTable ( zval * zv , upb_DefPool * symtab ) {
DescriptorPool * intern = emalloc ( sizeof ( DescriptorPool ) ) ;
zend_object_std_init ( & intern - > std , DescriptorPool_class_entry ) ;
intern - > std . handlers = & DescriptorPool_object_handlers ;
intern - > symtab = symtab ;
@ -776,9 +784,7 @@ void DescriptorPool_CreateWithSymbolTable(zval *zv, upb_DefPool *symtab) {
ZVAL_OBJ ( zv , & intern - > std ) ;
}
upb_DefPool * DescriptorPool_GetSymbolTable ( ) {
return get_global_symtab ( ) ;
}
upb_DefPool * DescriptorPool_GetSymbolTable ( ) { return get_global_symtab ( ) ; }
/*
* DescriptorPool : : getGeneratedPool ( )
@ -795,10 +801,10 @@ PHP_METHOD(DescriptorPool, getGeneratedPool) {
* Returns a Descriptor object for the given PHP class name .
*/
PHP_METHOD ( DescriptorPool , getDescriptorByClassName ) {
char * classname = NULL ;
char * classname = NULL ;
zend_long classname_len ;
zend_class_entry * ce ;
zend_string * str ;
zend_class_entry * ce ;
zend_string * str ;
zval ret ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s " , & classname , & classname_len ) = =
@ -808,7 +814,7 @@ PHP_METHOD(DescriptorPool, getDescriptorByClassName) {
str = zend_string_init ( classname , strlen ( classname ) , 0 ) ;
ce = zend_lookup_class ( str ) ; // May autoload the class.
zend_string_release ( str ) ;
zend_string_release ( str ) ;
if ( ! ce ) {
RETURN_NULL ( ) ;
@ -824,10 +830,10 @@ PHP_METHOD(DescriptorPool, getDescriptorByClassName) {
* Returns a EnumDescriptor object for the given PHP class name .
*/
PHP_METHOD ( DescriptorPool , getEnumDescriptorByClassName ) {
char * classname = NULL ;
char * classname = NULL ;
zend_long classname_len ;
zend_class_entry * ce ;
zend_string * str ;
zend_class_entry * ce ;
zend_string * str ;
zval ret ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s " , & classname , & classname_len ) = =
@ -837,7 +843,7 @@ PHP_METHOD(DescriptorPool, getEnumDescriptorByClassName) {
str = zend_string_init ( classname , strlen ( classname ) , 0 ) ;
ce = zend_lookup_class ( str ) ; // May autoload the class.
zend_string_release ( str ) ;
zend_string_release ( str ) ;
if ( ! ce ) {
RETURN_NULL ( ) ;
@ -853,10 +859,10 @@ PHP_METHOD(DescriptorPool, getEnumDescriptorByClassName) {
* Returns a Descriptor object for the given protobuf message name .
*/
PHP_METHOD ( DescriptorPool , getDescriptorByProtoName ) {
DescriptorPool * intern = GetPool ( getThis ( ) ) ;
char * protoname = NULL ;
DescriptorPool * intern = GetPool ( getThis ( ) ) ;
char * protoname = NULL ;
zend_long protoname_len ;
const upb_MessageDef * m ;
const upb_MessageDef * m ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s " , & protoname , & protoname_len ) = =
FAILURE ) {
@ -880,8 +886,9 @@ PHP_METHOD(DescriptorPool, getDescriptorByProtoName) {
* Returns true if this FileDescriptorProto depends on descriptor . proto .
*/
bool depends_on_descriptor ( const google_protobuf_FileDescriptorProto * file ) {
const upb_StringView * deps ;
upb_StringView name = upb_StringView_FromString ( " google/protobuf/descriptor.proto " ) ;
const upb_StringView * deps ;
upb_StringView name =
upb_StringView_FromString ( " google/protobuf/descriptor.proto " ) ;
size_t i , n ;
deps = google_protobuf_FileDescriptorProto_dependency ( file , & n ) ;
@ -894,7 +901,7 @@ bool depends_on_descriptor(const google_protobuf_FileDescriptorProto* file) {
return false ;
}
static void add_message_name_mappings ( const upb_MessageDef * message ) {
static void add_message_name_mappings ( const upb_MessageDef * message ) {
NameMap_AddMessage ( message ) ;
int msg_n = upb_MessageDef_NestedMessageCount ( message ) ;
for ( int i = 0 ; i < msg_n ; i + + ) {
@ -911,7 +918,7 @@ static void add_message_name_mappings(const upb_MessageDef *message) {
*
* Adds the messages and enums in this file to the NameMap .
*/
static void add_name_mappings ( const upb_FileDef * file ) {
static void add_name_mappings ( const upb_FileDef * file ) {
for ( int i = 0 ; i < upb_FileDef_TopLevelMessageCount ( file ) ; i + + ) {
add_message_name_mappings ( upb_FileDef_TopLevelMessage ( file , i ) ) ;
}
@ -921,11 +928,11 @@ static void add_name_mappings(const upb_FileDef *file) {
}
}
static void add_descriptor ( upb_DefPool * symtab ,
const google_protobuf_FileDescriptorProto * file ) {
static void add_descriptor ( upb_DefPool * symtab ,
const google_protobuf_FileDescriptorProto * file ) {
upb_StringView name = google_protobuf_FileDescriptorProto_name ( file ) ;
upb_Status status ;
const upb_FileDef * file_def ;
const upb_FileDef * file_def ;
upb_Status_Clear ( & status ) ;
if ( upb_DefPool_FindFileByNameWithSize ( symtab , name . data , name . size ) ) {
@ -933,8 +940,8 @@ static void add_descriptor(upb_DefPool *symtab,
// TODO(teboring): Re-enable this warning when aggregate metadata is
// deprecated.
// zend_error(E_USER_WARNING,
// "proto descriptor was previously loaded (included in multiple "
// "metadata bundles?): " UPB_STRINGVIEW_FORMAT,
// "proto descriptor was previously loaded (included in multiple
// " " metadata bundles?): " UPB_STRINGVIEW_FORMAT,
// UPB_STRINGVIEW_ARGS(name));
return ;
}
@ -956,10 +963,10 @@ static void add_descriptor(upb_DefPool *symtab,
*
* Adds the given descriptor data to this DescriptorPool .
*/
static void add_descriptor_set ( upb_DefPool * symtab , const char * data ,
int data_len , upb_Arena * arena ) {
static void add_descriptor_set ( upb_DefPool * symtab , const char * data ,
int data_len , upb_Arena * arena ) {
size_t i , n ;
google_protobuf_FileDescriptorSet * set ;
google_protobuf_FileDescriptorSet * set ;
const google_protobuf_FileDescriptorProto * const * files ;
set = google_protobuf_FileDescriptorSet_parse ( data , data_len , arena ) ;
@ -977,14 +984,14 @@ static void add_descriptor_set(upb_DefPool *symtab, const char *data,
}
}
bool DescriptorPool_HasFile ( const char * filename ) {
bool DescriptorPool_HasFile ( const char * filename ) {
return upb_DefPool_FindFileByName ( get_global_symtab ( ) , filename ) ! = NULL ;
}
void DescriptorPool_AddDescriptor ( const char * filename , const char * data ,
void DescriptorPool_AddDescriptor ( const char * filename , const char * data ,
int size ) {
upb_Arena * arena = upb_Arena_New ( ) ;
const google_protobuf_FileDescriptorProto * file =
upb_Arena * arena = upb_Arena_New ( ) ;
const google_protobuf_FileDescriptorProto * file =
google_protobuf_FileDescriptorProto_parse ( data , size , arena ) ;
if ( ! file ) {
@ -1002,11 +1009,11 @@ void DescriptorPool_AddDescriptor(const char *filename, const char *data,
* Adds the given descriptor data to this DescriptorPool .
*/
PHP_METHOD ( DescriptorPool , internalAddGeneratedFile ) {
DescriptorPool * intern = GetPool ( getThis ( ) ) ;
char * data = NULL ;
DescriptorPool * intern = GetPool ( getThis ( ) ) ;
char * data = NULL ;
zend_long data_len ;
zend_bool use_nested_submsg = false ;
upb_Arena * arena ;
upb_Arena * arena ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " s|b " , & data , & data_len ,
& use_nested_submsg ) ! = SUCCESS ) {
@ -1018,6 +1025,7 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
upb_Arena_Free ( arena ) ;
}
// clang-format off
ZEND_BEGIN_ARG_INFO_EX ( arginfo_lookupByName , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , name )
ZEND_END_ARG_INFO ( )
@ -1036,6 +1044,7 @@ static zend_function_entry DescriptorPool_methods[] = {
PHP_ME ( DescriptorPool , internalAddGeneratedFile , arginfo_addgeneratedfile , ZEND_ACC_PUBLIC )
ZEND_FE_END
} ;
// clang-format on
// -----------------------------------------------------------------------------
// InternalDescriptorPool
@ -1045,7 +1054,7 @@ static zend_function_entry DescriptorPool_methods[] = {
// separate instantiable object, it just returns a
// Google\Protobuf\DescriptorPool.
zend_class_entry * InternalDescriptorPool_class_entry ;
zend_class_entry * InternalDescriptorPool_class_entry ;
/*
* InternalDescriptorPool : : getGeneratedPool ( )
@ -1058,11 +1067,13 @@ PHP_METHOD(InternalDescriptorPool, getGeneratedPool) {
DescriptorPool_CreateWithSymbolTable ( return_value , get_global_symtab ( ) ) ;
}
// clang-format off
static zend_function_entry InternalDescriptorPool_methods [ ] = {
PHP_ME ( InternalDescriptorPool , getGeneratedPool , arginfo_void ,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
ZEND_FE_END
} ;
// clang-format on
// -----------------------------------------------------------------------------
// GPBType
@ -1070,9 +1081,7 @@ static zend_function_entry InternalDescriptorPool_methods[] = {
zend_class_entry * gpb_type_type ;
static zend_function_entry gpb_type_methods [ ] = {
ZEND_FE_END
} ;
static zend_function_entry gpb_type_methods [ ] = { ZEND_FE_END } ;
// -----------------------------------------------------------------------------
// Module Init
@ -1080,7 +1089,7 @@ static zend_function_entry gpb_type_methods[] = {
void Def_ModuleInit ( ) {
zend_class_entry tmp_ce ;
zend_object_handlers * h ;
zend_object_handlers * h ;
INIT_CLASS_ENTRY ( tmp_ce , " Google \\ Protobuf \\ OneofDescriptor " ,
OneofDescriptor_methods ) ;
@ -1108,8 +1117,7 @@ void Def_ModuleInit() {
memcpy ( h , & std_object_handlers , sizeof ( zend_object_handlers ) ) ;
h - > dtor_obj = & EnumDescriptor_destructor ;
INIT_CLASS_ENTRY ( tmp_ce , " Google \\ Protobuf \\ Descriptor " ,
Descriptor_methods ) ;
INIT_CLASS_ENTRY ( tmp_ce , " Google \\ Protobuf \\ Descriptor " , Descriptor_methods ) ;
Descriptor_class_entry = zend_register_internal_class ( & tmp_ce ) ;
Descriptor_class_entry - > ce_flags | = ZEND_ACC_FINAL ;