diff options
Diffstat (limited to 'python/google/protobuf/pyext/message.h')
-rw-r--r-- | python/google/protobuf/pyext/message.h | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index d754e62a..e729e448 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -38,6 +38,7 @@ #include <memory> #include <string> +#include <hash_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 __gnu_cxx::hash_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 { @@ -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); @@ -357,6 +357,6 @@ extern template bool CheckAndGetInteger<uint64>(PyObject*, uint64*); } // namespace python } // namespace protobuf - } // namespace google + #endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__ |