aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jie Luo <anandolee@gmail.com>2018-02-09 15:54:03 -0800
committerGravatar GitHub <noreply@github.com>2018-02-09 15:54:03 -0800
commite34ec6077af141dd5dfc1c334ecdcce3c6b51612 (patch)
treead0a605d6d67f9c7f12df43dcb5ee103f8405844
parent96b535cc2f4f7b7e22a1b8622149f7c26a5a3f63 (diff)
Only check filenames when end with .py in _CalledFromGeneratedFile() (#4262)
* Cython's stack does not have .py file name. Only check filenames when end with .py for _CalledFromGeneratedFile()
-rw-r--r--python/google/protobuf/pyext/descriptor.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc
index 9634ea05..6bbc92b9 100644
--- a/python/google/protobuf/pyext/descriptor.cc
+++ b/python/google/protobuf/pyext/descriptor.cc
@@ -107,10 +107,6 @@ bool _CalledFromGeneratedFile(int stacklevel) {
return false;
}
}
- if (frame->f_globals != frame->f_locals) {
- // Not at global module scope
- return false;
- }
if (frame->f_code->co_filename == NULL) {
return false;
@@ -123,6 +119,10 @@ bool _CalledFromGeneratedFile(int stacklevel) {
PyErr_Clear();
return false;
}
+ if ((filename_size < 3) || (strcmp(&filename[filename_size - 3], ".py") != 0)) {
+ // Cython's stack does not have .py file name and is not at global module scope.
+ return true;
+ }
if (filename_size < 7) {
// filename is too short.
return false;
@@ -131,6 +131,11 @@ bool _CalledFromGeneratedFile(int stacklevel) {
// Filename is not ending with _pb2.
return false;
}
+
+ if (frame->f_globals != frame->f_locals) {
+ // Not at global module scope
+ return false;
+ }
#endif
return true;
}