|
56 | 56 | #include "zmqclient.h"
|
57 | 57 | #include "zmqconsumerstatetable.h"
|
58 | 58 | #include "zmqproducerstatetable.h"
|
| 59 | +#include <memory> |
| 60 | +#include <functional> |
59 | 61 | %}
|
60 | 62 |
|
61 | 63 | %include <std_string.i>
|
|
156 | 158 | SWIG_Python_AppendOutput($result, temp);
|
157 | 159 | }
|
158 | 160 |
|
159 |
| -%typemap(in, fragment="SWIG_AsPtr_std_string") |
| 161 | +%typemap(in, fragment="SWIG_AsVal_std_string") |
160 | 162 | const std::vector<std::pair< std::string,std::string >,std::allocator< std::pair< std::string,std::string > > > &
|
161 | 163 | (std::vector< std::pair< std::string,std::string >,std::allocator< std::pair< std::string,std::string > > > temp,
|
162 | 164 | int res) {
|
163 | 165 | res = SWIG_OK;
|
164 | 166 | for (int i = 0; i < PySequence_Length($input); ++i) {
|
165 | 167 | temp.push_back(std::pair< std::string,std::string >());
|
166 |
| - PyObject *item = PySequence_GetItem($input, i); |
167 |
| - if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) { |
| 168 | + std::unique_ptr<PyObject, std::function<void(PyObject *)> > item( |
| 169 | + PySequence_GetItem($input, i), |
| 170 | + [](PyObject *ptr){ |
| 171 | + Py_DECREF(ptr); |
| 172 | + }); |
| 173 | + if (!PyTuple_Check(item.get()) || PyTuple_Size(item.get()) != 2) { |
168 | 174 | SWIG_fail;
|
169 | 175 | }
|
170 |
| - PyObject *key = PyTuple_GetItem(item, 0); |
171 |
| - PyObject *value = PyTuple_GetItem(item, 1); |
172 |
| - std::string *ptr = (std::string *)0; |
| 176 | + PyObject *key = PyTuple_GetItem(item.get(), 0); |
| 177 | + PyObject *value = PyTuple_GetItem(item.get(), 1); |
| 178 | + std::string str; |
| 179 | + |
173 | 180 | if (PyBytes_Check(key)) {
|
174 | 181 | temp.back().first.assign(PyBytes_AsString(key), PyBytes_Size(key));
|
175 |
| - } else if (SWIG_AsPtr_std_string(key, &ptr)) { |
176 |
| - temp.back().first = *ptr; |
| 182 | + } else if (SWIG_AsVal_std_string(key, &str) != SWIG_ERROR) { |
| 183 | + temp.back().first = str; |
177 | 184 | } else {
|
178 | 185 | SWIG_fail;
|
179 | 186 | }
|
180 | 187 | if (PyBytes_Check(value)) {
|
181 | 188 | temp.back().second.assign(PyBytes_AsString(value), PyBytes_Size(value));
|
182 |
| - } else if (SWIG_AsPtr_std_string(value, &ptr)) { |
183 |
| - temp.back().second = *ptr; |
| 189 | + } else if (SWIG_AsVal_std_string(value, &str) != SWIG_ERROR) { |
| 190 | + temp.back().second = str; |
184 | 191 | } else {
|
185 | 192 | SWIG_fail;
|
186 | 193 | }
|
|
191 | 198 | %typemap(typecheck) const std::vector< std::pair< std::string,std::string >,std::allocator< std::pair< std::string,std::string > > > &{
|
192 | 199 | $1 = 1;
|
193 | 200 | for (int i = 0; i < PySequence_Length($input); ++i) {
|
194 |
| - PyObject *item = PySequence_GetItem($input, i); |
195 |
| - if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) { |
| 201 | + std::unique_ptr<PyObject, std::function<void(PyObject *)> > item( |
| 202 | + PySequence_GetItem($input, i), |
| 203 | + [](PyObject *ptr){ |
| 204 | + Py_DECREF(ptr); |
| 205 | + }); |
| 206 | + if (!PyTuple_Check(item.get()) || PyTuple_Size(item.get()) != 2) { |
196 | 207 | $1 = 0;
|
197 | 208 | break;
|
198 | 209 | }
|
199 |
| - PyObject *key = PyTuple_GetItem(item, 0); |
200 |
| - PyObject *value = PyTuple_GetItem(item, 1); |
| 210 | + PyObject *key = PyTuple_GetItem(item.get(), 0); |
| 211 | + PyObject *value = PyTuple_GetItem(item.get(), 1); |
201 | 212 | if (!PyBytes_Check(key)
|
202 | 213 | && !PyUnicode_Check(key)
|
203 | 214 | && !PyString_Check(key)
|
|
0 commit comments