MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / list_ass_slice

Function list_ass_slice

src/JSArrayProxy.cc:166–264  ·  view source on GitHub ↗

a[ilow:ihigh] = v if v != NULL. * del a[ilow:ihigh] if v == NULL. */ private

Source from the content-addressed store, hash-verified

164 */
165// private
166static int list_ass_slice(JSArrayProxy *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
167{
168 /* Because [X]DECREF can recursively invoke list operations on
169 this list, we must postpone all [X]DECREF activity until
170 after the list is back in its canonical shape. Therefore
171 we must allocate an additional array, 'recycle', into which
172 we temporarily copy the items that are deleted from the
173 list. :-( */
174 PyObject **item;
175 PyObject **vitem = NULL;
176 PyObject *v_as_SF = NULL; /* PySequence_Fast(v) */
177 Py_ssize_t n; /* # of elements in replacement list */
178 Py_ssize_t norig; /* # of elements in list getting replaced */
179 Py_ssize_t d; /* Change in size */
180 Py_ssize_t k;
181 size_t s;
182 int result = -1; /* guilty until proved innocent */
183#define b ((PyListObject *)v)
184 Py_ssize_t selfLength = JSArrayProxyMethodDefinitions::JSArrayProxy_length(self);
185 if (v == NULL) {
186 n = 0;
187 }
188 else {
189 if ((PyListObject *)self == b) {
190 /* Special case "a[i:j] = a" -- copy b first */
191 v = list_slice(self, 0, selfLength);
192 if (v == NULL) {
193 return result;
194 }
195 result = list_ass_slice(self, ilow, ihigh, v);
196 Py_DECREF(v);
197 return result;
198 }
199 v_as_SF = PySequence_Fast(v, "can only assign an iterable");
200 if (v_as_SF == NULL) {
201 return result;
202 }
203 n = PySequence_Fast_GET_SIZE(v_as_SF);
204 vitem = PySequence_Fast_ITEMS(v_as_SF);
205 }
206
207 if (ilow < 0) {
208 ilow = 0;
209 }
210 else if (ilow > selfLength) {
211 ilow = selfLength;
212 }
213
214 if (ihigh < ilow) {
215 ihigh = ilow;
216 }
217 else if (ihigh > selfLength) {
218 ihigh = selfLength;
219 }
220
221 norig = ihigh - ilow;
222 assert(norig >= 0);
223 d = n - norig;

Callers 1

Calls 3

list_sliceFunction · 0.85
jsTypeFactoryFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected