@@ -188,17 +188,21 @@ Object usingNativePointer(Object type, Object[] args, @SuppressWarnings("unused"
188
188
@ Bind ("this" ) Node inliningTarget ,
189
189
@ SuppressWarnings ("unused" ) @ Cached PyLongCheckNode longCheckNode ,
190
190
@ Cached PointerNodes .PointerFromLongNode pointerFromLongNode ,
191
+ @ Cached PointerNodes .WritePointerNode writePointerNode ,
191
192
@ Cached PyTypeStgDictNode pyTypeStgDictNode ) {
192
193
CDataObject ob = factory ().createPyCFuncPtrObject (type );
193
194
StgDictObject dict = pyTypeStgDictNode .checkAbstractClass (type , getRaiseNode ());
194
195
GenericPyCDataNew (dict , ob );
195
- ob .b_ptr = pointerFromLongNode .execute (inliningTarget , args [0 ]).createReference ();
196
+ Pointer value = pointerFromLongNode .execute (inliningTarget , args [0 ]);
197
+ writePointerNode .execute (inliningTarget , ob .b_ptr , value );
196
198
return ob ;
197
199
}
198
200
199
201
@ Specialization (guards = {"args.length > 0" , "!isPTuple(args)" , "!isLong(args, longCheckNode)" })
200
202
Object callback (VirtualFrame frame , Object type , Object [] args , @ SuppressWarnings ("unused" ) PKeyword [] kwds ,
203
+ @ Bind ("this" ) Node inliningTarget ,
201
204
@ SuppressWarnings ("unused" ) @ Cached PyLongCheckNode longCheckNode ,
205
+ @ Cached PointerNodes .WritePointerNode writePointerNode ,
202
206
@ Cached KeepRefNode keepRefNode ,
203
207
@ Cached PyCallableCheckNode callableCheck ,
204
208
@ Cached PyTypeStgDictNode pyTypeStgDictNode ) {
@@ -207,20 +211,7 @@ Object callback(VirtualFrame frame, Object type, Object[] args, @SuppressWarning
207
211
throw raise (TypeError , ARGUMENT_MUST_BE_CALLABLE_OR_INTEGER_FUNCTION_ADDRESS );
208
212
}
209
213
210
- /*
211
- * XXX XXX This would allow passing additional options. For COM method
212
- * *implementations*, we would probably want different behaviour than in 'normal'
213
- * callback functions: return a HRESULT if an exception occurs in the callback, and
214
- * print the traceback not only on the console, but also to OutputDebugString() or
215
- * something like that.
216
- */
217
- /*
218
- * if (kwds && _PyDict_GetItemIdWithError(kwds, &PyId_options)) { ... } else if
219
- * (PyErr_Occurred()) { return NULL; }
220
- */
221
-
222
214
StgDictObject dict = pyTypeStgDictNode .checkAbstractClass (type , getRaiseNode ());
223
- /* XXXX Fails if we do: 'PyCFuncPtr(lambda x: x)' */
224
215
if (dict == null || dict .argtypes == null ) {
225
216
throw raise (TypeError , CANNOT_CONSTRUCT_INSTANCE_OF_THIS_CLASS_NO_ARGTYPES );
226
217
}
@@ -230,8 +221,7 @@ Object callback(VirtualFrame frame, Object type, Object[] args, @SuppressWarning
230
221
GenericPyCDataNew (dict , self );
231
222
self .callable = callable ;
232
223
self .thunk = thunk ;
233
- self .b_ptr = Pointer .nativeMemory (thunk .pcl_exec ).createReference ();
234
-
224
+ writePointerNode .execute (inliningTarget , self .b_ptr , Pointer .nativeMemory (thunk .pcl_exec ));
235
225
keepRefNode .execute (frame , self , 0 , thunk );
236
226
return self ;
237
227
}
@@ -774,6 +764,7 @@ Object PyCFuncPtr_FromDll(VirtualFrame frame, Object type, Object[] args,
774
764
@ Cached PyTypeCheck pyTypeCheck ,
775
765
@ Cached CtypesDlSymNode dlSymNode ,
776
766
@ Cached PointerNodes .PointerFromLongNode pointerFromLongNode ,
767
+ @ Cached PointerNodes .WritePointerNode writePointerNode ,
777
768
@ Cached PyLongCheckNode longCheckNode ,
778
769
@ Cached GetInternalObjectArrayNode getArray ,
779
770
@ Cached CastToTruffleStringNode toString ,
@@ -815,7 +806,7 @@ Object PyCFuncPtr_FromDll(VirtualFrame frame, Object type, Object[] args,
815
806
self .paramflags = paramflags ;
816
807
817
808
Object addressObj = address instanceof PythonNativeVoidPtr ptr ? ptr .getPointerObject () : address ;
818
- self .b_ptr = Pointer .nativeMemory (addressObj ). createReference ( );
809
+ writePointerNode . execute ( inliningTarget , self .b_ptr , Pointer .nativeMemory (addressObj ));
819
810
keepRefNode .execute (frame , self , 0 , dll );
820
811
821
812
self .callable = self ;
0 commit comments