Skip to content

Commit 5bc7819

Browse files
committed
cleanup
1 parent 19ae06d commit 5bc7819

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/python.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,18 @@ export class PyObject {
365365
*/
366366
get owned(): PyObject {
367367
const handleValue = Deno.UnsafePointer.value(this.handle);
368-
const handleKey = typeof handleValue === "bigint"
369-
? handleValue
370-
: BigInt(handleValue);
371368

372-
if (!registeredHandles.has(handleKey)) {
369+
if (!registeredHandles.has(handleValue)) {
373370
// Check if this is a callback (has #callback reference)
374371
if (this.#callback) {
375372
// Callback - register with callbackRegistry now that it's being passed to Python
376-
callbackRegistry.set(handleKey, this.#callback);
373+
callbackRegistry.set(handleValue, this.#callback);
377374
} else {
378375
// Normal PyObject - use refregistry
379376
py.Py_IncRef(this.handle);
380377
refregistry.register(this, this.handle);
381378
}
382-
registeredHandles.add(handleKey);
379+
registeredHandles.add(handleValue);
383380
}
384381

385382
return this;
@@ -676,7 +673,7 @@ export class PyObject {
676673

677674
// Create a capsule with destructor to track when Python frees the callback
678675
const capsule = py.PyCapsule_New(
679-
Deno.UnsafePointer.of(handleBuffer),
676+
handleBuffer,
680677
CAPSULE_NAME,
681678
capsuleDestructor.pointer,
682679
);
@@ -692,14 +689,11 @@ export class PyObject {
692689

693690
// Now fill in the handle buffer with the actual function pointer
694691
const handleValue = Deno.UnsafePointer.value(fn);
695-
const handleKey = typeof handleValue === "bigint"
696-
? handleValue
697-
: BigInt(handleValue);
698-
handleBuffer[0] = handleKey;
692+
handleBuffer[0] = handleValue;
699693

700694
// Store handle buffer for capsule destructor lookup
701695
// The callback will be added to callbackRegistry when .owned is called
702-
handleBuffers.set(handleKey, handleBuffer);
696+
handleBuffers.set(handleValue, handleBuffer);
703697

704698
// Decref capsule so only PyCFunction holds it
705699
// When PyCFunction is freed, capsule refcount goes to 0, triggering our destructor
@@ -769,12 +763,9 @@ export class PyObject {
769763

770764
// Register with cleanup registry for auto-created callbacks
771765
const handleValue = Deno.UnsafePointer.value(pyObject.handle);
772-
const handleKey = typeof handleValue === "bigint"
773-
? handleValue
774-
: BigInt(handleValue);
775766
callbackCleanupRegistry.register(pyObject, {
776767
callback,
777-
handle: handleKey,
768+
handle: handleValue,
778769
});
779770
return pyObject;
780771
}

src/symbols.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export const SYMBOLS = {
261261
},
262262

263263
PyCapsule_New: {
264-
parameters: ["pointer", "buffer", "pointer"], // pointer, name, destructor
264+
parameters: ["buffer", "buffer", "pointer"], // pointer, name, destructor
265265
result: "pointer",
266266
},
267267

0 commit comments

Comments
 (0)