From 57aebe96dd8361cc31ac86ca11cd7e9cb40c18c0 Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Sun, 14 Jul 2024 12:19:46 +0100 Subject: [PATCH 1/2] fix pyMethodDef layout --- src/python.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/python.ts b/src/python.ts index e09b821..dcaa4dc 100644 --- a/src/python.ts +++ b/src/python.ts @@ -452,7 +452,9 @@ export class PyObject { } return new PyObject(list); } else if (v instanceof Callback) { - const pyMethodDef = new Uint8Array(8 + 8 + 4 + 8); + // https://docs.python.org/3/c-api/structures.html#c.PyMethodDef + // there extra 4 bytes of padding after ml_flags field + const pyMethodDef = new Uint8Array(8 + 8 + 4 + 4 + 8); const view = new DataView(pyMethodDef.buffer); const LE = new Uint8Array(new Uint32Array([0x12345678]).buffer)[0] !== 0x7; @@ -471,7 +473,7 @@ export class PyObject { ); view.setInt32(16, 0x1 | 0x2, LE); view.setBigUint64( - 20, + 24, BigInt(Deno.UnsafePointer.value(Deno.UnsafePointer.of(nameBuf)!)), LE, ); From 579b3b29e0f21df9dd24b86dfef18b0f12180389 Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Sun, 14 Jul 2024 12:21:17 +0100 Subject: [PATCH 2/2] comment --- src/python.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python.ts b/src/python.ts index dcaa4dc..9c41ea1 100644 --- a/src/python.ts +++ b/src/python.ts @@ -453,7 +453,7 @@ export class PyObject { return new PyObject(list); } else if (v instanceof Callback) { // https://docs.python.org/3/c-api/structures.html#c.PyMethodDef - // there extra 4 bytes of padding after ml_flags field + // there are extra 4 bytes of padding after ml_flags field const pyMethodDef = new Uint8Array(8 + 8 + 4 + 4 + 8); const view = new DataView(pyMethodDef.buffer); const LE =