A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/protocolbuffers/protobuf/commit/e5f9ab4d073996b0b7a700a300bb2f9c61976e98 below:

Add reference leak check to Python well_known_types_test. Fix two ref… · protocolbuffers/protobuf@e5f9ab4 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+33

-24

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+33

-24

lines changed Original file line number Diff line number Diff line change

@@ -16,6 +16,7 @@

16 16

from google.protobuf import json_format

17 17

from google.protobuf import text_format

18 18

from google.protobuf.internal import more_messages_pb2

19 +

from google.protobuf.internal import testing_refleaks

19 20

from google.protobuf.internal import well_known_types

20 21

from google.protobuf.internal import well_known_types_test_pb2

21 22

@@ -54,6 +55,7 @@ def CheckDurationConversion(self, message, text):

54 55

self.assertEqual(message, parsed_message)

55 56 56 57 58 +

@testing_refleaks.TestCase

57 59

class TimeUtilTest(TimeUtilTestBase):

58 60 59 61

def testTimestampSerializeAndParse(self):

@@ -704,6 +706,7 @@ def testDurationSub(self, old_time, time_delta, expected_sec, expected_nano):

704 706

self.assertEqual(expected_nano, msg.optional_timestamp.nanos)

705 707 706 708 709 +

@testing_refleaks.TestCase

707 710

class StructTest(unittest.TestCase):

708 711 709 712

def testEmptyDict(self):

@@ -987,6 +990,7 @@ def testMergeFrom(self):

987 990

self.assertEqual(5, struct['key5'][0][1])

988 991 989 992 993 +

@testing_refleaks.TestCase

990 994

class AnyTest(unittest.TestCase):

991 995 992 996

def testAnyMessage(self):

Original file line number Diff line number Diff line change

