33try :
44 # module locations as of numba 0.49.0
55 from numba .core import cgutils , types
6+ from numba .core .imputils import lower_constant
67except ImportError :
78 # module locations prior to numba 0.49.0
89 from numba import cgutils , types
10+ from numba .targets .imputils import lower_constant
911
1012from .._layout import Layout
1113
1214
13- # Taken from numba_passthru
14- opaque_pyobject = types .Opaque ('Opaque(PyObject)' )
15+ opaque_layout = types .Opaque ('Opaque(Layout)' )
1516
1617
1718class LayoutType (types .Type ):
@@ -23,7 +24,7 @@ def __init__(self):
2324class LayoutModel (numba .extending .models .StructModel ):
2425 def __init__ (self , dmm , fe_typ ):
2526 members = [
26- ('meminfo ' , types . MemInfoPointer ( opaque_pyobject ) ),
27+ ('obj ' , opaque_layout ),
2728 ]
2829 super ().__init__ (dmm , fe_typ , members )
2930
@@ -33,18 +34,25 @@ def _typeof_Layout(val: Layout, c) -> LayoutType:
3334 return LayoutType ()
3435
3536
36- # Derived from numba_passthru
37+ # Derived from the `Dispatcher` boxing
38+
39+ @lower_constant (LayoutType )
40+ def lower_constant_dispatcher (context , builder , typ , pyval ):
41+ layout = cgutils .create_struct_proxy (typ )(context , builder )
42+ layout .obj = context .add_dynamic_addr (builder , id (pyval ), info = type (pyval ).__name__ )
43+ return layout ._getvalue ()
44+
3745
3846@numba .extending .unbox (LayoutType )
3947def unbox_Layout (typ , obj , context ):
4048 layout = cgutils .create_struct_proxy (typ )(context .context , context .builder )
41- layout .meminfo = context . pyapi . nrt_meminfo_new_from_pyobject ( obj , obj )
49+ layout .obj = obj
4250 return numba .extending .NativeValue (layout ._getvalue ())
4351
4452
4553@numba .extending .box (LayoutType )
4654def box_Layout (typ , val , context ):
4755 val = cgutils .create_struct_proxy (typ )(context .context , context .builder , value = val )
48- obj = context . context . nrt . meminfo_data ( context . builder , val .meminfo )
56+ obj = val .obj
4957 context .pyapi .incref (obj )
5058 return obj
0 commit comments