@@ -285,12 +285,20 @@ int PySequence_Check(PyObject *s) {
285
285
return UPCALL_CEXT_I (_jls_PySequence_Check , native_to_java (s ));
286
286
}
287
287
288
+ // downcall for native python objects
289
+ // taken from CPython "Objects/abstract.c PySequence_Check()"
290
+ int PyTruffle_PySequence_Check (PyObject * s ) {
291
+ if (PyDict_Check (s ))
292
+ return 0 ;
293
+ return s -> ob_type -> tp_as_sequence && s -> ob_type -> tp_as_sequence -> sq_item != NULL ;
294
+ }
295
+
288
296
UPCALL_ID (PySequence_Size );
289
297
Py_ssize_t PySequence_Size (PyObject * s ) {
290
298
return UPCALL_CEXT_L (_jls_PySequence_Size , native_to_java (s ));
291
299
}
292
300
293
- // PySequence_Size downcall for native python objects
301
+ // downcall for native python objects
294
302
// taken from CPython "Objects/abstract.c/Py_Sequence_Size"
295
303
Py_ssize_t PyTruffle_PySequence_Size (PyObject * s ) {
296
304
PySequenceMethods * m ;
@@ -308,10 +316,10 @@ Py_ssize_t PyTruffle_PySequence_Size(PyObject *s) {
308
316
}
309
317
310
318
if (s -> ob_type -> tp_as_mapping && s -> ob_type -> tp_as_mapping -> mp_length ) {
311
- PyErr_Format (PyExc_TypeError , "%s is not a sequence" , s );
319
+ PyErr_Format (PyExc_TypeError , "PyTruffle_PySequence_Size(): object of type '%s' is not a sequence" , Py_TYPE ( s ) -> tp_name );
312
320
return -1 ;
313
321
}
314
- PyErr_Format (PyExc_TypeError , "object of type '%s' has no len()" , Py_TYPE (s )-> tp_name );
322
+ PyErr_Format (PyExc_TypeError , "PyTruffle_PySequence_Size(): object of type '%s' has no len()" , Py_TYPE (s )-> tp_name );
315
323
return -1 ;
316
324
}
317
325
@@ -377,8 +385,8 @@ Py_ssize_t PyObject_Size(PyObject *o) {
377
385
return UPCALL_CEXT_L (_jls_PyObject_Size , native_to_java (o ));
378
386
}
379
387
380
- // PyObject_Size downcall for native python objects
381
- // taken from CPython "Objects/abstract.c/Py_Object_Size "
388
+ // downcall for native python objects
389
+ // taken from CPython "Objects/abstract.c/PyObject_Size "
382
390
Py_ssize_t PyTruffle_PyObject_Size (PyObject * o ) {
383
391
PySequenceMethods * m ;
384
392
@@ -415,8 +423,14 @@ PyObject * PyMapping_Values(PyObject *o) {
415
423
return UPCALL_CEXT_O (_jls_PyMapping_Values , native_to_java (o ));
416
424
}
417
425
418
- // taken from CPython "Objects/abstract.c"
426
+ UPCALL_ID ( PyMapping_Check );
419
427
int PyMapping_Check (PyObject * o ) {
428
+ return UPCALL_CEXT_I (_jls_PyMapping_Check , native_to_java (o ));
429
+ }
430
+
431
+ // downcall for native python objects
432
+ // taken from CPython "Objects/abstract.c PyMapping_Check"
433
+ int PyTruffle_PyMapping_Check (PyObject * o ) {
420
434
return o && o -> ob_type -> tp_as_mapping && o -> ob_type -> tp_as_mapping -> mp_subscript ;
421
435
}
422
436
@@ -589,7 +603,7 @@ Py_ssize_t PyTruffle_PyMapping_Size(PyObject *o) {
589
603
return len ;
590
604
}
591
605
592
- PyErr_Format (PyExc_TypeError , "object of type '%s' has no len()" , Py_TYPE (o )-> tp_name );
606
+ PyErr_Format (PyExc_TypeError , "PyTruffle_PyMapping_Size(): object of type '%s' has no len()" , Py_TYPE (o )-> tp_name );
593
607
return -1 ;
594
608
}
595
609
0 commit comments