[Patches] [ python-Patches-1610575 ] C99 _Bool support for struct

SourceForge.net noreply at sourceforge.net
Thu Dec 7 21:09:39 CET 2006

Patches item #1610575, was opened at 2006-12-07 06:37
Message generated for change (Comment added) made by theller
You can respond by visiting: 

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Modules
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: David Remahl (chmod007)
Assigned to: Nobody/Anonymous (nobody)
Summary: C99 _Bool support for struct

Initial Comment:
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.


>Comment By: Thomas Heller (theller)
Date: 2006-12-07 21:09

Logged In: YES 
Originator: NO

The patch is not complete or not correct.


- 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?
  should be added, together with tests in Lib/ctypes/test


You can respond by visiting: 

More information about the Patches mailing list