Skip to content

Commit 038e0c3

Browse files
Minor improvement of "private" data store
1 parent cf7fb82 commit 038e0c3

19 files changed

+190
-247
lines changed

src/interface/shared/private_data.i

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,44 @@
1919
// Functions to store and retrieve "private" data attached to Pyhon object
2020
%fragment("private_data", "header") {
2121
static PyObject* _get_store(PyObject* py_self, bool create) {
22-
// Return a new reference
22+
// Return a borrowed reference
23+
PyObject* dict = NULL;
2324
if (!PyObject_HasAttrString(py_self, "_private_data_")) {
2425
if (!create)
2526
return NULL;
26-
PyObject* dict = PyDict_New();
27+
dict = PyDict_New();
2728
if (!dict)
2829
return NULL;
2930
int error = PyObject_SetAttrString(py_self, "_private_data_", dict);
3031
Py_DECREF(dict);
3132
if (error)
3233
return NULL;
3334
}
34-
return PyObject_GetAttrString(py_self, "_private_data_");
35+
dict = PyObject_GetAttrString(py_self, "_private_data_");
36+
Py_DECREF(dict);
37+
return dict;
3538
};
3639
static int private_store_set(PyObject* py_self, const char* name,
3740
PyObject* val) {
3841
PyObject* dict = _get_store(py_self, true);
3942
if (!dict)
4043
return -1;
41-
int result = PyDict_SetItemString(dict, name, val);
42-
Py_DECREF(dict);
43-
return result;
44+
return PyDict_SetItemString(dict, name, val);
4445
};
4546
static PyObject* private_store_get(PyObject* py_self, const char* name) {
4647
// Return a borrowed reference
4748
PyObject* dict = _get_store(py_self, false);
4849
if (!dict)
4950
return NULL;
50-
PyObject* result = PyDict_GetItemString(dict, name);
51-
Py_DECREF(dict);
52-
return result;
51+
return PyDict_GetItemString(dict, name);
5352
};
5453
static int private_store_del(PyObject* py_self, const char* name) {
5554
PyObject* dict = _get_store(py_self, false);
5655
if (!dict)
5756
return 0;
58-
int result = 0;
5957
if (PyDict_GetItemString(dict, name))
60-
result = PyDict_DelItemString(dict, name);
61-
Py_DECREF(dict);
62-
return result;
58+
return PyDict_DelItemString(dict, name);
59+
return 0;
6360
};
6461
}
6562

