@@ -1550,33 +1550,40 @@ Object doPythonObject(PythonManagedClass obj, Object getBufferProc, Object relea
1550
1550
@ GenerateNodeFactory
1551
1551
abstract static class PyTruffle_MemoryViewFromObject extends NativeBuiltin {
1552
1552
@ Specialization
1553
- static Object wrap (Object object ,
1554
- @ Cached AsPythonObjectNode asPythonObjectNode ,
1553
+ Object wrap (VirtualFrame frame , Object object ,
1555
1554
@ Cached BuiltinConstructors .MemoryViewNode memoryViewNode ,
1556
- @ Cached ToNewRefNode toNewRefNode ) {
1557
- return toNewRefNode .execute (memoryViewNode .create (asPythonObjectNode .execute (object )));
1555
+ @ Cached GetNativeNullNode getNativeNullNode ) {
1556
+ try {
1557
+ return memoryViewNode .create (object );
1558
+ } catch (PException e ) {
1559
+ transformToNative (frame , e );
1560
+ return getNativeNullNode .execute ();
1561
+ }
1558
1562
}
1559
1563
}
1560
1564
1565
+ // Called without landing node
1561
1566
@ Builtin (name = NativeCAPISymbols .FUN_PY_TRUFFLE_MEMORYVIEW_FROM_BUFFER , minNumOfPositionalArgs = 12 )
1562
1567
@ GenerateNodeFactory
1563
1568
abstract static class PyTruffle_MemoryViewFromBuffer extends NativeBuiltin {
1564
1569
1565
1570
@ Specialization
1566
- static Object wrap (Object bufferStructPointer , Object ownerObj , Object releasefn , Object lenObj , Object readonlyObj , Object itemsizeObj , Object formatObj ,
1571
+ Object wrap (VirtualFrame frame , Object bufferStructPointer , Object ownerObj , Object releasefn , Object lenObj ,
1572
+ Object readonlyObj , Object itemsizeObj , Object formatObj ,
1567
1573
Object ndimObj , Object bufPointer , Object shapePointer , Object stridesPointer , Object suboffsetsPointer ,
1568
1574
@ Cached MemoryViewNodes .InitFlagsNode initFlagsNode ,
1569
1575
@ CachedLibrary (limit = "1" ) InteropLibrary lib ,
1570
1576
@ Cached CastToJavaIntExactNode castToIntNode ,
1571
1577
@ Cached AsPythonObjectNode asPythonObjectNode ,
1572
- @ Cached ToNewRefNode toNewRefNode ) {
1573
- int ndim = castToIntNode .execute (ndimObj );
1574
- int itemsize = castToIntNode .execute (itemsizeObj );
1575
- int len = castToIntNode .execute (lenObj );
1576
- boolean readonly = castToIntNode .execute (readonlyObj ) != 0 ;
1577
- String format = (String ) asPythonObjectNode .execute (formatObj );
1578
- Object owner = lib .isNull (ownerObj ) ? null : asPythonObjectNode .execute (ownerObj );
1578
+ @ Cached ToNewRefNode toNewRefNode ,
1579
+ @ Cached GetNativeNullNode getNativeNullNode ) {
1579
1580
try {
1581
+ int ndim = castToIntNode .execute (ndimObj );
1582
+ int itemsize = castToIntNode .execute (itemsizeObj );
1583
+ int len = castToIntNode .execute (lenObj );
1584
+ boolean readonly = castToIntNode .execute (readonlyObj ) != 0 ;
1585
+ String format = (String ) asPythonObjectNode .execute (formatObj );
1586
+ Object owner = lib .isNull (ownerObj ) ? null : asPythonObjectNode .execute (ownerObj );
1580
1587
int [] shape = null ;
1581
1588
int [] strides = null ;
1582
1589
int [] suboffsets = null ;
@@ -1617,6 +1624,9 @@ static Object wrap(Object bufferStructPointer, Object ownerObj, Object releasefn
1617
1624
PythonBuiltinClassType .PMemoryView .getInstanceShape (),
1618
1625
managedBuffer , owner , len , readonly , itemsize , format , ndim , bufPointer , 0 , shape , strides , suboffsets , flags );
1619
1626
return toNewRefNode .execute (memoryview );
1627
+ } catch (PException e ) {
1628
+ transformToNative (frame , e );
1629
+ return toNewRefNode .execute (getNativeNullNode .execute ());
1620
1630
} catch (UnsupportedMessageException | InvalidArrayIndexException e ) {
1621
1631
throw CompilerDirectives .shouldNotReachHere (e );
1622
1632
}
0 commit comments