aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJie Luo <anandolee@gmail.com>2018-02-07 11:06:01 -0800
committerGitHub <noreply@github.com>2018-02-07 11:06:01 -0800
commit568db69246c444c69c884895159ba83fb1e98f9e (patch)
tree846d2c45f2d103da2e8223825e7f0478d603fd2d
parent5fcc8e39949799e2fdbeaa1237c0e55f1716449a (diff)
downloadprotobuf-568db69246c444c69c884895159ba83fb1e98f9e.tar.gz
protobuf-568db69246c444c69c884895159ba83fb1e98f9e.tar.bz2
protobuf-568db69246c444c69c884895159ba83fb1e98f9e.zip
Do not check global module scope for Cython
-rw-r--r--python/google/protobuf/pyext/descriptor.cc36
1 files changed, 21 insertions, 15 deletions
diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc
index 3526fc1c..12f3df41 100644
--- a/python/google/protobuf/pyext/descriptor.cc
+++ b/python/google/protobuf/pyext/descriptor.cc
@@ -101,20 +101,11 @@ bool _CalledFromGeneratedFile(int stacklevel) {
if (frame == NULL) {
return false;
}
- while (stacklevel-- > 0) {
- frame = frame->f_back;
- if (frame == NULL) {
- 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;
}
+
char* filename;
Py_ssize_t filename_size;
if (PyString_AsStringAndSize(frame->f_code->co_filename,
@@ -123,17 +114,32 @@ bool _CalledFromGeneratedFile(int stacklevel) {
PyErr_Clear();
return false;
}
+
+ if (filename_size < 3 or strcmp(&filename[filename_size - 3], ".py") != 0) {
+ // Cython is not using .py file and not at global module scope.
+ return true;
+ }
+
if (filename_size < 7) {
// filename is too short.
return false;
}
- // Cython is not using .py file. Only check filenames when end with .py
- if (strcmp(&filename[filename_size - 3], ".py") == 0) {
- if (strcmp(&filename[filename_size - 7], "_pb2.py") != 0) {
- // Filename is not ending with _pb2.
+
+ if (strcmp(&filename[filename_size - 7], "_pb2.py") != 0) {
+ // Filename is not ending with _pb2.
+ return false;
+ }
+
+ while (stacklevel-- > 0) {
+ frame = frame->f_back;
+ if (frame == NULL) {
return false;
}
}
+ if (frame->f_globals != frame->f_locals) {
+ // Not at global module scope
+ return false;
+ }
#endif
return true;
}