@@ -53,10 +53,7 @@ uint64_t (*PY_TRUFFLE_CEXT_LANDING_L)(void* name, ...);
5353double (* PY_TRUFFLE_CEXT_LANDING_D )(void * name , ...);
5454void * (* PY_TRUFFLE_CEXT_LANDING_PTR )(void * name , ...);
5555
56- typedef void * (* cache_t )(uint64_t );
57- static cache_t cache ;
58-
59- #define resolve_handle (__cache__ , __addr__ ) (__cache__)(__addr__)
56+ cache_t cache ;
6057
6158__attribute__((constructor (__COUNTER__ )))
6259static void initialize_upcall_functions () {
@@ -198,28 +195,6 @@ static void initialize_capi() {
198195 initialize_bufferprocs ();
199196}
200197
201- // Heuristic to test if some value is a pointer object
202- // TODO we need a reliable solution for that
203- #define IS_POINTER (__val__ ) (polyglot_is_value(__val__) && !polyglot_fits_in_i64(__val__))
204-
205- MUST_INLINE
206- void * native_to_java (PyObject * obj ) {
207- if (obj == NULL ) {
208- return Py_NoValue ;
209- } else if (obj == Py_None ) {
210- return Py_None ;
211- } else if (polyglot_is_string (obj )) {
212- return obj ;
213- } else if (truffle_is_handle_to_managed (obj )) {
214- return resolve_handle (cache , (uint64_t )obj );
215- } else if (truffle_is_handle_to_managed (obj -> ob_refcnt )) {
216- return truffle_managed_from_handle (obj -> ob_refcnt );
217- } else if (IS_POINTER (obj -> ob_refcnt )) {
218- return obj -> ob_refcnt ;
219- }
220- return obj ;
221- }
222-
223198void * native_to_java_exported (PyObject * obj ) {
224199 return native_to_java (obj );
225200}
@@ -273,15 +248,15 @@ uint64_t PyTruffle_Wchar_Size() {
273248}
274249
275250void * PyObjectHandle_ForJavaObject (void * cobj , unsigned long flags ) {
276- if (! truffle_is_handle_to_managed (cobj )) {
251+ if (truffle_is_handle_to_managed (cobj )) {
277252 return truffle_deref_handle_for_managed (cobj );
278253 }
279254 return cobj ;
280255}
281256
282257/** to be used from Java code only; only creates the deref handle */
283258void * PyObjectHandle_ForJavaType (void * ptype ) {
284- if (! truffle_is_handle_to_managed (ptype )) {
259+ if (truffle_is_handle_to_managed (ptype )) {
285260 return truffle_deref_handle_for_managed (ptype );
286261 }
287262 return ptype ;
0 commit comments