internal change

PiperOrigin-RevId: 572965793
pull/14355/head
Jie Luo 1 year ago committed by Copybara-Service
parent 312986896d
commit 656d62ae32
  1. 23
      python/google/protobuf/link_error_fast_cpp.cc
  2. 23
      python/google/protobuf/link_error_pure_python.cc
  3. 24
      python/google/protobuf/link_error_upb.cc
  4. 40
      python/google/protobuf/use_fast_cpp_protos.cc
  5. 40
      python/google/protobuf/use_pure_python.cc
  6. 40
      python/google/protobuf/use_upb_protos.cc
  7. 2
      python/pb_unit_tests/pyproto_test_wrapper.bzl

@ -0,0 +1,23 @@
// go/fastpythonproto
namespace google {
namespace protobuf {
namespace python {
// This exists solely to cause a build/link time error when both
// :use_fast_cpp_protos and :use_pure_python are specified in a build.;
extern "C" {
// MUST match link_error_pure_python.cc's function signature.
__attribute__((noinline)) __attribute__((optnone)) int
go_SLASH_build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python() {
return 1;
}
} // extern "C"
} // namespace python
} // namespace protobuf
} // namespace google

@ -0,0 +1,23 @@
// go/fastpythonproto
namespace google {
namespace protobuf {
namespace python {
// This exists solely to cause a build/link time error when both
// :use_fast_cpp_protos and :use_pure_python are specified in a build.;
extern "C" {
// MUST match link_error_pure_python.cc's function signature.
__attribute__((noinline)) __attribute__((optnone)) int
go_SLASH_build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python() {
return 0;
}
} // extern "C"
} // namespace python
} // namespace protobuf
} // namespace google

@ -0,0 +1,24 @@
// go/fastpythonproto
namespace google {
namespace protobuf {
namespace python {
// This exists solely to cause a build/link time error when either
// :use_fast_cpp_protos and :use_pure_python are specified in a build
// in addition to :use_upb_protos.;
extern "C" {
// MUST match link_error_pure_python.cc's function signature.
__attribute__((noinline)) __attribute__((optnone)) int
go_SLASH_build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python() {
return 2;
}
} // extern "C"
} // namespace python
} // namespace protobuf
} // namespace google

@ -0,0 +1,40 @@
// go/fastpythonproto
#include <Python.h>
namespace google {
namespace protobuf {
namespace python {
static const char* kModuleName = "_use_fast_cpp_protos";
static const char kModuleDocstring[] =
"The presence of this module in a build's deps signals to\n"
"net.google.protobuf.internal.api_implementation that the fast\n"
"C++ protobuf implementation should be the default.\n";
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
kModuleName,
kModuleDocstring,
-1,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr};
extern "C" {
PyMODINIT_FUNC PyInit__use_fast_cpp_protos() {
PyObject* module = PyModule_Create(&_module);
if (module == nullptr) {
return nullptr;
}
return module;
}
} // extern "C"
} // namespace python
} // namespace protobuf
} // namespace google

@ -0,0 +1,40 @@
// The opposite side of go/fastpythonproto.
#include <Python.h>
namespace google {
namespace protobuf {
namespace python {
static const char* kModuleName = "use_pure_python";
static const char kModuleDocstring[] =
"The presence of this module in a build's deps signals to\n"
"net.google.protobuf.internal.api_implementation that the pure\n"
"Python protobuf implementation should be used.\n";
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
kModuleName,
kModuleDocstring,
-1,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr};
extern "C" {
PyMODINIT_FUNC PyInit_use_pure_python() {
PyObject* module = PyModule_Create(&_module);
if (module == nullptr) {
return nullptr;
}
return module;
}
}
} // namespace python
} // namespace protobuf
} // namespace google

@ -0,0 +1,40 @@
// go/fastpythonproto
#include <Python.h>
namespace google {
namespace protobuf {
namespace python {
static const char* kModuleName = "_use_upb_protos";
static const char kModuleDocstring[] =
"The presence of this module in a build's deps signals to\n"
"net.google.protobuf.internal.api_implementation that the upb\n"
"protobuf implementation should be the default.\n";
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
kModuleName,
kModuleDocstring,
-1,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr};
extern "C" {
PyMODINIT_FUNC PyInit__use_upb_protos() {
PyObject* module = PyModule_Create(&_module);
if (module == nullptr) {
return nullptr;
}
return module;
}
} // extern "C"
} // namespace python
} // namespace protobuf
} // namespace google

@ -35,7 +35,7 @@ def pyproto_test_wrapper(name, deps = []):
# main = src,
# deps = [
# "//third_party/py/google/protobuf/internal:" + name + "_for_deps",
# "//net/proto2/python/public:use_upb_protos",
# "//third_party/py/google/protobuf:use_upb_protos",
# ],
# target_compatible_with = select({
# "@platforms//os:windows": ["@platforms//:incompatible"],

Loading…
Cancel
Save