aboutsummaryrefslogtreecommitdiff
path: root/python/google/protobuf/pyext/repeated_composite_container.cc
diff options
context:
space:
mode:
Diffstat (limited to 'python/google/protobuf/pyext/repeated_composite_container.cc')
-rw-r--r--python/google/protobuf/pyext/repeated_composite_container.cc37
1 files changed, 18 insertions, 19 deletions
diff --git a/python/google/protobuf/pyext/repeated_composite_container.cc b/python/google/protobuf/pyext/repeated_composite_container.cc
index fe2e600b..4f339e77 100644
--- a/python/google/protobuf/pyext/repeated_composite_container.cc
+++ b/python/google/protobuf/pyext/repeated_composite_container.cc
@@ -107,8 +107,7 @@ static int UpdateChildMessages(RepeatedCompositeContainer* self) {
for (Py_ssize_t i = child_length; i < message_length; ++i) {
const Message& sub_message = reflection->GetRepeatedMessage(
*(self->message), self->parent_field_descriptor, i);
- CMessage* cmsg = cmessage::NewEmptyMessage(self->subclass_init,
- sub_message.GetDescriptor());
+ CMessage* cmsg = cmessage::NewEmptyMessage(self->child_message_class);
ScopedPyObjectPtr py_cmsg(reinterpret_cast<PyObject*>(cmsg));
if (cmsg == NULL) {
return -1;
@@ -116,7 +115,7 @@ static int UpdateChildMessages(RepeatedCompositeContainer* self) {
cmsg->owner = self->owner;
cmsg->message = const_cast<Message*>(&sub_message);
cmsg->parent = self->parent;
- if (PyList_Append(self->child_messages, py_cmsg) < 0) {
+ if (PyList_Append(self->child_messages, py_cmsg.get()) < 0) {
return -1;
}
}
@@ -140,8 +139,7 @@ static PyObject* AddToAttached(RepeatedCompositeContainer* self,
Message* sub_message =
message->GetReflection()->AddMessage(message,
self->parent_field_descriptor);
- CMessage* cmsg = cmessage::NewEmptyMessage(self->subclass_init,
- sub_message->GetDescriptor());
+ CMessage* cmsg = cmessage::NewEmptyMessage(self->child_message_class);
if (cmsg == NULL)
return NULL;
@@ -168,7 +166,7 @@ static PyObject* AddToReleased(RepeatedCompositeContainer* self,
// Create a new Message detached from the rest.
PyObject* py_cmsg = PyEval_CallObjectWithKeywords(
- self->subclass_init, NULL, kwargs);
+ self->child_message_class->AsPyObject(), NULL, kwargs);
if (py_cmsg == NULL)
return NULL;
@@ -202,8 +200,8 @@ PyObject* Extend(RepeatedCompositeContainer* self, PyObject* value) {
return NULL;
}
ScopedPyObjectPtr next;
- while ((next.reset(PyIter_Next(iter))) != NULL) {
- if (!PyObject_TypeCheck(next, &CMessage_Type)) {
+ while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
+ if (!PyObject_TypeCheck(next.get(), &CMessage_Type)) {
PyErr_SetString(PyExc_TypeError, "Not a cmessage");
return NULL;
}
@@ -212,7 +210,8 @@ PyObject* Extend(RepeatedCompositeContainer* self, PyObject* value) {
return NULL;
}
CMessage* new_cmessage = reinterpret_cast<CMessage*>(new_message.get());
- if (ScopedPyObjectPtr(cmessage::MergeFrom(new_cmessage, next)) == NULL) {
+ if (ScopedPyObjectPtr(cmessage::MergeFrom(new_cmessage, next.get())) ==
+ NULL) {
return NULL;
}
}
@@ -294,7 +293,7 @@ static PyObject* Remove(RepeatedCompositeContainer* self, PyObject* value) {
return NULL;
}
ScopedPyObjectPtr py_index(PyLong_FromLong(index));
- if (AssignSubscript(self, py_index, NULL) < 0) {
+ if (AssignSubscript(self, py_index.get(), NULL) < 0) {
return NULL;
}
Py_RETURN_NONE;
@@ -318,17 +317,17 @@ static PyObject* RichCompare(RepeatedCompositeContainer* self,
if (full_slice == NULL) {
return NULL;
}
- ScopedPyObjectPtr list(Subscript(self, full_slice));
+ ScopedPyObjectPtr list(Subscript(self, full_slice.get()));
if (list == NULL) {
return NULL;
}
ScopedPyObjectPtr other_list(
- Subscript(
- reinterpret_cast<RepeatedCompositeContainer*>(other), full_slice));
+ Subscript(reinterpret_cast<RepeatedCompositeContainer*>(other),
+ full_slice.get()));
if (other_list == NULL) {
return NULL;
}
- return PyObject_RichCompare(list, other_list, opid);
+ return PyObject_RichCompare(list.get(), other_list.get(), opid);
} else {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
@@ -365,7 +364,7 @@ static int SortPythonMessages(RepeatedCompositeContainer* self,
ScopedPyObjectPtr m(PyObject_GetAttrString(self->child_messages, "sort"));
if (m == NULL)
return -1;
- if (PyObject_Call(m, args, kwds) == NULL)
+ if (PyObject_Call(m.get(), args, kwds) == NULL)
return -1;
if (self->message != NULL) {
ReorderAttached(self);
@@ -429,7 +428,7 @@ static PyObject* Pop(RepeatedCompositeContainer* self,
return NULL;
}
ScopedPyObjectPtr py_index(PyLong_FromSsize_t(index));
- if (AssignSubscript(self, py_index, NULL) < 0) {
+ if (AssignSubscript(self, py_index.get(), NULL) < 0) {
return NULL;
}
return item;
@@ -505,7 +504,7 @@ int SetOwner(RepeatedCompositeContainer* self,
PyObject *NewContainer(
CMessage* parent,
const FieldDescriptor* parent_field_descriptor,
- PyObject *concrete_class) {
+ CMessageClass* concrete_class) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
return NULL;
}
@@ -522,7 +521,7 @@ PyObject *NewContainer(
self->parent_field_descriptor = parent_field_descriptor;
self->owner = parent->owner;
Py_INCREF(concrete_class);
- self->subclass_init = concrete_class;
+ self->child_message_class = concrete_class;
self->child_messages = PyList_New(0);
return reinterpret_cast<PyObject*>(self);
@@ -530,7 +529,7 @@ PyObject *NewContainer(
static void Dealloc(RepeatedCompositeContainer* self) {
Py_CLEAR(self->child_messages);
- Py_CLEAR(self->subclass_init);
+ Py_CLEAR(self->child_message_class);
// TODO(tibell): Do we need to call delete on these objects to make
// sure their destructors are called?
self->owner.reset();