@@ -207,9 +207,11 @@ extern void* (*PY_TRUFFLE_CEXT_LANDING_PTR)(void* name, ...);
207207typedef void * (* cache_t )(uint64_t );
208208extern cache_t cache ;
209209
210- typedef void * (* ptr_cache_t )(void * , uint64_t );
210+ typedef PyObject * (* ptr_cache_t )(PyObject * );
211+ typedef PyTypeObject * (* type_ptr_cache_t )(PyTypeObject * , int64_t );
211212extern ptr_cache_t ptr_cache ;
212213extern ptr_cache_t ptr_cache_stealing ;
214+ extern type_ptr_cache_t type_ptr_cache ;
213215
214216typedef int (* alloc_upcall_fun_t )(void * , Py_ssize_t );
215217extern alloc_upcall_fun_t alloc_upcall ;
@@ -228,51 +230,31 @@ Py_ssize_t PyTruffle_Type_AddSlots(PyTypeObject* cls, PyObject* slotsTuple);
228230
229231
230232MUST_INLINE
231- void * native_to_java (PyObject * obj ) {
232- if (obj == NULL ) {
233- return Py_NoValue ;
234- } else if (obj == Py_None ) {
235- return Py_None ;
236- } else if (polyglot_is_string (obj )) {
237- return obj ;
238- } else if (!truffle_cannot_be_handle (obj )) {
239- return resolve_handle (cache , (uint64_t )obj );
233+ PyObject * native_to_java (PyObject * obj ) {
234+ if (!truffle_cannot_be_handle (obj )) {
235+ return truffle_managed_from_handle (obj );
240236 }
241- return ptr_cache (obj , obj -> ob_refcnt );
237+ return ptr_cache (obj );
242238}
243239
244240MUST_INLINE
245- void * native_to_java_stealing (PyObject * obj ) {
246- if (obj == NULL ) {
247- return Py_NoValue ;
248- } else if (obj == Py_None ) {
249- return Py_None ;
250- } else if (polyglot_is_string (obj )) {
251- return obj ;
252- } else if (!truffle_cannot_be_handle (obj )) {
241+ PyObject * native_to_java_stealing (PyObject * obj ) {
242+ if (!truffle_cannot_be_handle (obj )) {
253243 return resolve_handle (cache , (uint64_t )obj );
254244 }
255- return ptr_cache_stealing (obj , obj -> ob_refcnt );
245+ return ptr_cache_stealing (obj );
256246}
257247
258248
259249extern void * native_to_java_exported (PyObject * obj );
260250extern void * native_to_java_stealing_exported (PyObject * obj );
261251
262- MUST_INLINE
263- void * native_to_java_slim (PyObject * obj ) {
264- if (!truffle_cannot_be_handle (obj )) {
265- return truffle_managed_from_handle (obj );
266- }
267- return ptr_cache (obj , obj != NULL ? obj -> ob_refcnt : 0 );
268- }
269-
270252MUST_INLINE
271253PyTypeObject * native_type_to_java (PyTypeObject * type ) {
272254 if (!truffle_cannot_be_handle (type )) {
273255 return (PyTypeObject * )truffle_managed_from_handle (type );
274256 }
275- return ptr_cache (type , type -> ob_base . ob_base . ob_refcnt );
257+ return type_ptr_cache (type , Py_REFCNT ( type ) );
276258}
277259
278260MUST_INLINE
0 commit comments