This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: C99 _Bool support for struct
Type: Stage:
Components: Extension Modules Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: chmod007, loewis, theller
Priority: normal Keywords: patch

Created on 2006-12-07 05:37 by chmod007, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bool struct patch.diff chmod007, 2006-12-07 05:37 patch relative to http://svn.python.org/projects/python/trunk rev 52945
bool struct patch-2.diff chmod007, 2006-12-08 07:13 new patch without ctypes content -- otherwise identical
Messages (4)
msg51488 - (view) Author: David Remahl (chmod007) Date: 2006-12-07 05:37
C99 adds the fundamental _Bool integer type (fundamental in the sense that it is not equivalent to or a composite of any other C type). Its size can vary from platform to platform; the only restriction imposed by the C standard is that it must be able to hold the values 0 or 1. Typically, sizeof _Bool is 1 or 4.

A struct module user trying to parse a native C structure that contains a _Bool member faces a problem: struct does not have a format character for _Bool. One is forced to hardcode a size for bool (use a char or an int instead).

This patch adds support for a new format character, 't', representing the fundamental type _Bool. It is handled sementically as representing pure booleans -- when packing a structure the truth value of the argument to be packed is used and when unpacking either True or False is always returned.

For platforms that don't support _Bool, as well as in non-native mode, 't' packs as a single byte.

Test cases are included, as well as a small change to the struct documentation. The patch modifies configure.in to check for _Bool support, and the patch includes the autogenerated configure and pyconfig.h.in files as well.

I have tested the module on Mac OS X x86 (uses 1 byte for _Bool) and Mac OS X ppc (uses 4 bytes for _Bool). Ran regression suite.
msg51489 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-12-07 20:09
The patch is not complete or not correct.

Either:

- the part of that patch that changes Modules/_ctypes/_ctypes.c should be omitted because
  it does not contain a ctypes _Bool type

- or complete support for a ctypes _Bool type (how would that be called? ctypes.c99_bool?)
  should be added, together with tests in Lib/ctypes/test
msg51490 - (view) Author: David Remahl (chmod007) Date: 2006-12-08 07:13
Oops!

I didn't intend for there to be any ctypes content in this patch (as indicated by the subject), but apparently I forgot to remove part of the ctypes section. I have uploaded a new patch without that part.

Once this has been integrated, I'll upload a complete ctypes patch for consideration.
File Added: bool struct patch-2.diff
msg51491 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-01-21 09:33
Thanks for the patch. Committed as r53508
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44312
2006-12-07 05:37:42chmod007create