mirror of
https://github.com/python/cpython.git
synced 2025-11-20 10:57:44 +00:00
In places where a ResObj is expected for PyArg_Parse and the object passed in isn't but it does have an as_Resource method use that. This makes life a lot easier
for appearance portability (and was needed anyway).
This commit is contained in:
parent
c5d0959a22
commit
2d76c25f59
2 changed files with 53 additions and 10 deletions
|
|
@ -74,6 +74,17 @@ ResObj_Convert(v, p_itself)
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
Handle *p_itself;
|
Handle *p_itself;
|
||||||
{
|
{
|
||||||
|
if (!ResObj_Check(v))
|
||||||
|
{
|
||||||
|
PyObject *tmp;
|
||||||
|
if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) )
|
||||||
|
{
|
||||||
|
*p_itself = ((ResourceObject *)tmp)->ob_itself;
|
||||||
|
Py_DECREF(tmp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
PyErr_Clear();
|
||||||
|
}
|
||||||
if (!ResObj_Check(v))
|
if (!ResObj_Check(v))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError, "Resource required");
|
PyErr_SetString(PyExc_TypeError, "Resource required");
|
||||||
|
|
@ -1388,17 +1399,26 @@ OptResObj_Convert(v, p_itself)
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
Handle *p_itself;
|
Handle *p_itself;
|
||||||
{
|
{
|
||||||
|
PyObject *tmp;
|
||||||
|
|
||||||
if ( v == Py_None ) {
|
if ( v == Py_None ) {
|
||||||
*p_itself = NULL;
|
*p_itself = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!ResObj_Check(v))
|
if (ResObj_Check(v))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError, "Resource required");
|
*p_itself = ((ResourceObject *)v)->ob_itself;
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
*p_itself = ((ResourceObject *)v)->ob_itself;
|
/* If it isn't a resource yet see whether it is convertible */
|
||||||
return 1;
|
if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) {
|
||||||
|
*p_itself = ((ResourceObject *)tmp)->ob_itself;
|
||||||
|
Py_DECREF(tmp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
PyErr_Clear();
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Resource required");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,17 +44,26 @@ OptResObj_Convert(v, p_itself)
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
Handle *p_itself;
|
Handle *p_itself;
|
||||||
{
|
{
|
||||||
|
PyObject *tmp;
|
||||||
|
|
||||||
if ( v == Py_None ) {
|
if ( v == Py_None ) {
|
||||||
*p_itself = NULL;
|
*p_itself = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!ResObj_Check(v))
|
if (ResObj_Check(v))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError, "Resource required");
|
*p_itself = ((ResourceObject *)v)->ob_itself;
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
*p_itself = ((ResourceObject *)v)->ob_itself;
|
/* If it isn't a resource yet see whether it is convertible */
|
||||||
return 1;
|
if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) {
|
||||||
|
*p_itself = ((ResourceObject *)tmp)->ob_itself;
|
||||||
|
Py_DECREF(tmp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
PyErr_Clear();
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Resource required");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -116,6 +125,20 @@ class ResDefiniton(GlobalObjectDefinition):
|
||||||
def outputCheckNewArg(self):
|
def outputCheckNewArg(self):
|
||||||
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
||||||
|
|
||||||
|
def outputCheckConvertArg(self):
|
||||||
|
# if it isn't a resource we may be able to coerce it
|
||||||
|
Output("if (!%s_Check(v))", self.prefix)
|
||||||
|
OutLbrace()
|
||||||
|
Output("PyObject *tmp;")
|
||||||
|
Output('if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) )')
|
||||||
|
OutLbrace()
|
||||||
|
Output("*p_itself = ((ResourceObject *)tmp)->ob_itself;")
|
||||||
|
Output("Py_DECREF(tmp);")
|
||||||
|
Output("return 1;")
|
||||||
|
OutRbrace()
|
||||||
|
Output("PyErr_Clear();")
|
||||||
|
OutRbrace()
|
||||||
|
|
||||||
def outputGetattrHook(self):
|
def outputGetattrHook(self):
|
||||||
Output(getattrHookCode)
|
Output(getattrHookCode)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue