Skip to content

Commit

Permalink
Handle case where callback keeps the entity. This made the API confus…
Browse files Browse the repository at this point in the history
…ing since the retained entity object would change.
  • Loading branch information
robbywalker committed Dec 2, 2011
1 parent d88c67b commit 04c238e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/fastpb/template/module.jinjacc
Expand Up @@ -208,10 +208,14 @@ namespace {
inputStream->SetTotalBytesLimit(512 * 1024 * 1024, 512 * 1024 * 1024);

google::protobuf::uint32 bytes;
PyObject *single = {{ message.name }}_new(&{{ message.name}}Type, NULL, NULL);
PyObject *single = NULL;
while (inputStream->ReadVarint32(&bytes)) {
google::protobuf::io::CodedInputStream::Limit messageLimit = inputStream->PushLimit(bytes);

if (single == NULL) {
single = {{ message.name }}_new(&{{ message.name}}Type, NULL, NULL);
}

Py_BEGIN_ALLOW_THREADS
(({{message.name}} *)single)->protobuf->ParseFromCodedStream(inputStream);
Py_END_ALLOW_THREADS
Expand All @@ -222,8 +226,16 @@ namespace {
fail = 1;
break;
};

if (single->ob_refcnt != 1) {
// If the callback saved a reference to the item, don't re-use it.
Py_XDECREF(single);
single = NULL;
}
}
if (single != NULL) {
Py_XDECREF(single);
}
Py_XDECREF(single);

delete inputStream;
delete input;
Expand Down

0 comments on commit 04c238e

Please sign in to comment.