Menu

#20 Py::Boolean fix / 'unsigned int' to Py:: numeric types

closed-accepted
None
6
2009-07-19
2008-04-04
No

Hello,

While trying to use Py::Boolean for the first time when it appeared in PyCXX I got to such problems:

1) acceptance of 'True' or 'False' Python types only
2) bad ref. counting if was created from another Py::Object

While fixing the problem, I have also added some convenient change to Py::Int Py::Long Py::LongLong types to be accepting 'unsigned int' for constructor/operator=. It is useful for users who usually export object ids, 32bit guids and etc. that have to convert into 'int' explicitly (this is what is done in our project all over).

Here is the change log:

+++ Py::Boolean: fixed acceptance of 'True' or 'False' Python types only, and changed to native Python boolean types support using PyObject_IsTrue() check that returns (-1) on non-boolean type. Now PyCXX supports Python similar Mapping/Sequence types testing with Py::Boolean object. Numeric types are now also supported as supposed to be, e.g. 0(FALSE) 1(TRUE), -2(FALSE) -1(TRUE).
+++ Py::Boolean: fixed crash bug on bad pointer appearing in Py::Boolean after creation from another Py::Object or assigned from it. Now it does reference counting (e.g. it is not pretending as pointer owner) that resolves situation.
+++ added native support for 'unsinged int' type for Py::Int Py::Long Py::LongLong
+++ Py::Object: new method 'isBoolean()' to test object on Python explicit boolean type, e.g. 'True' or 'False'

Patch is for rev.101

Discussion

  • Anonymous

    Anonymous - 2008-04-04

    patch for rev.101

     
  • Anonymous

    Anonymous - 2008-04-04
    • priority: 5 --> 6
    • assigned_to: nobody --> barry-scott
     
  • Barry Alan Scott

    Logged In: YES
    user_id=28665
    Originator: NO

    Unsigned conversion have been omitted for a reason, Python does not support them.
    doing long = unsigned int does not work portably as both can be the same size.
    The caller needs to deal with the problem by converting the unsigned to a suitable
    signed value.

    I'm not sure that isBoolean is useful or safe. There is already a call to find if a
    object is true/false - isTrue(). I recall seeing that False is int(0) under the covers
    and that limited some of the API choices.

    Your patch uses TABs that I do not use in the sources for the usually reasons.
    Please do not change whitespace and add () unless its required.

    I'm not clear on which parts of the bool patch is the fix and what the reason for
    the other changes are.

    Please provide a patch for just the bool issue and explain the need for the parts
    of the change.

     
  • Barry Alan Scott

    r193 contains the changes to boolean. I have not include the unsigend int changes.

     
  • Barry Alan Scott

    • status: open --> closed-accepted
     

Log in to post a comment.