aboutsummaryrefslogtreecommitdiff
path: root/python/google/protobuf/pyext/message.h
diff options
context:
space:
mode:
Diffstat (limited to 'python/google/protobuf/pyext/message.h')
-rw-r--r--python/google/protobuf/pyext/message.h49
1 files changed, 26 insertions, 23 deletions
diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h
index 72bcfa83..c112a88f 100644
--- a/python/google/protobuf/pyext/message.h
+++ b/python/google/protobuf/pyext/message.h
@@ -38,6 +38,7 @@
#include <memory>
#include <string>
+#include <unordered_map>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/pyext/thread_unsafe_shared_ptr.h>
@@ -96,26 +97,25 @@ typedef struct CMessage {
// made writable, at which point this field is set to false.
bool read_only;
- // A reference to a Python dictionary containing CMessage,
+ // A mapping indexed by field, containing CMessage,
// RepeatedCompositeContainer, and RepeatedScalarContainer
// objects. Used as a cache to make sure we don't have to make a
// Python wrapper for the C++ Message objects on every access, or
// deal with the synchronization nightmare that could create.
- PyObject* composite_fields;
+ // Also cache extension fields.
+ // The FieldDescriptor is owned by the message's pool; PyObject references
+ // are owned.
+ typedef std::unordered_map<const FieldDescriptor*, PyObject*>
+ CompositeFieldsMap;
+ CompositeFieldsMap* composite_fields;
- // A reference to the dictionary containing the message's extensions.
- // Similar to composite_fields, acting as a cache, but also contains the
- // required extension dict logic.
- ExtensionDict* extensions;
+ // A reference to PyUnknownFields.
+ PyObject* unknown_field_set;
// Implements the "weakref" protocol for this object.
PyObject* weakreflist;
} CMessage;
-extern PyTypeObject CMessageClass_Type;
-extern PyTypeObject CMessage_Type;
-
-
// The (meta) type of all Messages classes.
// It allows us to cache some C++ pointers in the class object itself, they are
// faster to extract than from the type's dictionary.
@@ -142,6 +142,8 @@ struct CMessageClass {
}
};
+extern PyTypeObject* CMessageClass_Type;
+extern PyTypeObject* CMessage_Type;
namespace cmessage {
@@ -164,13 +166,13 @@ PyObject* InternalGetSubMessage(
// Deletes a range of C++ submessages in a repeated field (following a
// removal in a RepeatedCompositeContainer).
//
-// Releases messages to the provided cmessage_list if it is not NULL rather
+// Releases submessages to the provided cmessage_list if it is not NULL rather
// than just removing them from the underlying proto. This cmessage_list must
// have a CMessage for each underlying submessage. The CMessages referred to
// by slice will be removed from cmessage_list by this function.
//
// Corresponds to reflection api method RemoveLast.
-int InternalDeleteRepeatedField(CMessage* self,
+int InternalDeleteRepeatedField(Message* message,
const FieldDescriptor* field_descriptor,
PyObject* slice, PyObject* cmessage_list);
@@ -235,15 +237,13 @@ PyObject* MergeFrom(CMessage* self, PyObject* arg);
// has been registered with the same field number on this class.
PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle);
-// Retrieves an attribute named 'name' from 'self', which is interpreted as a
-// CMessage. Returns the attribute value on success, or null on failure.
-//
-// Returns a new reference.
-PyObject* GetAttr(PyObject* self, PyObject* name);
-
-// Set the value of the attribute named 'name', for 'self', which is interpreted
-// as a CMessage, to the value 'value'. Returns -1 on failure.
-int SetAttr(PyObject* self, PyObject* name, PyObject* value);
+// Get a field from a message.
+PyObject* GetFieldValue(CMessage* self,
+ const FieldDescriptor* field_descriptor);
+// Sets the value of a scalar field in a message.
+// On error, return -1 with an extension set.
+int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
+ PyObject* value);
PyObject* FindInitializationErrors(CMessage* self);
@@ -332,7 +332,7 @@ bool CheckAndSetString(
bool append,
int index);
PyObject* ToStringObject(const FieldDescriptor* descriptor,
- const string& value);
+ const std::string& value);
// Check if the passed field descriptor belongs to the given message.
// If not, return false and set a Python exception (a KeyError)
@@ -341,6 +341,9 @@ bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
extern PyObject* PickleError_class;
+const Message* PyMessage_GetMessagePointer(PyObject* msg);
+Message* PyMessage_GetMutableMessagePointer(PyObject* msg);
+
bool InitProto2MessageModule(PyObject *m);
#if LANG_CXX11
@@ -354,6 +357,6 @@ extern template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
} // namespace python
} // namespace protobuf
-
} // namespace google
+
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__