Skip to content

Commit

Permalink
Internal changes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 495152163
  • Loading branch information
mkruskal-google authored and copybara-github committed Dec 14, 2022
1 parent 0dd27f9 commit bfed218
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 108 deletions.
24 changes: 12 additions & 12 deletions conformance/conformance_test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ using std::vector;

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define GOOGLE_CHECK_SYSCALL(call) \
#define CHECK_SYSCALL(call) \
if (call < 0) { \
perror(#call " " __FILE__ ":" TOSTRING(__LINE__)); \
exit(1); \
Expand Down Expand Up @@ -289,22 +289,22 @@ void ForkPipeRunner::SpawnTestProgram() {

if (pid) {
// Parent.
GOOGLE_CHECK_SYSCALL(close(toproc_pipe_fd[0]));
GOOGLE_CHECK_SYSCALL(close(fromproc_pipe_fd[1]));
CHECK_SYSCALL(close(toproc_pipe_fd[0]));
CHECK_SYSCALL(close(fromproc_pipe_fd[1]));
write_fd_ = toproc_pipe_fd[1];
read_fd_ = fromproc_pipe_fd[0];
child_pid_ = pid;
} else {
// Child.
GOOGLE_CHECK_SYSCALL(close(STDIN_FILENO));
GOOGLE_CHECK_SYSCALL(close(STDOUT_FILENO));
GOOGLE_CHECK_SYSCALL(dup2(toproc_pipe_fd[0], STDIN_FILENO));
GOOGLE_CHECK_SYSCALL(dup2(fromproc_pipe_fd[1], STDOUT_FILENO));
CHECK_SYSCALL(close(STDIN_FILENO));
CHECK_SYSCALL(close(STDOUT_FILENO));
CHECK_SYSCALL(dup2(toproc_pipe_fd[0], STDIN_FILENO));
CHECK_SYSCALL(dup2(fromproc_pipe_fd[1], STDOUT_FILENO));

GOOGLE_CHECK_SYSCALL(close(toproc_pipe_fd[0]));
GOOGLE_CHECK_SYSCALL(close(fromproc_pipe_fd[1]));
GOOGLE_CHECK_SYSCALL(close(toproc_pipe_fd[1]));
GOOGLE_CHECK_SYSCALL(close(fromproc_pipe_fd[0]));
CHECK_SYSCALL(close(toproc_pipe_fd[0]));
CHECK_SYSCALL(close(fromproc_pipe_fd[1]));
CHECK_SYSCALL(close(toproc_pipe_fd[1]));
CHECK_SYSCALL(close(fromproc_pipe_fd[0]));

std::unique_ptr<char[]> executable(new char[executable_.size() + 1]);
memcpy(executable.get(), executable_.c_str(), executable_.size());
Expand All @@ -319,7 +319,7 @@ void ForkPipeRunner::SpawnTestProgram() {
}
argv.push_back(nullptr);
// Never returns.
GOOGLE_CHECK_SYSCALL(execv(executable.get(), const_cast<char **>(argv.data())));
CHECK_SYSCALL(execv(executable.get(), const_cast<char **>(argv.data())));
}
}

Expand Down
4 changes: 3 additions & 1 deletion python/google/protobuf/pyext/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "google/protobuf/pyext/descriptor.h"

#include "google/protobuf/stubs/logging.h"

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <frameobject.h>
Expand Down Expand Up @@ -404,7 +406,7 @@ PyObject* NewInternedDescriptor(PyTypeObject* type,
std::unordered_map<const void*, PyObject*>::iterator it =
interned_descriptors->find(descriptor);
if (it != interned_descriptors->end()) {
GOOGLE_DCHECK(Py_TYPE(it->second) == type);
GOOGLE_ABSL_DCHECK(Py_TYPE(it->second) == type);
Py_INCREF(it->second);
return it->second;
}
Expand Down
15 changes: 7 additions & 8 deletions python/google/protobuf/pyext/descriptor_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include <string>
#include <vector>

#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/pyext/message.h"
#include "google/protobuf/pyext/scoped_pyobject_ptr.h"

Expand All @@ -62,7 +62,7 @@ static bool GetFileDescriptorProto(PyObject* py_descriptor,
// Expected error: item was simply not found.
PyErr_Clear();
} else {
GOOGLE_LOG(ERROR) << "DescriptorDatabase method raised an error";
GOOGLE_ABSL_LOG(ERROR) << "DescriptorDatabase method raised an error";
PyErr_Print();
}
return false;
Expand All @@ -86,22 +86,22 @@ static bool GetFileDescriptorProto(PyObject* py_descriptor,
ScopedPyObjectPtr serialized_pb(
PyObject_CallMethod(py_descriptor, "SerializeToString", nullptr));
if (serialized_pb == nullptr) {
GOOGLE_LOG(ERROR)
GOOGLE_ABSL_LOG(ERROR)
<< "DescriptorDatabase method did not return a FileDescriptorProto";
PyErr_Print();
return false;
}
char* str;
Py_ssize_t len;
if (PyBytes_AsStringAndSize(serialized_pb.get(), &str, &len) < 0) {
GOOGLE_LOG(ERROR)
GOOGLE_ABSL_LOG(ERROR)
<< "DescriptorDatabase method did not return a FileDescriptorProto";
PyErr_Print();
return false;
}
FileDescriptorProto file_proto;
if (!file_proto.ParseFromArray(str, len)) {
GOOGLE_LOG(ERROR)
GOOGLE_ABSL_LOG(ERROR)
<< "DescriptorDatabase method did not return a FileDescriptorProto";
return false;
}
Expand Down Expand Up @@ -172,9 +172,8 @@ bool PyDescriptorDatabase::FindAllExtensionNumbers(
ScopedPyObjectPtr item(PySequence_GetItem(py_list.get(), i));
item_value = PyLong_AsLong(item.get());
if (item_value < 0) {
GOOGLE_LOG(ERROR)
<< "FindAllExtensionNumbers method did not return "
<< "valid extension numbers.";
GOOGLE_ABSL_LOG(ERROR) << "FindAllExtensionNumbers method did not return "
<< "valid extension numbers.";
PyErr_Print();
return false;
}
Expand Down
1 change: 0 additions & 1 deletion python/google/protobuf/pyext/extension_dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <memory>
#include <vector>

#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/dynamic_message.h"
Expand Down
27 changes: 13 additions & 14 deletions python/google/protobuf/pyext/map_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <memory>
#include <string>

#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/map.h"
#include "google/protobuf/map_field.h"
#include "google/protobuf/message.h"
Expand Down Expand Up @@ -125,27 +124,27 @@ static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
self->parent_field_descriptor->message_type()->map_key();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
GOOGLE_CHECK_GET_INT32(obj, value, false);
PROTOBUF_CHECK_GET_INT32(obj, value, false);
key->SetInt32Value(value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
GOOGLE_CHECK_GET_INT64(obj, value, false);
PROTOBUF_CHECK_GET_INT64(obj, value, false);
key->SetInt64Value(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
GOOGLE_CHECK_GET_UINT32(obj, value, false);
PROTOBUF_CHECK_GET_UINT32(obj, value, false);
key->SetUInt32Value(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
GOOGLE_CHECK_GET_UINT64(obj, value, false);
PROTOBUF_CHECK_GET_UINT64(obj, value, false);
key->SetUInt64Value(value);
break;
}
case FieldDescriptor::CPPTYPE_BOOL: {
GOOGLE_CHECK_GET_BOOL(obj, value, false);
PROTOBUF_CHECK_GET_BOOL(obj, value, false);
key->SetBoolValue(value);
break;
}
Expand Down Expand Up @@ -231,37 +230,37 @@ static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
self->parent_field_descriptor->message_type()->map_value();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
GOOGLE_CHECK_GET_INT32(obj, value, false);
PROTOBUF_CHECK_GET_INT32(obj, value, false);
value_ref->SetInt32Value(value);
return true;
}
case FieldDescriptor::CPPTYPE_INT64: {
GOOGLE_CHECK_GET_INT64(obj, value, false);
PROTOBUF_CHECK_GET_INT64(obj, value, false);
value_ref->SetInt64Value(value);
return true;
}
case FieldDescriptor::CPPTYPE_UINT32: {
GOOGLE_CHECK_GET_UINT32(obj, value, false);
PROTOBUF_CHECK_GET_UINT32(obj, value, false);
value_ref->SetUInt32Value(value);
return true;
}
case FieldDescriptor::CPPTYPE_UINT64: {
GOOGLE_CHECK_GET_UINT64(obj, value, false);
PROTOBUF_CHECK_GET_UINT64(obj, value, false);
value_ref->SetUInt64Value(value);
return true;
}
case FieldDescriptor::CPPTYPE_FLOAT: {
GOOGLE_CHECK_GET_FLOAT(obj, value, false);
PROTOBUF_CHECK_GET_FLOAT(obj, value, false);
value_ref->SetFloatValue(value);
return true;
}
case FieldDescriptor::CPPTYPE_DOUBLE: {
GOOGLE_CHECK_GET_DOUBLE(obj, value, false);
PROTOBUF_CHECK_GET_DOUBLE(obj, value, false);
value_ref->SetDoubleValue(value);
return true;
}
case FieldDescriptor::CPPTYPE_BOOL: {
GOOGLE_CHECK_GET_BOOL(obj, value, false);
PROTOBUF_CHECK_GET_BOOL(obj, value, false);
value_ref->SetBoolValue(value);
return true;
}
Expand All @@ -274,7 +273,7 @@ static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
return true;
}
case FieldDescriptor::CPPTYPE_ENUM: {
GOOGLE_CHECK_GET_INT32(obj, value, false);
PROTOBUF_CHECK_GET_INT32(obj, value, false);
if (allow_unknown_enum_values) {
value_ref->SetEnumValue(value);
return true;
Expand Down
43 changes: 22 additions & 21 deletions python/google/protobuf/pyext/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <string>
#include <vector>

#include "google/protobuf/stubs/logging.h"
#include "absl/strings/match.h"

#ifndef PyVarObject_HEAD_INIT
Expand All @@ -51,7 +52,6 @@
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/message.h"
Expand Down Expand Up @@ -252,10 +252,10 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
if (WKT_classes == nullptr) {
ScopedPyObjectPtr well_known_types(
PyImport_ImportModule(PROTOBUF_PYTHON_INTERNAL ".well_known_types"));
GOOGLE_DCHECK(well_known_types != nullptr);
GOOGLE_ABSL_DCHECK(well_known_types != nullptr);

WKT_classes = PyObject_GetAttrString(well_known_types.get(), "WKTBASES");
GOOGLE_DCHECK(WKT_classes != nullptr);
GOOGLE_ABSL_DCHECK(WKT_classes != nullptr);
}

PyObject* well_known_class = PyDict_GetItemString(
Expand Down Expand Up @@ -680,8 +680,8 @@ bool IsValidUTF8(PyObject* obj) {
bool AllowInvalidUTF8(const FieldDescriptor* field) { return false; }

PyObject* CheckString(PyObject* arg, const FieldDescriptor* descriptor) {
GOOGLE_DCHECK(descriptor->type() == FieldDescriptor::TYPE_STRING ||
descriptor->type() == FieldDescriptor::TYPE_BYTES);
GOOGLE_ABSL_DCHECK(descriptor->type() == FieldDescriptor::TYPE_STRING ||
descriptor->type() == FieldDescriptor::TYPE_BYTES);
if (descriptor->type() == FieldDescriptor::TYPE_STRING) {
if (!PyBytes_Check(arg) && !PyUnicode_Check(arg)) {
FormatTypeError(arg, "bytes, unicode");
Expand Down Expand Up @@ -784,7 +784,7 @@ bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
namespace cmessage {

PyMessageFactory* GetFactoryForMessage(CMessage* message) {
GOOGLE_DCHECK(PyObject_TypeCheck(message, CMessage_Type));
GOOGLE_ABSL_DCHECK(PyObject_TypeCheck(message, CMessage_Type));
return reinterpret_cast<CMessageClass*>(Py_TYPE(message))->py_message_factory;
}

Expand Down Expand Up @@ -856,7 +856,7 @@ int AssureWritable(CMessage* self) {
}

// Toplevel messages are always mutable.
GOOGLE_DCHECK(self->parent);
GOOGLE_ABSL_DCHECK(self->parent);

if (AssureWritable(self->parent) == -1) {
return -1;
Expand Down Expand Up @@ -988,7 +988,7 @@ int DeleteRepeatedField(
}

Arena* arena = Arena::InternalGetArenaForAllocation(message);
GOOGLE_DCHECK_EQ(arena, nullptr)
GOOGLE_ABSL_DCHECK_EQ(arena, nullptr)
<< "python protobuf is expected to be allocated from heap";
// Remove items, starting from the end.
for (; length > to; length--) {
Expand All @@ -1001,9 +1001,10 @@ int DeleteRepeatedField(
//
// To work around a debug hardening (PROTOBUF_FORCE_COPY_IN_RELEASE),
// explicitly use UnsafeArenaReleaseLast. To not break rare use cases where
// arena is used, we fallback to ReleaseLast (but GOOGLE_DCHECK to find/fix it).
// arena is used, we fallback to ReleaseLast (but GOOGLE_ABSL_DCHECK to find/fix
// it).
//
// Note that arena is likely null and GOOGLE_DCHECK and ReleaesLast might be
// Note that arena is likely null and GOOGLE_ABSL_DCHECK and ReleaesLast might be
// redundant. The current approach takes extra cautious path not to disrupt
// production.
Message* sub_message =
Expand Down Expand Up @@ -1268,8 +1269,8 @@ static void Dealloc(CMessage* self) {
PyObject_ClearWeakRefs(reinterpret_cast<PyObject*>(self));
}
// At this point all dependent objects have been removed.
GOOGLE_DCHECK(!self->child_submessages || self->child_submessages->empty());
GOOGLE_DCHECK(!self->composite_fields || self->composite_fields->empty());
GOOGLE_ABSL_DCHECK(!self->child_submessages || self->child_submessages->empty());
GOOGLE_ABSL_DCHECK(!self->composite_fields || self->composite_fields->empty());
delete self->child_submessages;
delete self->composite_fields;
if (self->unknown_field_set) {
Expand Down Expand Up @@ -1714,7 +1715,7 @@ static PyObject* InternalSerializeToString(
coded_out.SetSerializationDeterministic(deterministic);
}
self->message->SerializeWithCachedSizes(&coded_out);
GOOGLE_CHECK(!coded_out.HadError());
GOOGLE_ABSL_CHECK(!coded_out.HadError());
return result;
}

Expand Down Expand Up @@ -2256,37 +2257,37 @@ int InternalSetNonOneofScalar(

switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
GOOGLE_CHECK_GET_INT32(arg, value, -1);
PROTOBUF_CHECK_GET_INT32(arg, value, -1);
reflection->SetInt32(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
GOOGLE_CHECK_GET_INT64(arg, value, -1);
PROTOBUF_CHECK_GET_INT64(arg, value, -1);
reflection->SetInt64(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
GOOGLE_CHECK_GET_UINT32(arg, value, -1);
PROTOBUF_CHECK_GET_UINT32(arg, value, -1);
reflection->SetUInt32(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
GOOGLE_CHECK_GET_UINT64(arg, value, -1);
PROTOBUF_CHECK_GET_UINT64(arg, value, -1);
reflection->SetUInt64(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_FLOAT: {
GOOGLE_CHECK_GET_FLOAT(arg, value, -1);
PROTOBUF_CHECK_GET_FLOAT(arg, value, -1);
reflection->SetFloat(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE: {
GOOGLE_CHECK_GET_DOUBLE(arg, value, -1);
PROTOBUF_CHECK_GET_DOUBLE(arg, value, -1);
reflection->SetDouble(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_BOOL: {
GOOGLE_CHECK_GET_BOOL(arg, value, -1);
PROTOBUF_CHECK_GET_BOOL(arg, value, -1);
reflection->SetBool(message, field_descriptor, value);
break;
}
Expand All @@ -2298,7 +2299,7 @@ int InternalSetNonOneofScalar(
break;
}
case FieldDescriptor::CPPTYPE_ENUM: {
GOOGLE_CHECK_GET_INT32(arg, value, -1);
PROTOBUF_CHECK_GET_INT32(arg, value, -1);
if (reflection->SupportsUnknownEnumValues()) {
reflection->SetEnumValue(message, field_descriptor, value);
} else {
Expand Down
Loading

0 comments on commit bfed218

Please sign in to comment.