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

ctypes not converting None to Null in 64-bit system #51754

Closed
wenkats mannequin opened this issue Dec 14, 2009 · 5 comments
Closed

ctypes not converting None to Null in 64-bit system #51754

wenkats mannequin opened this issue Dec 14, 2009 · 5 comments
Assignees
Labels
topic-ctypes type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@wenkats
Copy link
Mannequin

wenkats mannequin commented Dec 14, 2009

BPO 7505
Nosy @theller, @pitrou, @briancurtin, @skrah
Files
  • test.py
  • 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 = 'https://github.com/theller'
    closed_at = <Date 2010-08-04.03:40:25.468>
    created_at = <Date 2009-12-14.17:10:40.511>
    labels = ['ctypes', 'type-crash']
    title = 'ctypes not converting None to Null in 64-bit system'
    updated_at = <Date 2010-08-04.03:40:25.468>
    user = 'https://bugs.python.org/wenkats'

    bugs.python.org fields:

    activity = <Date 2010-08-04.03:40:25.468>
    actor = 'terry.reedy'
    assignee = 'theller'
    closed = True
    closed_date = <Date 2010-08-04.03:40:25.468>
    closer = 'terry.reedy'
    components = ['ctypes']
    creation = <Date 2009-12-14.17:10:40.511>
    creator = 'wenkat_s'
    dependencies = []
    files = ['15557']
    hgrepos = []
    issue_num = 7505
    keywords = []
    message_count = 5.0
    messages = ['96385', '99127', '99134', '99162', '99286']
    nosy_count = 5.0
    nosy_names = ['theller', 'pitrou', 'brian.curtin', 'skrah', 'wenkat_s']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'test needed'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue7505'
    versions = ['Python 2.5']

    @wenkats
    Copy link
    Mannequin Author

    wenkats mannequin commented Dec 14, 2009

    The attached code is failing to convert None to Null. It is successful
    if the int* is shifted towards the beginning of argument list. The bug
    is actually in 32/64 bit pointers as the code works on a 32 bit system.

    The bug disappears if I reduce the number of arguments to less than 10.

    I created the so using the command - "gcc -shared -fPIC -o libtest.so
    libtest.c", (gcc (Debian 4.3.2-1.1) 4.3.2)

    The c file is as follows:

    libtest.c
    #include <stdint.h>
    #include <stdio.h>
    
    
    int32_t where ( int32_t a, int32_t c, int32_t d, int32_t e, int32_t f, 
    int32_t g, int32_t h, int32_t *b, int32_t i, int32_t j, int32_t k, 
    int32_t l)
    {
        printf("b = %p\n", (void *)b);
        printf("a = %d, c = %d, d = %d, e = %d, f = %d, g = %d, h = %d, i = 
    %d, j = %d, k = %d,  l = %d", a,c,d,e,f,g,h,i,j,k,l);
    return 100;
    

    } /* where() */

    Python Code:
    import ctypes

    libtest = ctypes.CDLL('./libtest.so')
    where = libtest.where
    where.restype = ctypes.c_int
    where.argtypes = [ 
                        ctypes.c_int32, ctypes.c_int32, ctypes.c_int32,          
    ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32,
                        ctypes.POINTER(ctypes.c_int32),
                        ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, 
    ctypes.c_int32,
                     ]
    
    
    a = 7
    b = None
    
    status = where(a,a,a,a,a,a,a,b,a,a,a,a)

    @wenkats wenkats mannequin assigned theller Dec 14, 2009
    @wenkats wenkats mannequin added topic-ctypes type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 14, 2009
    @briancurtin
    Copy link
    Member

    What is the output of your example? I'm not on Linux at the moment, but I'm trying to see if this is actually a crash.

    @wenkats
    Copy link
    Mannequin Author

    wenkats mannequin commented Feb 9, 2010

    The output was a valid pointer which was not null. I did not investigate further on this issue, because I had a work around i.e I used ctypes.POINTER(ctypes.c_cint)() instead of None.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 10, 2010

    It works in 64-bit mode under Mandriva Linux (gcc 4.4.1), with Python 2.6, 2.7 and 3.2.

    $ python issue7505.py 
    b = (nil)
    a = 7, c = 7, d = 7, e = 7, f = 7, g = 7, h = 7, i = 7, j = 7, k = 7,  l = 7

    I also works with a hand-compiled Python (2.6, 2.7, 3.2) under a 64-bit Ubuntu box. However, it fails with the system Python 2.5 shipped with Ubuntu. So perhaps this has to do with how Debian/Ubuntu compile their Pythons, or their libffi.

    $ python issue7505.py 
    b = 0x7f5300000000
    a = 7, c = 7, d = 7, e = 7, f = 7, g = 7, h = 7, i = 7, j = 7, k = 7,  l = 7

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Feb 12, 2010

    Confirm that 2.5 is the only troublesome version, but also when compiled from source (Ubuntu 64-bit, 2.5.5).

    @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
    topic-ctypes type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants