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

Function mergeFromSeq2

src/JSObjectProxy.cc:478–546  ·  view source on GitHub ↗

private

Source from the content-addressed store, hash-verified

476
477// private
478static int mergeFromSeq2(JSObjectProxy *self, PyObject *seq2) {
479 PyObject *it; /* iter(seq2) */
480 Py_ssize_t i; /* index into seq2 of current element */
481 PyObject *item; /* seq2[i] */
482 PyObject *fast; /* item as a 2-tuple or 2-list */
483
484 it = PyObject_GetIter(seq2);
485 if (it == NULL)
486 return -1;
487
488 for (i = 0;; ++i) {
489 PyObject *key, *value;
490 Py_ssize_t n;
491
492 fast = NULL;
493 item = PyIter_Next(it);
494 if (item == NULL) {
495 if (PyErr_Occurred())
496 goto Fail;
497 break;
498 }
499
500 /* Convert item to sequence, and verify length 2. */
501 fast = PySequence_Fast(item, "");
502 if (fast == NULL) {
503 if (PyErr_ExceptionMatches(PyExc_TypeError))
504 PyErr_Format(PyExc_TypeError,
505 "cannot convert dictionary update "
506 "sequence element #%zd to a sequence",
507 i);
508 goto Fail;
509 }
510 n = PySequence_Fast_GET_SIZE(fast);
511 if (n != 2) {
512 PyErr_Format(PyExc_ValueError,
513 "dictionary update sequence element #%zd "
514 "has length %zd; 2 is required",
515 i, n);
516 goto Fail;
517 }
518
519 /* Update/merge with this (key, value) pair. */
520 key = PySequence_Fast_GET_ITEM(fast, 0);
521 value = PySequence_Fast_GET_ITEM(fast, 1);
522 Py_INCREF(key);
523 Py_INCREF(value);
524
525 if (JSObjectProxyMethodDefinitions::JSObjectProxy_assign(self, key, value) < 0) {
526 Py_DECREF(key);
527 Py_DECREF(value);
528 goto Fail;
529 }
530
531 Py_DECREF(key);
532 Py_DECREF(value);
533 Py_DECREF(fast);
534 Py_DECREF(item);
535 }

Callers 2

JSObjectProxy_iorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected