瀏覽代碼

Cython is not using .py file. Only check filenames when end with .py for _CalledFromGeneratedFile()

Jie Luo 7 年之前
父節點
當前提交
5fcc8e3994
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      python/google/protobuf/pyext/descriptor.cc

+ 6 - 3
python/google/protobuf/pyext/descriptor.cc

@@ -127,9 +127,12 @@ bool _CalledFromGeneratedFile(int stacklevel) {
     // filename is too short.
     return false;
   }
-  if (strcmp(&filename[filename_size - 7], "_pb2.py") != 0) {
-    // Filename is not ending with _pb2.
-    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.
+      return false;
+    }
   }
 #endif
   return true;