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
8e9e4d8f
Commit
8e9e4d8f
authored
Dec 18, 2007
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
parent
52550e59
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
0 deletions
+44
-0
Lib/ctypes/test/test_delattr.py
Lib/ctypes/test/test_delattr.py
+21
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+16
-0
Modules/_ctypes/cfield.c
Modules/_ctypes/cfield.c
+5
-0
No files found.
Lib/ctypes/test/test_delattr.py
0 → 100644
View file @
8e9e4d8f
import
unittest
from
ctypes
import
*
class
X
(
Structure
):
_fields_
=
[(
"foo"
,
c_int
)]
class
TestCase
(
unittest
.
TestCase
):
def
test_simple
(
self
):
self
.
assertRaises
(
TypeError
,
delattr
,
c_int
(
42
),
"value"
)
def
test_chararray
(
self
):
self
.
assertRaises
(
TypeError
,
delattr
,
(
c_char
*
5
)(),
"value"
)
def
test_struct
(
self
):
self
.
assertRaises
(
TypeError
,
delattr
,
X
(),
"foo"
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Misc/NEWS
View file @
8e9e4d8f
...
...
@@ -49,6 +49,8 @@ Core and builtins
Library
-------
- Issue #1642: Fix segfault in ctypes when trying to delete attributes.
- os.access now returns True on Windows for any existing directory.
- Issue #1531: tarfile.py: Read fileobj from the current offset, do not
...
...
Modules/_ctypes/_ctypes.c
View file @
8e9e4d8f
...
...
@@ -791,6 +791,12 @@ CharArray_set_value(CDataObject *self, PyObject *value)
char
*
ptr
;
int
size
;
if
(
value
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"can't delete attribute"
);
return
-
1
;
}
if
(
PyUnicode_Check
(
value
))
{
value
=
PyUnicode_AsEncodedString
(
value
,
conversion_mode_encoding
,
...
...
@@ -846,6 +852,11 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
{
int
result
=
0
;
if
(
value
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"can't delete attribute"
);
return
-
1
;
}
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode_encoding
,
...
...
@@ -3969,6 +3980,11 @@ Simple_set_value(CDataObject *self, PyObject *value)
PyObject
*
result
;
StgDictObject
*
dict
=
PyObject_stgdict
((
PyObject
*
)
self
);
if
(
value
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"can't delete attribute"
);
return
-
1
;
}
assert
(
dict
);
/* Cannot be NULL for CDataObject instances */
assert
(
dict
->
setfunc
);
result
=
dict
->
setfunc
(
self
->
b_ptr
,
value
,
dict
->
size
);
...
...
Modules/_ctypes/cfield.c
View file @
8e9e4d8f
...
...
@@ -199,6 +199,11 @@ CField_set(CFieldObject *self, PyObject *inst, PyObject *value)
assert
(
CDataObject_Check
(
inst
));
dst
=
(
CDataObject
*
)
inst
;
ptr
=
dst
->
b_ptr
+
self
->
offset
;
if
(
value
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"can't delete attribute"
);
return
-
1
;
}
return
CData_set
(
inst
,
self
->
proto
,
self
->
setfunc
,
value
,
self
->
index
,
self
->
size
,
ptr
);
}
...
...
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