From 3f7adb769d069580f0f7cb37dd2d7d347c576077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=9A=93=E6=99=9F?= <2067144018@qq.com> Date: Mon, 1 Dec 2025 12:06:46 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E9=80=9A=E8=BF=87=E5=BC=95=E5=8F=91p?= =?UTF-8?q?y=5Fcall=E9=94=99=E8=AF=AF=E8=A6=86=E7=9B=96=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E8=80=85=E7=9A=84ok=3D=3Dfalse=E5=88=86?= =?UTF-8?q?=E6=94=AF"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 36dc0b5d81a02a83dfdeca2d4d6d265f5f793b4b. --- tests/100_extras2.py | 94 -------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 tests/100_extras2.py diff --git a/tests/100_extras2.py b/tests/100_extras2.py deleted file mode 100644 index 659e03f2..00000000 --- a/tests/100_extras2.py +++ /dev/null @@ -1,94 +0,0 @@ -''' -========= src/common/algorithm.c ========= -''' - -# 该函数的return false没有被覆盖 -# bool c11__stable_sort(void* ptr_, -# int length, -# int elem_size, -# int (*f_lt)(const void* a, const void* b, void* extra), -# void* extra) { -# // merge sort -# char *ptr = ptr_, *tmp = PK_MALLOC(length * elem_size); -# for(int seg = 1; seg < length; seg *= 2) { -# for(char* a = ptr; a < ptr + (length - seg) * elem_size; a += 2 * seg * elem_size) { -# char *b = a + seg * elem_size, *a_end = b, *b_end = b + seg * elem_size; -# if(b_end > ptr + length * elem_size) b_end = ptr + length * elem_size; -# bool ok = _stable_sort_merge(a, a_end, b, b_end, tmp, elem_size, f_lt, extra); -# if(!ok) { -# PK_FREE(tmp); -# ----> return false; -# } -# memcpy(a, tmp, b_end - a); -# } -# } -# PK_FREE(tmp); -# return true; -# } - - -# 调查得知只要触发bool ok = pk_stack_binaryop(vm, __lt__, __gt__)的return false即可 -# bool pk_stack_binaryop(VM* self, py_Name op, py_Name rop) { -# // [a, b] -# py_Ref magic = py_tpfindmagic(SECOND()->type, op); -# if(magic) { -# bool ok = py_call(magic, 2, SECOND()); -# ----> if(!ok) return false; -# if(self->last_retval.type != tp_NotImplementedType) return true; -# } -# // try reverse operation -# if(rop) { -# // [a, b] -> [b, a] -# py_TValue tmp = *TOP(); -# *TOP() = *SECOND(); -# *SECOND() = tmp; -# magic = py_tpfindmagic(SECOND()->type, rop); -# if(magic) { -# bool ok = py_call(magic, 2, SECOND()); -# ----> if(!ok) return false; -# if(self->last_retval.type != tp_NotImplementedType) return true; -# } -# } -# // eq/ne op never fails -# bool res = py_isidentical(SECOND(), TOP()); -# if(op == __eq__) { -# py_newbool(py_retval(), res); -# return true; -# } -# if(op == __ne__) { -# py_newbool(py_retval(), !res); -# return true; -# } - -# py_Type lhs_t = rop ? TOP()->type : SECOND()->type; -# py_Type rhs_t = rop ? SECOND()->type : TOP()->type; -# return TypeError("unsupported operand type(s) for '%s': '%t' and '%t'", -# pk_op2str(op), -# lhs_t, -# rhs_t); -# } - -# -# 调查得知只要触发bool ok = py_call(py_tpfindmagic(SECOND()->type, __lt__/__gt__), 2, SECOND())的return false即可 -# bool py_call(py_Ref f, int argc, py_Ref argv) { -# if(f->type == tp_nativefunc) { -# return py_callcfunc(f->_cfunc, argc, argv); -# } else { -# py_push(f); -# py_pushnil(); -# for(int i = 0; i < argc; i++) -# py_push(py_offset(argv, i)); -# bool ok = py_vectorcall(argc, 0); -# return ok; -# } -# } - -class A(): - def __lt__(self, other:int=1): - return True - - -try: - [A(), 1111].sort() -except TypeError: - pass \ No newline at end of file