Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
60d95f36
Commit
60d95f36
authored
Oct 11, 2016
by
Paul Yang
Committed by
GitHub
Oct 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the bug that message without namespace is not found in the descriptor pool. (#2240)
parent
0321baf9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
23 deletions
+83
-23
Makefile.am
Makefile.am
+2
-0
def.c
php/ext/google/protobuf/def.c
+26
-20
descriptor.php
php/src/Google/Protobuf/descriptor.php
+7
-3
generated_class_test.php
php/tests/generated_class_test.php
+9
-0
test_no_namespace.pb.php
php/tests/test_no_namespace.pb.php
+34
-0
test_no_namespace.proto
php/tests/test_no_namespace.proto
+5
-0
No files found.
Makefile.am
View file @
60d95f36
...
...
@@ -600,6 +600,8 @@ php_EXTRA_DIST= \
php/tests/test_include.pb.php
\
php/tests/map_field_test.php
\
php/tests/test_base.php
\
php/tests/test_no_namespace.proto
\
php/tests/test_no_namespace.pb.php
\
php/tests/test_util.php
\
php/tests/test.proto
\
php/tests/test.pb.php
\
...
...
php/ext/google/protobuf/def.c
View file @
60d95f36
...
...
@@ -250,28 +250,36 @@ PHP_METHOD(DescriptorPool, getGeneratedPool) {
RETURN_ZVAL
(
generated_pool_php
,
1
,
0
);
}
static
void
convert_to_class_name_inplace
(
char
*
proto_name
,
size_t
pkg_name_len
)
{
static
void
convert_to_class_name_inplace
(
char
*
class_name
,
const
char
*
fullname
,
const
char
*
package_name
)
{
size_t
i
;
bool
first_char
=
false
;
for
(
i
=
0
;
i
<=
pkg_name_len
+
1
;
i
++
)
{
// PHP package uses camel case.
if
(
!
first_char
&&
proto_name
[
i
]
!=
'.'
)
{
first_char
=
true
;
proto_name
[
i
]
+=
'A'
-
'a'
;
}
// php packages are divided by '\'.
if
(
proto_name
[
i
]
==
'.'
)
{
first_char
=
false
;
proto_name
[
i
]
=
'\\'
;
size_t
pkg_name_len
=
package_name
==
NULL
?
0
:
strlen
(
package_name
);
if
(
pkg_name_len
==
0
)
{
strcpy
(
class_name
,
fullname
);
}
else
{
class_name
[
0
]
=
'.'
;
strcpy
(
&
class_name
[
1
],
fullname
);
for
(
i
=
0
;
i
<=
pkg_name_len
+
1
;
i
++
)
{
// PHP package uses camel case.
if
(
!
first_char
&&
class_name
[
i
]
!=
'.'
)
{
first_char
=
true
;
class_name
[
i
]
+=
'A'
-
'a'
;
}
// php packages are divided by '\'.
if
(
class_name
[
i
]
==
'.'
)
{
first_char
=
false
;
class_name
[
i
]
=
'\\'
;
}
}
}
// Submessage is concatenated with its containing messages by '_'.
for
(
i
=
pkg_name_len
;
i
<
strlen
(
proto
_name
);
i
++
)
{
if
(
proto
_name
[
i
]
==
'.'
)
{
proto
_name
[
i
]
=
'_'
;
for
(
i
=
pkg_name_len
;
i
<
strlen
(
class
_name
);
i
++
)
{
if
(
class
_name
[
i
]
==
'.'
)
{
class
_name
[
i
]
=
'_'
;
}
}
}
...
...
@@ -325,10 +333,8 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
/* Prepend '.' to package name to make it absolute. */
\
const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \
char *klass_name = ecalloc(sizeof(char), 2 + strlen(fullname)); \
klass_name[0] = '.'; \
strcpy(&klass_name[1], fullname); \
size_t pkg_name_len = strlen(upb_filedef_package(files[0])); \
convert_to_class_name_inplace(klass_name, pkg_name_len); \
convert_to_class_name_inplace(klass_name, fullname, \
upb_filedef_package(files[0])); \
zend_class_entry **pce; \
if (zend_lookup_class(klass_name, strlen(klass_name), &pce TSRMLS_CC) == \
FAILURE) { \
...
...
php/src/Google/Protobuf/descriptor.php
View file @
60d95f36
...
...
@@ -240,9 +240,13 @@ function getFullClassName(
$class_name_without_package
=
implode
(
'_'
,
array_map
(
'ucwords'
,
explode
(
'.'
,
$message_name_without_package
)));
$classname
=
implode
(
'\\'
,
array_map
(
'ucwords'
,
explode
(
'.'
,
$package
)))
.
"
\\
"
.
$class_name_without_package
;
if
(
$package
===
""
)
{
$classname
=
$class_name_without_package
;
}
else
{
$classname
=
implode
(
'\\'
,
array_map
(
'ucwords'
,
explode
(
'.'
,
$package
)))
.
"
\\
"
.
$class_name_without_package
;
}
}
class
OneofDescriptor
...
...
php/tests/generated_class_test.php
View file @
60d95f36
<?php
require_once
(
'test.pb.php'
);
require_once
(
'test_no_namespace.pb.php'
);
require_once
(
'test_util.php'
);
use
Google\Protobuf\Internal\RepeatedField
;
...
...
@@ -554,4 +555,12 @@ class GeneratedClassTest extends PHPUnit_Framework_TestCase
$this
->
assertSame
(
''
,
$m
->
getOneofString
());
$this
->
assertSame
(
1
,
$m
->
getOneofMessage
()
->
getA
());
}
#########################################################
# Test oneof field.
#########################################################
public
function
testMessageWithoutNamespace
()
{
$m
=
new
NoNameSpace
();
}
}
php/tests/test_no_namespace.pb.php
0 → 100644
View file @
60d95f36
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: test_no_namespace.proto
use
Google\Protobuf\Internal\DescriptorPool
;
use
Google\Protobuf\Internal\GPBType
;
use
Google\Protobuf\Internal\RepeatedField
;
use
Google\Protobuf\Internal\GPBUtil
;
class
NoNameSpace
extends
\Google\Protobuf\Internal\Message
{
private
$a
=
0
;
public
function
getA
()
{
return
$this
->
a
;
}
public
function
setA
(
$var
)
{
GPBUtil
::
checkInt32
(
$var
);
$this
->
a
=
$var
;
}
}
$pool
=
DescriptorPool
::
getGeneratedPool
();
$pool
->
internalAddGeneratedFile
(
hex2bin
(
"0a3b0a17746573745f6e6f5f6e616d6573706163652e70726f746f22180a"
.
"0b4e6f4e616d65537061636512090a0161180120012805620670726f746f"
.
"33"
));
php/tests/test_no_namespace.proto
0 → 100644
View file @
60d95f36
syntax
=
"proto3"
;
message
NoNameSpace
{
int32
a
=
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment