MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / record_richcompare

Function record_richcompare

asyncpg/protocol/record/recordobj.c:300–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300static PyObject *
301record_richcompare(PyObject *v, PyObject *w, int op)
302{
303 Py_ssize_t i;
304 Py_ssize_t vlen, wlen;
305 int v_is_tuple = 0;
306 int w_is_tuple = 0;
307 int v_is_record = 0;
308 int w_is_record = 0;
309 int comp;
310 PyTypeObject *v_type = Py_TYPE(v);
311 PyTypeObject *w_type = Py_TYPE(w);
312
313 record_module_state *state;
314
315 state = find_module_state_by_def(v_type);
316 if (state == NULL) {
317 PyErr_Clear();
318 state = find_module_state_by_def(w_type);
319 }
320 if (PyTuple_Check(v)) {
321 v_is_tuple = 1;
322 }
323 else if (v_type == state->ApgRecord_Type) {
324 v_is_record = 1;
325 }
326 else if (!PyObject_TypeCheck(v, state->ApgRecord_Type)) {
327 Py_RETURN_NOTIMPLEMENTED;
328 }
329
330 if (PyTuple_Check(w)) {
331 w_is_tuple = 1;
332 }
333 else if (w_type == state->ApgRecord_Type) {
334 w_is_record = 1;
335 }
336 else if (!PyObject_TypeCheck(w, state->ApgRecord_Type)) {
337 Py_RETURN_NOTIMPLEMENTED;
338 }
339
340#define V_ITEM(i) \
341 (v_is_tuple ? PyTuple_GET_ITEM(v, i) \
342 : (v_is_record ? ApgRecord_GET_ITEM(v, i) : PySequence_GetItem(v, i)))
343#define W_ITEM(i) \
344 (w_is_tuple ? PyTuple_GET_ITEM(w, i) \
345 : (w_is_record ? ApgRecord_GET_ITEM(w, i) : PySequence_GetItem(w, i)))
346
347 vlen = Py_SIZE(v);
348 wlen = Py_SIZE(w);
349
350 if (op == Py_EQ && vlen != wlen) {
351 /* Checking if v == w, but len(v) != len(w): return False */
352 Py_RETURN_FALSE;
353 }
354
355 if (op == Py_NE && vlen != wlen) {
356 /* Checking if v != w, and len(v) != len(w): return True */
357 Py_RETURN_TRUE;

Callers

nothing calls this directly

Calls 1

find_module_state_by_defFunction · 0.85

Tested by

no test coverage detected