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
9287acf8
Commit
9287acf8
authored
May 29, 2008
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ctypes NULL function pointers have a boolean False value now.
parent
a52b244c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
21 deletions
+32
-21
Lib/ctypes/test/test_pointers.py
Lib/ctypes/test/test_pointers.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+21
-21
No files found.
Lib/ctypes/test/test_pointers.py
View file @
9287acf8
...
@@ -175,5 +175,13 @@ class PointersTestCase(unittest.TestCase):
...
@@ -175,5 +175,13 @@ class PointersTestCase(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
c_void_p
,
3.14
)
# make sure floats are NOT accepted
self
.
assertRaises
(
TypeError
,
c_void_p
,
3.14
)
# make sure floats are NOT accepted
self
.
assertRaises
(
TypeError
,
c_void_p
,
object
())
# nor other objects
self
.
assertRaises
(
TypeError
,
c_void_p
,
object
())
# nor other objects
def
test_pointers_bool
(
self
):
# NULL pointers have a boolean False value, non-NULL pointers True.
self
.
failUnlessEqual
(
bool
(
POINTER
(
c_int
)()),
False
)
self
.
failUnlessEqual
(
bool
(
pointer
(
c_int
())),
True
)
self
.
failUnlessEqual
(
bool
(
CFUNCTYPE
(
None
)(
0
)),
False
)
self
.
failUnlessEqual
(
bool
(
CFUNCTYPE
(
None
)(
42
)),
True
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Misc/NEWS
View file @
9287acf8
...
@@ -63,6 +63,9 @@ Extension Modules
...
@@ -63,6 +63,9 @@ Extension Modules
Library
Library
-------
-------
- Issue #1797 (partial fix): ctypes NULL function pointers have a
False boolean value now.
- Issue #2985: Allow 64-bit integer responses (``<i8>``) in XMLRPC
- Issue #2985: Allow 64-bit integer responses (``<i8>``) in XMLRPC
transfers.
transfers.
...
...
Modules/_ctypes/_ctypes.c
View file @
9287acf8
...
@@ -3784,6 +3784,26 @@ CFuncPtr_repr(CFuncPtrObject *self)
...
@@ -3784,6 +3784,26 @@ CFuncPtr_repr(CFuncPtrObject *self)
self
);
self
);
}
}
static
int
Pointer_nonzero
(
CDataObject
*
self
)
{
return
*
(
void
**
)
self
->
b_ptr
!=
NULL
;
}
static
PyNumberMethods
Pointer_as_number
=
{
0
,
/* nb_add */
0
,
/* nb_subtract */
0
,
/* nb_multiply */
0
,
/* nb_divide */
0
,
/* nb_remainder */
0
,
/* nb_divmod */
0
,
/* nb_power */
0
,
/* nb_negative */
0
,
/* nb_positive */
0
,
/* nb_absolute */
(
inquiry
)
Pointer_nonzero
,
/* nb_nonzero */
};
PyTypeObject
CFuncPtr_Type
=
{
PyTypeObject
CFuncPtr_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.CFuncPtr"
,
"_ctypes.CFuncPtr"
,
...
@@ -3795,7 +3815,7 @@ PyTypeObject CFuncPtr_Type = {
...
@@ -3795,7 +3815,7 @@ PyTypeObject CFuncPtr_Type = {
0
,
/* tp_setattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
CFuncPtr_repr
,
/* tp_repr */
(
reprfunc
)
CFuncPtr_repr
,
/* tp_repr */
0
,
/* tp_as_number */
&
Pointer_as_number
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_hash */
...
@@ -5003,26 +5023,6 @@ static PyMappingMethods Pointer_as_mapping = {
...
@@ -5003,26 +5023,6 @@ static PyMappingMethods Pointer_as_mapping = {
Pointer_subscript
,
Pointer_subscript
,
};
};
static
int
Pointer_nonzero
(
CDataObject
*
self
)
{
return
*
(
void
**
)
self
->
b_ptr
!=
NULL
;
}
static
PyNumberMethods
Pointer_as_number
=
{
0
,
/* nb_add */
0
,
/* nb_subtract */
0
,
/* nb_multiply */
0
,
/* nb_divide */
0
,
/* nb_remainder */
0
,
/* nb_divmod */
0
,
/* nb_power */
0
,
/* nb_negative */
0
,
/* nb_positive */
0
,
/* nb_absolute */
(
inquiry
)
Pointer_nonzero
,
/* nb_nonzero */
};
PyTypeObject
Pointer_Type
=
{
PyTypeObject
Pointer_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes._Pointer"
,
"_ctypes._Pointer"
,
...
...
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