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
25d208bd
Commit
25d208bd
authored
Nov 24, 2006
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug #1598620: A ctypes structure cannot contain itself.
parent
a3c77677
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
3 deletions
+45
-3
Lib/ctypes/test/test_structures.py
Lib/ctypes/test/test_structures.py
+30
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_ctypes/stgdict.c
Modules/_ctypes/stgdict.c
+13
-3
No files found.
Lib/ctypes/test/test_structures.py
View file @
25d208bd
...
...
@@ -381,5 +381,35 @@ class PointerMemberTestCase(unittest.TestCase):
s
.
p
=
None
self
.
failUnlessEqual
(
s
.
x
,
12345678
)
class
TestRecursiveStructure
(
unittest
.
TestCase
):
def
test_contains_itself
(
self
):
class
Recursive
(
Structure
):
pass
try
:
Recursive
.
_fields_
=
[(
"next"
,
Recursive
)]
except
AttributeError
,
details
:
self
.
failUnless
(
"Structure or union cannot contain itself"
in
str
(
details
))
else
:
self
.
fail
(
"Structure or union cannot contain itself"
)
def
test_vice_versa
(
self
):
class
First
(
Structure
):
pass
class
Second
(
Structure
):
pass
First
.
_fields_
=
[(
"second"
,
Second
)]
try
:
Second
.
_fields_
=
[(
"first"
,
First
)]
except
AttributeError
,
details
:
self
.
failUnless
(
"_fields_ is final"
in
str
(
details
))
else
:
self
.
fail
(
"AttributeError not raised"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
View file @
25d208bd
...
...
@@ -101,6 +101,8 @@ Core and builtins
Library
-------
- Bug #1598620: A ctypes Structure cannot contain itself.
- Patch #1362975: Rework CodeContext indentation algorithm to
avoid hard-coding pixel widths.
...
...
Modules/_ctypes/stgdict.c
View file @
25d208bd
...
...
@@ -339,14 +339,14 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
stgdict
=
PyType_stgdict
(
type
);
if
(
!
stgdict
)
return
-
1
;
/* If this structure/union is already marked final we cannot assign
_fields_ anymore. */
if
(
stgdict
->
flags
&
DICTFLAG_FINAL
)
{
/* is final ? */
PyErr_SetString
(
PyExc_AttributeError
,
"_fields_ is final"
);
return
-
1
;
}
/* XXX This should probably be moved to a point when all this
stuff is sucessfully finished. */
stgdict
->
flags
|=
DICTFLAG_FINAL
;
/* set final */
if
(
stgdict
->
ffi_type_pointer
.
elements
)
PyMem_Free
(
stgdict
->
ffi_type_pointer
.
elements
);
...
...
@@ -480,5 +480,15 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
stgdict
->
size
=
size
;
stgdict
->
align
=
total_align
;
stgdict
->
length
=
len
;
/* ADD ffi_ofs? */
/* We did check that this flag was NOT set above, it must not
have been set until now. */
if
(
stgdict
->
flags
&
DICTFLAG_FINAL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
"Structure or union cannot contain itself"
);
return
-
1
;
}
stgdict
->
flags
|=
DICTFLAG_FINAL
;
return
MakeAnonFields
(
type
);
}
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