src/swig-0_27_7/basicio_wrap.cxx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4441,47 +4441,44 @@ static PyObject* _get_enum_data_Exiv2_BasicIo_Position() {
44414441

44424442

44434443
static PyObject* _get_store(PyObject* py_self, bool create) {
4444-
// Return a new reference
4444+
// Return a borrowed reference
4445+
PyObject* dict = NULL;
44454446
if (!PyObject_HasAttrString(py_self, "_private_data_")) {
44464447
if (!create)
44474448
return NULL;
4448-
PyObject* dict = PyDict_New();
4449+
dict = PyDict_New();
44494450
if (!dict)
44504451
return NULL;
44514452
int error = PyObject_SetAttrString(py_self, "_private_data_", dict);
44524453
Py_DECREF(dict);
44534454
if (error)
44544455
return NULL;
44554456
}
4456-
return PyObject_GetAttrString(py_self, "_private_data_");
4457+
dict = PyObject_GetAttrString(py_self, "_private_data_");
4458+
Py_DECREF(dict);
4459+
return dict;
44574460
};
44584461
static int private_store_set(PyObject* py_self, const char* name,
44594462
PyObject* val) {
44604463
PyObject* dict = _get_store(py_self, true);
44614464
if (!dict)
44624465
return -1;
4463-
int result = PyDict_SetItemString(dict, name, val);
4464-
Py_DECREF(dict);
4465-
return result;
4466+
return PyDict_SetItemString(dict, name, val);
44664467
};
44674468
static PyObject* private_store_get(PyObject* py_self, const char* name) {
44684469
// Return a borrowed reference
44694470
PyObject* dict = _get_store(py_self, false);
44704471
if (!dict)
44714472
return NULL;
4472-
PyObject* result = PyDict_GetItemString(dict, name);
4473-
Py_DECREF(dict);
4474-
return result;
4473+
return PyDict_GetItemString(dict, name);
44754474
};
44764475
static int private_store_del(PyObject* py_self, const char* name) {
44774476
PyObject* dict = _get_store(py_self, false);
44784477
if (!dict)
44794478
return 0;
4480-
int result = 0;
44814479
if (PyDict_GetItemString(dict, name))
4482-
result = PyDict_DelItemString(dict, name);
4483-
Py_DECREF(dict);
4484-
return result;
4480+
return PyDict_DelItemString(dict, name);
4481+
return 0;
44854482
};
44864483

44874484

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,47 +5141,44 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
51415141

51425142

51435143
static PyObject* _get_store(PyObject* py_self, bool create) {
5144-
// Return a new reference
5144+
// Return a borrowed reference
5145+
PyObject* dict = NULL;
51455146
if (!PyObject_HasAttrString(py_self, "_private_data_")) {
51465147
if (!create)
51475148
return NULL;
5148-
PyObject* dict = PyDict_New();
5149+
dict = PyDict_New();
51495150
if (!dict)
51505151
return NULL;
51515152
int error = PyObject_SetAttrString(py_self, "_private_data_", dict);
51525153
Py_DECREF(dict);
51535154
if (error)
51545155
return NULL;
51555156
}
5156-
return PyObject_GetAttrString(py_self, "_private_data_");
5157+
dict = PyObject_GetAttrString(py_self, "_private_data_");
5158+
Py_DECREF(dict);
5159+
return dict;
51575160
};
51585161
static int private_store_set(PyObject* py_self, const char* name,
51595162
PyObject* val) {
51605163
PyObject* dict = _get_store(py_self, true);
51615164
if (!dict)
51625165
return -1;
5163-
int result = PyDict_SetItemString(dict, name, val);
5164-
Py_DECREF(dict);
5165-
return result;
5166+
return PyDict_SetItemString(dict, name, val);
51665167
};
51675168
static PyObject* private_store_get(PyObject* py_self, const char* name) {
51685169
// Return a borrowed reference
51695170
PyObject* dict = _get_store(py_self, false);
51705171
if (!dict)
51715172
return NULL;
5172-
PyObject* result = PyDict_GetItemString(dict, name);
5173-
Py_DECREF(dict);
5174-
return result;
5173+
return PyDict_GetItemString(dict, name);
51755174
};
51765175
static int private_store_del(PyObject* py_self, const char* name) {
51775176
PyObject* dict = _get_store(py_self, false);
51785177
if (!dict)
51795178
return 0;
5180-
int result = 0;
51815179
if (PyDict_GetItemString(dict, name))
5182-
result = PyDict_DelItemString(dict, name);
5183-
Py_DECREF(dict);
5184-
return result;
5180+
return PyDict_DelItemString(dict, name);
5181+
return 0;
51855182
};
51865183

51875184

src/swig-0_27_7/image_wrap.cxx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,47 +4670,44 @@ static PyObject* _get_enum_data_Exiv2_ImageType() {
46704670

46714671

46724672
static PyObject* _get_store(PyObject* py_self, bool create) {
4673-
// Return a new reference
4673+
// Return a borrowed reference
4674+
PyObject* dict = NULL;
46744675
if (!PyObject_HasAttrString(py_self, "_private_data_")) {
46754676
if (!create)
46764677
return NULL;
4677-
PyObject* dict = PyDict_New();
4678+
dict = PyDict_New();
46784679
if (!dict)
46794680
return NULL;
46804681
int error = PyObject_SetAttrString(py_self, "_private_data_", dict);
46814682
Py_DECREF(dict);
46824683
if (error)
46834684
return NULL;
46844685
}
4685-
return PyObject_GetAttrString(py_self, "_private_data_");
4686+
dict = PyObject_GetAttrString(py_self, "_private_data_");
4687+
Py_DECREF(dict);
4688+
return dict;
46864689
};
46874690
static int private_store_set(PyObject* py_self, const char* name,
46884691
PyObject* val) {
46894692
PyObject* dict = _get_store(py_self, true);
46904693
if (!dict)
46914694
return -1;
4692-
int result = PyDict_SetItemString(dict, name, val);
4693-
Py_DECREF(dict);
4694-
return result;
4695+
return PyDict_SetItemString(dict, name, val);
46954696
};
46964697
static PyObject* private_store_get(PyObject* py_self, const char* name) {
46974698
// Return a borrowed reference
46984699
PyObject* dict = _get_store(py_self, false);
46994700
if (!dict)
47004701
return NULL;
4701-
PyObject* result = PyDict_GetItemString(dict, name);
4702-
Py_DECREF(dict);
4703-
return result;
4702+
return PyDict_GetItemString(dict, name);
47044703
};
47054704
static int private_store_del(PyObject* py_self, const char* name) {
47064705
PyObject* dict = _get_store(py_self, false);
47074706
if (!dict)
47084707
return 0;
4709-
int result = 0;
47104708
if (PyDict_GetItemString(dict, name))
4711-
result = PyDict_DelItemString(dict, name);
4712-
Py_DECREF(dict);
4713-
return result;
4709+
return PyDict_DelItemString(dict, name);
4710+
return 0;
47144711
};
47154712

47164713

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5133,47 +5133,44 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
51335133

51345134

51355135
static PyObject* _get_store(PyObject* py_self, bool create) {
5136-
// Return a new reference
5136+
// Return a borrowed reference
5137+
PyObject* dict = NULL;
51375138
if (!PyObject_HasAttrString(py_self, "_private_data_")) {
51385139
if (!create)
51395140
return NULL;
5140-
PyObject* dict = PyDict_New();
5141+
dict = PyDict_New();
51415142
if (!dict)
51425143
return NULL;
51435144
int error = PyObject_SetAttrString(py_self, "_private_data_", dict);
51445145
Py_DECREF(dict);
51455146
if (error)
51465147
return NULL;
51475148
}
5148-
return PyObject_GetAttrString(py_self, "_private_data_");
5149+
dict = PyObject_GetAttrString(py_self, "_private_data_");
5150+
Py_DECREF(dict);
5151+
return dict;
51495152
};
51505153
static int private_store_set(PyObject* py_self, const char* name,
51515154
PyObject* val) {
51525155
PyObject* dict = _get_store(py_self, true);
51535156
if (!dict)
51545157
return -1;
5155-
int result = PyDict_SetItemString(dict, name, val);
5156-
Py_DECREF(dict);
5157-
return result;
5158+
return PyDict_SetItemString(dict, name, val);
51585159
};
51595160
static PyObject* private_store_get(PyObject* py_self, const char* name) {
51605161
// Return a borrowed reference
51615162
PyObject* dict = _get_store(py_self, false);
51625163
if (!dict)
51635164
return NULL;
5164-
PyObject* result = PyDict_GetItemString(dict, name);
5165-
Py_DECREF(dict);
5166-
return result;
5165+
return PyDict_GetItemString(dict, name);
51675166
};
51685167
static int private_store_del(PyObject* py_self, const char* name) {
51695168
PyObject* dict = _get_store(py_self, false);
51705169
if (!dict)
51715170
return 0;
5172-
int result = 0;
51735171
if (PyDict_GetItemString(dict, name))
5174-
result = PyDict_DelItemString(dict, name);
5175-
Py_DECREF(dict);
5176-
return result;
5172+
return PyDict_DelItemString(dict, name);
5173+
return 0;
51775174
};
51785175

51795176

src/swig-0_27_7/metadatum_wrap.cxx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5175,47 +5175,44 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
51755175

51765176

51775177
static PyObject* _get_store(PyObject* py_self, bool create) {
5178-
// Return a new reference
5178+
// Return a borrowed reference
5179+
PyObject* dict = NULL;
51795180
if (!PyObject_HasAttrString(py_self, "_private_data_")) {
51805181
if (!create)
51815182
return NULL;
5182-
PyObject* dict = PyDict_New();
5183+
dict = PyDict_New();
51835184
if (!dict)
51845185
return NULL;
51855186
int error = PyObject_SetAttrString(py_self, "_private_data_", dict);
51865187
Py_DECREF(dict);
51875188
if (error)
51885189
return NULL;
51895190
}
5190-
return PyObject_GetAttrString(py_self, "_private_data_");
5191+
dict = PyObject_GetAttrString(py_self, "_private_data_");
5192+
Py_DECREF(dict);
5193+
return dict;
51915194
};
51925195
static int private_store_set(PyObject* py_self, const char* name,
51935196
PyObject* val) {
51945197
PyObject* dict = _get_store(py_self, true);
51955198
if (!dict)
51965199
return -1;
5197-
int result = PyDict_SetItemString(dict, name, val);
5198-
Py_DECREF(dict);
5199-
return result;
5200+
return PyDict_SetItemString(dict, name, val);
52005201
};
52015202
static PyObject* private_store_get(PyObject* py_self, const char* name) {
52025203
// Return a borrowed reference
52035204
PyObject* dict = _get_store(py_self, false);
52045205
if (!dict)
52055206
return NULL;
5206-
PyObject* result = PyDict_GetItemString(dict, name);
5207-
Py_DECREF(dict);
5208-
return result;
5207+
return PyDict_GetItemString(dict, name);
52095208
};
52105209
static int private_store_del(PyObject* py_self, const char* name) {
52115210
PyObject* dict = _get_store(py_self, false);
52125211
if (!dict)
52135212
return 0;
5214-
int result = 0;
52155213
if (PyDict_GetItemString(dict, name))
5216-
result = PyDict_DelItemString(dict, name);
5217-
Py_DECREF(dict);
5218-
return result;
5214+
return PyDict_DelItemString(dict, name);
5215+
return 0;
52195216
};
52205217

52215218
#ifdef __cplusplus

0 commit comments

Comments
 (0)