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
3c6f93b5
Commit
3c6f93b5
authored
Oct 29, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19433: test_capi: check signness of some C types
parent
62c79179
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
10 deletions
+34
-10
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+34
-10
No files found.
Modules/_testcapimodule.c
View file @
3c6f93b5
...
@@ -67,38 +67,62 @@ test_config(PyObject *self)
...
@@ -67,38 +67,62 @@ test_config(PyObject *self)
static
PyObject
*
static
PyObject
*
test_sizeof_c_types
(
PyObject
*
self
)
test_sizeof_c_types
(
PyObject
*
self
)
{
{
#define CHECK_SIZEOF(
EXPECTED, TYPE
) \
#define CHECK_SIZEOF(
TYPE, EXPECTED
) \
if (EXPECTED != sizeof(TYPE)) { \
if (EXPECTED != sizeof(TYPE)) { \
PyErr_Format(TestError, \
PyErr_Format(TestError, \
"sizeof(%s) = %u instead of %u", \
"sizeof(%s) = %u instead of %u", \
#TYPE, sizeof(TYPE), EXPECTED); \
#TYPE, sizeof(TYPE), EXPECTED); \
return (PyObject*)NULL; \
return (PyObject*)NULL; \
}
}
#define IS_SIGNED(TYPE) (((TYPE)-1) < (TYPE)0)
#define CHECK_SIGNNESS(TYPE, SIGNED) \
if (IS_SIGNED(TYPE) != SIGNED) { \
PyErr_Format(TestError, \
"%s signness is, instead of %i", \
#TYPE, IS_SIGNED(TYPE), SIGNED); \
return (PyObject*)NULL; \
}
/* integer types */
/* integer types */
CHECK_SIZEOF
(
1
,
Py_UCS1
);
CHECK_SIZEOF
(
Py_UCS1
,
1
);
CHECK_SIZEOF
(
2
,
Py_UCS2
);
CHECK_SIZEOF
(
Py_UCS2
,
2
);
CHECK_SIZEOF
(
4
,
Py_UCS4
);
CHECK_SIZEOF
(
Py_UCS4
,
4
);
CHECK_SIGNNESS
(
Py_UCS1
,
0
);
CHECK_SIGNNESS
(
Py_UCS2
,
0
);
CHECK_SIGNNESS
(
Py_UCS4
,
0
);
#ifdef HAVE_INT32_T
#ifdef HAVE_INT32_T
CHECK_SIZEOF
(
4
,
PY_INT32_T
);
CHECK_SIZEOF
(
PY_INT32_T
,
4
);
CHECK_SIGNNESS
(
PY_INT32_T
,
1
);
#endif
#endif
#ifdef HAVE_UINT32_T
#ifdef HAVE_UINT32_T
CHECK_SIZEOF
(
4
,
PY_UINT32_T
);
CHECK_SIZEOF
(
PY_UINT32_T
,
4
);
CHECK_SIGNNESS
(
PY_UINT32_T
,
0
);
#endif
#endif
#ifdef HAVE_INT64_T
#ifdef HAVE_INT64_T
CHECK_SIZEOF
(
8
,
PY_INT64_T
);
CHECK_SIZEOF
(
PY_INT64_T
,
8
);
CHECK_SIGNNESS
(
PY_INT64_T
,
1
);
#endif
#endif
#ifdef HAVE_UINT64_T
#ifdef HAVE_UINT64_T
CHECK_SIZEOF
(
8
,
PY_UINT64_T
);
CHECK_SIZEOF
(
PY_UINT64_T
,
8
);
CHECK_SIGNNESS
(
PY_UINT64_T
,
0
);
#endif
#endif
/* pointer/size types */
/* pointer/size types */
CHECK_SIZEOF
(
sizeof
(
void
*
),
size_t
);
CHECK_SIZEOF
(
size_t
,
sizeof
(
void
*
));
CHECK_SIZEOF
(
sizeof
(
void
*
),
Py_ssize_t
);
CHECK_SIGNNESS
(
size_t
,
0
);
CHECK_SIZEOF
(
Py_ssize_t
,
sizeof
(
void
*
));
CHECK_SIGNNESS
(
Py_ssize_t
,
1
);
CHECK_SIZEOF
(
Py_uintptr_t
,
sizeof
(
void
*
));
CHECK_SIGNNESS
(
Py_uintptr_t
,
0
);
CHECK_SIZEOF
(
Py_intptr_t
,
sizeof
(
void
*
));
CHECK_SIGNNESS
(
Py_intptr_t
,
1
);
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
#undef IS_SIGNED
#undef CHECK_SIGNESS
#undef CHECK_SIZEOF
#undef CHECK_SIZEOF
}
}
...
...
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