[C++-sig] strange behavior with respect to numeric and Booleanoverloads

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Apr 9 19:44:44 CEST 2009


I checked in (svn rev. 52299) Troy's patch with an additional condition, e.g.:

#if PY_VERSION_HEX >= 0x02040000 && defined(BOOST_PYTHON_BOOL_INT_STRICT)

I.e. the default behavior is unchanged, but people can add -DBOOST_PYTHON_BOOL_INT_STRICT
to experiement.

When I did this in my project, it took me several hours to correct bool/int mismatches.
I also had to introduce a special trick to easily make bool arrays (mainly for unit tests),
e.g. before it was array.bool([0,1,0,1]) but now it is array.int([0,1,0,1]).as_bool().
Because if things like this, I decided it is best not to make the new behavior the default.

Ideas: Maybe we'll have a comprehensive overload solution after the summer, which will mean
the current patch and the define will be obsolete.
If not, it may be best to turn the compile-time choice into a runtime choice, similar to
the docstring options (http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/docstring_options.html).

I could do that if necessary.

Ralf



----- Original Message ----
From: troy d. straszheim <troy at resophonic.com>
To: Development of Python/C++ integration <cplusplus-sig at python.org>
Sent: Thursday, March 19, 2009 12:27:56 PM
Subject: Re: [C++-sig] strange behavior with respect to numeric and Booleanoverloads

Ralf W. Grosse-Kunstleve wrote:
> The comprehensive solution sounds like a project. Do we have someone to work on this?
> 
> I'm asking because I think Troy's proposed simple solution is better than the status quo.
> 

I'm willing to work on it.  I'd have to look at Daniel W's code to see if I want to push back on the simple solution or not... haven't done that yet.  Maybe we want to get Haoyu thinking about this in the background, as well, he might be done with py3k support before the end of the gsoc summer.

-t



More information about the Cplusplus-sig mailing list