@@ -725,11 +725,38 @@ pycall_libpython_helpers_m_compare(VALUE mod, VALUE op, VALUE pyptr_a, VALUE pyp
725
725
return pycall_pyobject_to_ruby (res );
726
726
}
727
727
728
+ static int is_pyobject_wrapper (VALUE obj );
729
+
730
+ VALUE
731
+ pycall_getattr_default (VALUE obj , char const * name , VALUE default_value )
732
+ {
733
+ PyObject * pyobj , * res ;
734
+
735
+ if (is_pyobject_wrapper (obj )) {
736
+ pyobj = pycall_pyobject_wrapper_get_pyobj_ptr (obj );
737
+ }
738
+ else {
739
+ pyobj = check_get_pyobj_ptr (obj , NULL );
740
+ }
741
+
742
+ res = Py_API (PyObject_GetAttrString )(pyobj , name );
743
+ if (!res && default_value == Qundef ) {
744
+ pycall_pyerror_fetch_and_raise ("PyObject_GetAttrString in pycall_libpython_helpers_m_getattr" );
745
+ }
746
+ Py_API (PyErr_Clear )();
747
+ return res ? pycall_pyobject_to_ruby (res ) : default_value ;
748
+ }
749
+
750
+ VALUE
751
+ pycall_getattr (VALUE pyptr , char const * name )
752
+ {
753
+ return pycall_getattr_default (pyptr , name , Qundef );
754
+ }
755
+
728
756
static VALUE
729
757
pycall_libpython_helpers_m_getattr (int argc , VALUE * argv , VALUE mod )
730
758
{
731
759
VALUE pyptr , name , default_value ;
732
- PyObject * pyobj , * res ;
733
760
734
761
if (rb_scan_args (argc , argv , "21" , & pyptr , & name , & default_value ) == 2 ) {
735
762
default_value = Qundef ;
@@ -739,18 +766,11 @@ pycall_libpython_helpers_m_getattr(int argc, VALUE *argv, VALUE mod)
739
766
rb_raise (rb_eTypeError , "PyCall::PyPtr is required" );
740
767
}
741
768
742
- pyobj = get_pyobj_ptr (pyptr );
743
-
744
769
if (RB_TYPE_P (name , T_SYMBOL )) {
745
770
name = rb_sym_to_s (name );
746
771
}
747
772
748
- res = Py_API (PyObject_GetAttrString )(pyobj , StringValueCStr (name ));
749
- if (!res && default_value == Qundef ) {
750
- pycall_pyerror_fetch_and_raise ("PyObject_GetAttrString in pycall_libpython_helpers_m_getattr" );
751
- }
752
- Py_API (PyErr_Clear )();
753
- return res ? pycall_pyobject_to_ruby (res ) : default_value ;
773
+ return pycall_getattr_default (pyptr , StringValueCStr (name ), default_value );
754
774
}
755
775
756
776
static VALUE
0 commit comments