Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
39530f8c
Commit
39530f8c
authored
Mar 26, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
always check return value of PyObject_IsInstance for error
parent
8d6c62dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
19 deletions
+44
-19
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+44
-19
No files found.
Modules/_ctypes/_ctypes.c
View file @
39530f8c
...
@@ -587,7 +587,10 @@ static PyObject *
...
@@ -587,7 +587,10 @@ static PyObject *
CDataType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
CDataType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
if
(
1
==
PyObject_IsInstance
(
value
,
type
))
{
int
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -600,10 +603,14 @@ CDataType_from_param(PyObject *type, PyObject *value)
...
@@ -600,10 +603,14 @@ CDataType_from_param(PyObject *type, PyObject *value)
/* If we got a PyCArgObject, we must check if the object packed in it
/* If we got a PyCArgObject, we must check if the object packed in it
is an instance of the type's dict->proto */
is an instance of the type's dict->proto */
if
(
dict
&&
ob
if
(
dict
&&
ob
)
{
&&
PyObject_IsInstance
(
ob
,
dict
->
proto
))
{
res
=
PyObject_IsInstance
(
ob
,
dict
->
proto
);
Py_INCREF
(
value
);
if
(
res
==
-
1
)
return
value
;
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
return
value
;
}
}
}
ob_name
=
(
ob
)
?
Py_TYPE
(
ob
)
->
tp_name
:
"???"
;
ob_name
=
(
ob
)
?
Py_TYPE
(
ob
)
->
tp_name
:
"???"
;
PyErr_Format
(
PyExc_TypeError
,
PyErr_Format
(
PyExc_TypeError
,
...
@@ -953,8 +960,7 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
...
@@ -953,8 +960,7 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
Py_INCREF
(
value
);
/* _byref steals a refcount */
Py_INCREF
(
value
);
/* _byref steals a refcount */
return
_byref
(
value
);
return
_byref
(
value
);
case
-
1
:
case
-
1
:
PyErr_Clear
();
return
NULL
;
break
;
default:
default:
break
;
break
;
}
}
...
@@ -1445,6 +1451,7 @@ static PyObject *
...
@@ -1445,6 +1451,7 @@ static PyObject *
c_wchar_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
c_wchar_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
int
res
;
if
(
value
==
Py_None
)
{
if
(
value
==
Py_None
)
{
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
...
@@ -1465,7 +1472,10 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
...
@@ -1465,7 +1472,10 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
}
}
return
(
PyObject
*
)
parg
;
return
(
PyObject
*
)
parg
;
}
}
if
(
PyObject_IsInstance
(
value
,
type
))
{
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1506,6 +1516,7 @@ static PyObject *
...
@@ -1506,6 +1516,7 @@ static PyObject *
c_char_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
c_char_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
int
res
;
if
(
value
==
Py_None
)
{
if
(
value
==
Py_None
)
{
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
...
@@ -1526,7 +1537,10 @@ c_char_p_from_param(PyObject *type, PyObject *value)
...
@@ -1526,7 +1537,10 @@ c_char_p_from_param(PyObject *type, PyObject *value)
}
}
return
(
PyObject
*
)
parg
;
return
(
PyObject
*
)
parg
;
}
}
if
(
PyObject_IsInstance
(
value
,
type
))
{
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1568,6 +1582,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1568,6 +1582,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
{
{
StgDictObject
*
stgd
;
StgDictObject
*
stgd
;
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
int
res
;
/* None */
/* None */
if
(
value
==
Py_None
)
{
if
(
value
==
Py_None
)
{
...
@@ -1645,7 +1660,10 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1645,7 +1660,10 @@ c_void_p_from_param(PyObject *type, PyObject *value)
return
(
PyObject
*
)
parg
;
return
(
PyObject
*
)
parg
;
}
}
/* c_void_p instance (or subclass) */
/* c_void_p instance (or subclass) */
if
(
PyObject_IsInstance
(
value
,
type
))
{
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
/* c_void_p instances */
/* c_void_p instances */
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
...
@@ -2737,6 +2755,7 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2737,6 +2755,7 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
Py_ssize_t
size
,
char
*
ptr
)
Py_ssize_t
size
,
char
*
ptr
)
{
{
CDataObject
*
src
;
CDataObject
*
src
;
int
err
;
if
(
setfunc
)
if
(
setfunc
)
return
setfunc
(
ptr
,
value
,
size
);
return
setfunc
(
ptr
,
value
,
size
);
...
@@ -2777,7 +2796,10 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2777,7 +2796,10 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
}
}
src
=
(
CDataObject
*
)
value
;
src
=
(
CDataObject
*
)
value
;
if
(
PyObject_IsInstance
(
value
,
type
))
{
err
=
PyObject_IsInstance
(
value
,
type
);
if
(
err
==
-
1
)
return
NULL
;
if
(
err
)
{
memcpy
(
ptr
,
memcpy
(
ptr
,
src
->
b_ptr
,
src
->
b_ptr
,
size
);
size
);
...
@@ -4772,14 +4794,17 @@ Pointer_set_contents(CDataObject *self, PyObject *value, void *closure)
...
@@ -4772,14 +4794,17 @@ Pointer_set_contents(CDataObject *self, PyObject *value, void *closure)
stgdict
=
PyObject_stgdict
((
PyObject
*
)
self
);
stgdict
=
PyObject_stgdict
((
PyObject
*
)
self
);
assert
(
stgdict
);
/* Cannot be NULL fr pointer instances */
assert
(
stgdict
);
/* Cannot be NULL fr pointer instances */
assert
(
stgdict
->
proto
);
assert
(
stgdict
->
proto
);
if
(
!
CDataObject_Check
(
value
)
if
(
!
CDataObject_Check
(
value
))
{
||
0
==
PyObject_IsInstance
(
value
,
stgdict
->
proto
))
{
int
res
=
PyObject_IsInstance
(
value
,
stgdict
->
proto
);
/* XXX PyObject_IsInstance could return -1! */
if
(
res
==
-
1
)
PyErr_Format
(
PyExc_TypeError
,
return
-
1
;
"expected %s instead of %s"
,
if
(
!
res
)
{
((
PyTypeObject
*
)(
stgdict
->
proto
))
->
tp_name
,
PyErr_Format
(
PyExc_TypeError
,
Py_TYPE
(
value
)
->
tp_name
);
"expected %s instead of %s"
,
return
-
1
;
((
PyTypeObject
*
)(
stgdict
->
proto
))
->
tp_name
,
Py_TYPE
(
value
)
->
tp_name
);
return
-
1
;
}
}
}
dst
=
(
CDataObject
*
)
value
;
dst
=
(
CDataObject
*
)
value
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment