Seems there can be types which have buffer operations struct,
but no function pointers. So check also for called functions.
/* try to get buffer */
bfp = obj->ob_type->tp_as_buffer;
- if (bfp && bfp->bf_getsegcount(obj, NULL) == 1)
- return bfp->bf_getreadbuffer(obj, 0, (void**)buf_p);
+ if (bfp && bfp->bf_getsegcount && bfp->bf_getreadbuffer) {
+ if (bfp->bf_getsegcount(obj, NULL) == 1)
+ return bfp->bf_getreadbuffer(obj, 0, (void**)buf_p);
+ }
/*
* Not a string-like object, run str() or it.