@@ -1124,14 +1124,16 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {

1124 1124

Descriptor::WELLKNOWNTYPE_STRUCT) {

1125 1125

ScopedPyObjectPtr ok(PyObject_CallMethod(

1126 1126

reinterpret_cast<PyObject*>(cmessage), "update", "O", value));

1127 -

if (ok.get() == nullptr && PyDict_Size(value) == 1 &&

1128 -

PyDict_Contains(value, PyUnicode_FromString("fields"))) {

1129 -

// Fallback to init as normal message field.

1130 -

PyErr_Clear();

1131 -

PyObject* tmp = Clear(cmessage);

1132 -

Py_DECREF(tmp);

1133 -

if (InitAttributes(cmessage, nullptr, value) < 0) {

1134 -

return -1;

1127 +

if (ok.get() == nullptr && PyDict_Size(value) == 1) {

1128 +

ScopedPyObjectPtr fields_str(PyUnicode_FromString("fields"));

1129 +

if (PyDict_Contains(value, fields_str.get())) {

1130 +

// Fallback to init as normal message field.

1131 +

PyErr_Clear();

1132 +

PyObject* tmp = Clear(cmessage);

1133 +

Py_DECREF(tmp);

1134 +

if (InitAttributes(cmessage, nullptr, value) < 0) {

1135 +

return -1;

1136 +

}

1135 1137

}

1136 1138

}

1137 1139

} else {

@@ -2391,21 +2393,19 @@ PyObject* Contains(CMessage* self, PyObject* arg) {

2391 2393

const Reflection* reflection = message->GetReflection();

2392 2394

const FieldDescriptor* map_field = descriptor->FindFieldByName("fields");

2393 2395

const FieldDescriptor* key_field = map_field->message_type()->map_key();

2394 -

PyObject* py_string = CheckString(arg, key_field);

2395 -

if (!py_string) {

2396 +

ScopedPyObjectPtr py_string(CheckString(arg, key_field));

2397 +

if (py_string.get() == nullptr) {

2396 2398

PyErr_SetString(PyExc_TypeError,

2397 2399

"The key passed to Struct message must be a str.");

2398 2400

return nullptr;

2399 2401

}

2400 2402

char* value;

2401 2403

Py_ssize_t value_len;

2402 -

if (PyBytes_AsStringAndSize(py_string, &value, &value_len) < 0) {

2403 -

Py_DECREF(py_string);

2404 +

if (PyBytes_AsStringAndSize(py_string.get(), &value, &value_len) < 0) {

2404 2405

Py_RETURN_FALSE;

2405 2406

}

2406 2407

std::string key_str;

2407 2408

key_str.assign(value, value_len);

2408 -

Py_DECREF(py_string);

2409 2409 2410 2410

MapKey map_key;

2411 2411

map_key.SetStringValue(key_str);

@@ -2414,9 +2414,9 @@ PyObject* Contains(CMessage* self, PyObject* arg) {

2414 2414

}

2415 2415

case Descriptor::WELLKNOWNTYPE_LISTVALUE: {

2416 2416

// For WKT ListValue, check if the key is in the items.

2417 -

PyObject* items = PyObject_CallMethod(reinterpret_cast<PyObject*>(self),

2418 -

"items", nullptr);

2419 -

return PyBool_FromLong(PySequence_Contains(items, arg));

2417 +

ScopedPyObjectPtr items(PyObject_CallMethod(

2418 +

reinterpret_cast<PyObject*>(self), "items", nullptr));

2419 +

return PyBool_FromLong(PySequence_Contains(items.get(), arg));

2420 2420

}

2421 2421

default:

2422 2422

// For other messages, check with HasField.

Original file line number Diff line number Diff line change

@@ -453,13 +453,16 @@ static bool PyUpb_Message_InitMessageAttribute(PyObject* _self, PyObject* name,

453 453

const upb_MessageDef* msgdef = upb_FieldDef_MessageSubDef(field);

454 454

if (upb_MessageDef_WellKnownType(msgdef) == kUpb_WellKnown_Struct) {

455 455

ok = PyObject_CallMethod(submsg, "_internal_assign", "O", value);

456 -

if (!ok && PyDict_Size(value) == 1 &&

457 -

PyDict_Contains(value, PyUnicode_FromString("fields"))) {

458 -

// Fall back to init as normal message field.

459 -

PyErr_Clear();

460 -

PyObject* tmp = PyUpb_Message_Clear((PyUpb_Message*)submsg);

461 -

Py_DECREF(tmp);

462 -

ok = PyUpb_Message_InitAttributes(submsg, NULL, value) >= 0;

456 +

if (!ok && PyDict_Size(value) == 1) {

457 +

PyObject* fields_str = PyUnicode_FromString("fields");

458 +

if (PyDict_Contains(value, fields_str)) {

459 +

// Fall back to init as normal message field.

460 +

PyErr_Clear();

461 +

PyObject* tmp = PyUpb_Message_Clear((PyUpb_Message*)submsg);

462 +

Py_DECREF(tmp);

463 +

ok = PyUpb_Message_InitAttributes(submsg, NULL, value) >= 0;

464 +

}

465 +

Py_DECREF(fields_str);

463 466

}

464 467

} else {

465 468

ok = PyUpb_Message_InitAttributes(submsg, NULL, value) >= 0;

@@ -1110,7 +1113,9 @@ static PyObject* PyUpb_Message_Contains(PyObject* _self, PyObject* arg) {

1110 1113

PyUpb_Message* self = (void*)_self;

1111 1114

if (PyUpb_Message_IsStub(self)) Py_RETURN_FALSE;

1112 1115

PyObject* items = PyObject_CallMethod(_self, "items", NULL);

1113 -

return PyBool_FromLong(PySequence_Contains(items, arg));

1116 +

int ret = PySequence_Contains(items, arg);

1117 +

Py_DECREF(items);

1118 +

return PyBool_FromLong(ret);

1114 1119

}

1115 1120

default:

1116 1121

// For other messages, check with HasField.

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4