Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow T_BOOL in PyMemberDef definitions #44962

Closed
lillo mannequin opened this issue May 17, 2007 · 8 comments
Closed

Allow T_BOOL in PyMemberDef definitions #44962

lillo mannequin opened this issue May 17, 2007 · 8 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@lillo
Copy link
Mannequin

lillo mannequin commented May 17, 2007

BPO 1720595
Nosy @loewis, @birkenfeld, @pitrou, @tiran
Files
  • Python-2.5_T_BOOL.diff: The patch built against a plain Python 2.5 installation
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-01-21.21:24:22.475>
    created_at = <Date 2007-05-17.09:50:16.000>
    labels = ['interpreter-core', 'type-feature']
    title = 'Allow T_BOOL in PyMemberDef definitions'
    updated_at = <Date 2008-01-21.21:24:22.473>
    user = 'https://bugs.python.org/lillo'

    bugs.python.org fields:

    activity = <Date 2008-01-21.21:24:22.473>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-01-21.21:24:22.475>
    closer = 'georg.brandl'
    components = ['Interpreter Core']
    creation = <Date 2007-05-17.09:50:16.000>
    creator = 'lillo'
    dependencies = []
    files = ['7995']
    hgrepos = []
    issue_num = 1720595
    keywords = ['patch']
    message_count = 8.0
    messages = ['52637', '52638', '59795', '59807', '61362', '61413', '61448', '61450']
    nosy_count = 5.0
    nosy_names = ['loewis', 'georg.brandl', 'pitrou', 'christian.heimes', 'lillo']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1720595'
    versions = ['Python 2.6']

    @lillo
    Copy link
    Mannequin Author

    lillo mannequin commented May 17, 2007

    Hello

    The attached patch allows to use T_BOOL alongside other common types in the PyMemberDef definitions of your custom types.
    The boolean value is assumed to be held in a straight C char variable, and PyMember_SetOne() sets it to 1 or 0 depending on the result of calling PyObject_IsTrue() on the passed value object.

    Usage example:

    typedef struct ButtonObject
    {
    	PyObject_HEAD
    	char		fToggled;
    } ButtonObject;

    static PyMemberDef eb_ButtonEventMembers[] = {

    { "toggled", T_BOOL, offsetof(ButtonObject, fToggled), RO, "True if the button is currently toggled" },
    { NULL, 0, 0, 0, NULL }
    

    };

    The patch has been built against a plain Python 2.5 installation.

    @lillo lillo mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) labels May 17, 2007
    @birkenfeld
    Copy link
    Member

    I'd rather not allow any object to be assigned to the attribute, but only a bool. T_INT, for example, doesn't automatically call int() on its values too.

    @tiran
    Copy link
    Member

    tiran commented Jan 12, 2008

    allow or reject it for 2.6, Georg?

    @tiran tiran added type-feature A feature request or enhancement labels Jan 12, 2008
    @birkenfeld
    Copy link
    Member

    The question is also what C type to assume for boolean fields -- char or
    int?

    @pitrou
    Copy link
    Member

    pitrou commented Jan 20, 2008

    It seems to me that, when a boolean is to be represented, most C
    programmers would expect a char rather than an int. Also an int would
    make the object larger without any benefit.

    As for type checking, Angelo's patch already does a PyBool_Check against
    the argument. Is anything more required?

    @birkenfeld
    Copy link
    Member

    Martin - is a char struct member for T_BOOL fine with you?

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 21, 2008

    I can't see anything wrong with the feature. Of course, the patch itself
    lacks changes to the test suite.

    Ideally, there would also be changes to the documentation, but as
    PyMemberDef seems to be undocumented currently, it's unfair to ask for
    documentation with this patch. If documentation was made, it should list
    for each T_ constant what the corresponding C type should be.

    I think the cast to long (in PyBool_FromLong) is redundant.

    @loewis loewis mannequin unassigned loewis Jan 21, 2008
    @birkenfeld
    Copy link
    Member

    Okay, added tests, removed the cast and committed in r60181. If I find
    time, I'll add docs for PyMemberDef in the next few days.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants