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
153038ef
Commit
153038ef
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
effde12f
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 @
153038ef
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 @
153038ef
...
...
@@ -325,6 +325,8 @@ Core and builtins
Library
-------
- Issue #1642: Fix segfault in ctypes when trying to delete attributes.
- Issue #1727780: Support loading pickles of random.Random objects created
on 32-bit systems on 64-bit systems, and vice versa. As a consequence
of the change, Random pickles created by Python 2.6 cannot be loaded
...
...
Modules/_ctypes/_ctypes.c
View file @
153038ef
...
...
@@ -788,6 +788,12 @@ CharArray_set_value(CDataObject *self, PyObject *value)
char
*
ptr
;
Py_ssize_t
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
,
...
...
@@ -843,6 +849,11 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
{
Py_ssize_t
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
,
...
...
@@ -4139,6 +4150,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 @
153038ef
...
...
@@ -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