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

_uuidmodule.c cannot build on AIX - different typedefs of uuid_t, etc.. #76580

Closed
aixtools opened this issue Dec 21, 2017 · 7 comments
Closed
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@aixtools
Copy link
Contributor

BPO 32399
Nosy @pitrou, @aixtools
PRs
  • bpo-32399: Starting with AIX6.1 there is support in libc.a for uuid (RFC4122) #4974
  • 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 2017-12-30.21:40:46.835>
    created_at = <Date 2017-12-21.18:49:07.780>
    labels = ['extension-modules', 'type-bug', '3.7']
    title = '_uuidmodule.c cannot build on AIX - different typedefs of uuid_t, etc..'
    updated_at = <Date 2017-12-30.21:40:46.834>
    user = 'https://github.com/aixtools'

    bugs.python.org fields:

    activity = <Date 2017-12-30.21:40:46.834>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-12-30.21:40:46.835>
    closer = 'pitrou'
    components = ['Extension Modules']
    creation = <Date 2017-12-21.18:49:07.780>
    creator = 'Michael.Felt'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32399
    keywords = ['patch']
    message_count = 7.0
    messages = ['308894', '308896', '308911', '308929', '308952', '308953', '309262']
    nosy_count = 2.0
    nosy_names = ['pitrou', 'Michael.Felt']
    pr_nums = ['4974']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32399'
    versions = ['Python 3.7']

    @aixtools
    Copy link
    Contributor Author

    I was hoping for something simple - as in:

    +1  #define PY_SSIZE_T_CLEAN
    +2
    +3  #include "Python.h"
    +4  #ifndef _AIX
    +5  #include <uuid/uuid.h>
    +6  #else
    +7  #include <uuid.h>
    +8  #endif
    

    However, it dies - instantly.

       11 | static PyObject *
       12 | py_uuid_generate_time_safe(void)
       13 | {
       14 | #ifdef HAVE_UUID_GENERATE_TIME_SAFE
       15 |     uuid_t out;
       16 |     int res;
       17 |
       18 |     res = uuid_generate_time_safe(out);
       19 |     return Py_BuildValue("y#i", (const char \*) out, sizeof(out), res);
       20 | #else
       21 |     uuid_t out;
       22 |     uuid_generate_time(out);
       23 |     return Py_BuildValue("y#O", (const char \*) out, sizeof(out), Py_None);
       23 +     return \_Py_BuildValue_SizeT("y#O", (const char \*) out, sizeof(out), (&_Py_NoneStruct));
    

    "/data/prj/python/git/python3-3.7.0.a3/Modules/_uuidmodule.c", line 23.48: 1506-117 (S) Operand must be a scalar type.
    24 | #endif
    25 | }
    26 |

    On a linux system I see:

    typedef unsigned char uuid_t[16];
    while on AIX the typedef is:
    /*
     * Universal Unique Identifier (UUID) types.
     */
    typedef struct _uuid_t
    {
        unsigned32          time_low;
        unsigned16          time_mid;
        unsigned16          time_hi_and_version;
        unsigned8           clock_seq_hi_and_reserved;
        unsigned8           clock_seq_low;
        byte               node[6];
    } uuid_t, *uuid_p_t;

    So, mentioning this for now - as I do not yet know the module. If someone with intimate knowledge of the current implementation is willing to help me - I'll dabble and learn - and see if we can make it work on AIX as well.

    p.s. - guessing on the "Extension Modules" label. If not the right choice, please update.

    @aixtools aixtools added 3.7 (EOL) end of life extension-modules C modules in the Modules dir labels Dec 21, 2017
    @aixtools
    Copy link
    Contributor Author

    So - KISS principle:

    This diff shows what can compile:

    diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c
    index d4bc3c7..5550705 100644
    --- a/Modules/_uuidmodule.c
    +++ b/Modules/_uuidmodule.c
    @@ -1,7 +1,11 @@
     #define PY_SSIZE_T_CLEAN
    
     #include "Python.h"
    +#ifndef _AIX
     #include <uuid/uuid.h>
    +#else
    +#include <uuid.h>
    +#endif
     static PyObject *
    @@ -16,7 +20,11 @@ py_uuid_generate_time_safe(void)
     #else
         uuid_t out;
         uuid_generate_time(out);
    +#ifndef _AIX
         return Py_BuildValue("y#O", (const char *) out, sizeof(out), Py_None);
    +#else
    +    return Py_BuildValue("y#O", (const char *) &out, sizeof(out), Py_None);
    +#endif
     #endif
     }

    However, no uuid_generate_time(). So, ends with:
    ld: 0711-317 ERROR: Undefined symbol: .uuid_generate_time

    @pitrou
    Copy link
    Member

    pitrou commented Dec 21, 2017

    Keep in mind _uuid is an optional C extension that is used to accelerate the uuid module when available. It doesn't bring any additional functionality by itself.

    @aixtools
    Copy link
    Contributor Author

    Understood.

    What I have learned.

    Although the types are quite different, they are both 16 bytes.

    Starting with AIX 6.1, libc includes uuid_create(&uuid, &status)
    which fills "uuid" with a uuid.uuid1() like result.
    After calling uuid_to_string( &uuid, &uuid_string, &status); the result:
    "13d866fa-e6f1-11e7-8017-fad18cf76204"

    Further reading of the documentation within """ and """ in Lib/uuid.py helps me realize that the AIX approach aligns with the UUID fields description:

        fields      a tuple of the six integer fields of the UUID,
                    which are also available as six individual attributes
                    and two derived attributes:
    
            time_low                the first 32 bits of the UUID
            time_mid                the next 16 bits of the UUID
            time_hi_version         the next 16 bits of the UUID
            clock_seq_hi_variant    the next 8 bits of the UUID
            clock_seq_low           the next 8 bits of the UUID
            node                    the last 48 bits of the UUID
    

    So - with this: there is also more than can be done for AIX re: https://bugs.python.org/issue28009

    More to come...

    @aixtools aixtools added the type-bug An unexpected behavior, bug, or error label Dec 22, 2017
    @aixtools
    Copy link
    Contributor Author

    As the 'basics' seem to be 'accepted', going to work on the PR so that configure.ac can prepare the right choices, rather than rely on a hard-coded _AIX determined macro.

    @pitrou
    Copy link
    Member

    pitrou commented Dec 23, 2017

    Does this approach allow test_uuid to pass for you?

    @pitrou
    Copy link
    Member

    pitrou commented Dec 30, 2017

    New changeset 0d3ccb4 by Antoine Pitrou (Michael Felt) in branch 'master':
    bpo-32399: Starting with AIX6.1 there is support in libc.a for uuid (RFC4122) (bpo-4974)
    0d3ccb4

    @pitrou pitrou closed this as completed Dec 30, 2017
    @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
    3.7 (EOL) end of life extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants