@@ -149,11 +149,11 @@ export class Callback {
149
149
kwargs : Deno . PointerValue ,
150
150
) => {
151
151
return PyObject . from ( callback (
152
- kwargs === 0 ? { } : Object . fromEntries (
152
+ kwargs === null ? { } : Object . fromEntries (
153
153
new PyObject ( kwargs ) . asDict ( )
154
154
. entries ( ) ,
155
155
) ,
156
- ...( args === 0 ? [ ] : new PyObject ( args ) . valueOf ( ) ) ,
156
+ ...( args === null ? [ ] : new PyObject ( args ) . valueOf ( ) ) ,
157
157
) ) . handle ;
158
158
} ,
159
159
) ;
@@ -193,8 +193,7 @@ export class PyObject {
193
193
* Check if the object is NULL (pointer) or None type in Python.
194
194
*/
195
195
get isNone ( ) {
196
- return this . handle === 0 ||
197
- this . handle === 0n ||
196
+ return this . handle === null ||
198
197
this . handle === python . None [ ProxiedPyObject ] . handle ;
199
198
}
200
199
@@ -290,7 +289,7 @@ export class PyObject {
290
289
this . handle ,
291
290
parseInt ( name ) ,
292
291
) ;
293
- if ( item !== 0 ) {
292
+ if ( item !== null ) {
294
293
return new PyObject ( item ) . proxy ;
295
294
}
296
295
}
@@ -302,7 +301,7 @@ export class PyObject {
302
301
this . handle ,
303
302
slice . handle ,
304
303
) ;
305
- if ( item !== 0 ) {
304
+ if ( item !== null ) {
306
305
return new PyObject ( item ) . proxy ;
307
306
}
308
307
}
@@ -319,7 +318,7 @@ export class PyObject {
319
318
this . handle ,
320
319
cstr ( name ) ,
321
320
) ;
322
- if ( value !== 0 ) {
321
+ if ( value !== null ) {
323
322
return new PyObject ( value ) . proxy ;
324
323
}
325
324
}
@@ -443,20 +442,24 @@ export class PyObject {
443
442
) ;
444
443
view . setBigUint64 (
445
444
0 ,
446
- BigInt ( Deno . UnsafePointer . of ( nameBuf ) ) ,
445
+ BigInt ( Deno . UnsafePointer . value ( Deno . UnsafePointer . of ( nameBuf ) ! ) ) ,
446
+ LE ,
447
+ ) ;
448
+ view . setBigUint64 (
449
+ 8 ,
450
+ BigInt ( Deno . UnsafePointer . value ( v . unsafe . pointer ) ) ,
447
451
LE ,
448
452
) ;
449
- view . setBigUint64 ( 8 , BigInt ( v . unsafe . pointer ) , LE ) ;
450
453
view . setInt32 ( 16 , 0x1 | 0x2 , LE ) ;
451
454
view . setBigUint64 (
452
455
20 ,
453
- BigInt ( Deno . UnsafePointer . of ( nameBuf ) ) ,
456
+ BigInt ( Deno . UnsafePointer . value ( Deno . UnsafePointer . of ( nameBuf ) ! ) ) ,
454
457
LE ,
455
458
) ;
456
459
const fn = py . PyCFunction_NewEx (
457
460
struct ,
458
461
PyObject . from ( null ) . handle ,
459
- 0n ,
462
+ null ,
460
463
) ;
461
464
return new PyObject ( fn ) ;
462
465
} else if ( v instanceof PyObject ) {
@@ -526,7 +529,7 @@ export class PyObject {
526
529
const obj = new PyObject (
527
530
py . PyObject_GetAttrString ( this . handle , cstr ( name ) ) ,
528
531
) ;
529
- if ( obj . handle === 0 ) {
532
+ if ( obj . handle === null ) {
530
533
py . PyErr_Clear ( ) ;
531
534
return undefined ;
532
535
} else {
@@ -592,11 +595,7 @@ export class PyObject {
592
595
*/
593
596
asString ( ) {
594
597
const str = py . PyUnicode_AsUTF8 ( this . handle ) ;
595
- if ( str === 0 ) {
596
- return null ;
597
- } else {
598
- return Deno . UnsafePointerView . getCString ( str as bigint ) ;
599
- }
598
+ return str !== null ? Deno . UnsafePointerView . getCString ( str ) : null ;
600
599
}
601
600
602
601
/**
@@ -635,7 +634,7 @@ export class PyObject {
635
634
* [ Symbol . iterator ] ( ) {
636
635
const iter = py . PyObject_GetIter ( this . handle ) ;
637
636
let item = py . PyIter_Next ( iter ) ;
638
- while ( item !== 0 ) {
637
+ while ( item !== null ) {
639
638
yield new PyObject ( item ) ;
640
639
item = py . PyIter_Next ( iter ) ;
641
640
}
@@ -677,23 +676,39 @@ export class PyObject {
677
676
valueOf ( ) {
678
677
const type = py . PyObject_Type ( this . handle ) ;
679
678
680
- if ( type === python . None [ ProxiedPyObject ] . handle ) {
679
+ if ( Deno . UnsafePointer . equals ( type , python . None [ ProxiedPyObject ] . handle ) ) {
681
680
return null ;
682
- } else if ( type === python . bool [ ProxiedPyObject ] . handle ) {
681
+ } else if (
682
+ Deno . UnsafePointer . equals ( type , python . bool [ ProxiedPyObject ] . handle )
683
+ ) {
683
684
return this . asBoolean ( ) ;
684
- } else if ( type === python . int [ ProxiedPyObject ] . handle ) {
685
+ } else if (
686
+ Deno . UnsafePointer . equals ( type , python . int [ ProxiedPyObject ] . handle )
687
+ ) {
685
688
return this . asLong ( ) ;
686
- } else if ( type === python . float [ ProxiedPyObject ] . handle ) {
689
+ } else if (
690
+ Deno . UnsafePointer . equals ( type , python . float [ ProxiedPyObject ] . handle )
691
+ ) {
687
692
return this . asDouble ( ) ;
688
- } else if ( type === python . str [ ProxiedPyObject ] . handle ) {
693
+ } else if (
694
+ Deno . UnsafePointer . equals ( type , python . str [ ProxiedPyObject ] . handle )
695
+ ) {
689
696
return this . asString ( ) ;
690
- } else if ( type === python . list [ ProxiedPyObject ] . handle ) {
697
+ } else if (
698
+ Deno . UnsafePointer . equals ( type , python . list [ ProxiedPyObject ] . handle )
699
+ ) {
691
700
return this . asArray ( ) ;
692
- } else if ( type === python . dict [ ProxiedPyObject ] . handle ) {
701
+ } else if (
702
+ Deno . UnsafePointer . equals ( type , python . dict [ ProxiedPyObject ] . handle )
703
+ ) {
693
704
return this . asDict ( ) ;
694
- } else if ( type === python . set [ ProxiedPyObject ] . handle ) {
705
+ } else if (
706
+ Deno . UnsafePointer . equals ( type , python . set [ ProxiedPyObject ] . handle )
707
+ ) {
695
708
return this . asSet ( ) ;
696
- } else if ( type === python . tuple [ ProxiedPyObject ] . handle ) {
709
+ } else if (
710
+ Deno . UnsafePointer . equals ( type , python . tuple [ ProxiedPyObject ] . handle )
711
+ ) {
697
712
return this . asTuple ( ) ;
698
713
} else {
699
714
return this . proxy ;
@@ -777,7 +792,7 @@ export class PythonError extends Error {
777
792
*/
778
793
export function maybeThrowError ( ) {
779
794
const error = py . PyErr_Occurred ( ) ;
780
- if ( error === 0 ) {
795
+ if ( error === null ) {
781
796
return ;
782
797
}
783
798
@@ -788,9 +803,9 @@ export function maybeThrowError() {
788
803
pointers . subarray ( 2 , 3 ) ,
789
804
) ;
790
805
791
- const type = new PyObject ( pointers [ 0 ] ) ,
792
- value = new PyObject ( pointers [ 1 ] ) ,
793
- traceback = new PyObject ( pointers [ 2 ] ) ;
806
+ const type = new PyObject ( Deno . UnsafePointer . create ( pointers [ 0 ] ) ) ,
807
+ value = new PyObject ( Deno . UnsafePointer . create ( pointers [ 1 ] ) ) ,
808
+ traceback = new PyObject ( Deno . UnsafePointer . create ( pointers [ 2 ] ) ) ;
794
809
795
810
let errorMessage = ( value ?? type ) . toString ( ) ?? "Unknown error" ;
796
811
if ( ! traceback . isNone ) {
@@ -880,7 +895,7 @@ export class Python {
880
895
)
881
896
. handle ,
882
897
) ;
883
- if ( module === 0 ) {
898
+ if ( module === null ) {
884
899
throw new PythonError ( "Failed to run module" ) ;
885
900
}
886
901
return new PyObject ( module ) ?. proxy ;
@@ -891,7 +906,7 @@ export class Python {
891
906
*/
892
907
importObject ( name : string ) {
893
908
const mod = py . PyImport_ImportModule ( cstr ( name ) ) ;
894
- if ( mod === 0 ) {
909
+ if ( mod === null ) {
895
910
maybeThrowError ( ) ;
896
911
throw new PythonError ( `Failed to import module ${ name } ` ) ;
897
912
}
@@ -949,7 +964,7 @@ function toSlice(sliceList: string): PyObject {
949
964
const pyTuple_Pack = new Deno . UnsafeFnPointer (
950
965
// TODO: this isn't really a `bigint`, but Deno's type definitions
951
966
// haven't been updated to support `number` yet
952
- py . PyTuple_Pack as bigint ,
967
+ py . PyTuple_Pack ! ,
953
968
{
954
969
parameters : [ "i32" , ...pySlicesHandle . map ( ( ) => "pointer" as const ) ] ,
955
970
result : "pointer" ,
0 commit comments