1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| static PyObject * binary_iop(PyObject *v, PyObject *w, const int iop_slot, const int op_slot, const char *op_name) {
PyObject *result = BINARY_IOP1(v, w, iop_slot, op_slot, op_name); if (result == Py_NotImplemented) { Py_DECREF(result); return binop_type_error(v, w, op_name); } // === 日志部分 === const char* type_v = Py_TYPE(v)->tp_name; const char* type_w = Py_TYPE(w)->tp_name;
fprintf(stderr, "[binary_iop] op: %s, v type: %s, w type: %s\n", op_name, type_v, type_w);
// 如果都是整数类型,打印其值和计算结果 if (PyLong_Check(v) && PyLong_Check(w)) { int ovf1 = 0, ovf2 = 0; long long a = PyLong_AsLongLongAndOverflow(v, &ovf1); long long b = PyLong_AsLongLongAndOverflow(w, &ovf2);
if (!ovf1 && !ovf2) { if (strcmp(op_name, "^=") == 0) { fprintf(stderr, "[XOR] 0x%llx ^ 0x%llx = 0x%llx\n", a, b, a ^ b); } else if (strcmp(op_name, "&=") == 0) { fprintf(stderr, "[AND] 0x%llx & 0x%llx = 0x%llx\n", a, b, a & b); } else if (strcmp(op_name, "|=") == 0) { fprintf(stderr, "[OR ] 0x%llx | 0x%llx = 0x%llx\n", a, b, a | b); } else if (strcmp(op_name, "<<=") == 0) { fprintf(stderr, "[LSHIFT] 0x%llx << 0x%llx = 0x%llx\n", a, b, a << b); } else if (strcmp(op_name, ">>=") == 0) { fprintf(stderr, "[RSHIFT] 0x%llx >> 0x%llx = 0x%llx\n", a, b, a >> b); } else if (strcmp(op_name, "-=") == 0) { fprintf(stderr, "[SUB] 0x%llx - 0x%llx = 0x%llx\n", a, b, a - b); } else { // 兜底打印 fprintf(stderr, "[DEBUG] %s: 0x%llx %s 0x%llx\n", op_name, a, op_name, b); } } } return result; }
|