调用PyErr_Set*
覆盖异常是否安全?根据文档,如果出现错误,则使用提供给它的message 参数PySequence_Fast
引发 a 。引发错误后调用是否安全?TypeError
const char *
PyErr_SetObject
PySequence_Fast
例子:
static PyObject * myfunc(PyObject * self, PyObject * args) {
PyObject * pyobj;
PyObject * pyseq;
PyObject * message;
if (!PyArg_ParseTuple(args, "O", &pyobj)) {
return NULL;
}
pyseq = PySequence_Fast(pyobj, "");
if (pyseq == NULL) {
message = PyString_FromFormat("argument is a '%s', not a sequence.", pyobj->ob_type->tp_name);
PyErr_SetObject(PyExc_TypeError, message);
Py_XDECREF(message);
return NULL;
}
// ...
}