This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Devyn Johnson
Recipients Devyn Johnson
Date 2016-01-22.13:35:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1453469734.25.0.137084363575.issue26178@psf.upfronthosting.co.za>
In-reply-to
Content
When creating Python modules via th C-API, it would be wonderful if there were an easier and more efficient way of creating an "__all__" for the module. In my opinion, an API function should be made; i.e., something like PyALL("FUNC1", "FUNC2", ...)


Currently, I use something like the below code.

"""
PyObject *create_all(void);

PyObject *create_all(void) {  // Create __all__
#define _ALLSTRING "[ssssss"
#define _ENDSTRING "]"
    return Py_BuildValue(
        _ALLSTRING
#if defined(ENV64BIT) && (defined(__x86_64__) || defined(__x86_64))
        "sss"
#ifdef __BMI2__
        "ssss"
#endif
#endif
        _ENDSTRING,
        // STRING CONVERSIONS
        "lowercasestr",
        "uppercasestr",
        // FIND AND REPLACE/REMOVE
        "strreplace",
        "strreplace_once",
        "rmgravequote",
        // ASSEMBLY-RELATED COMMANDS
#if defined(ENV64BIT) && (defined(__x86_64__) || defined(__x86_64))
        "rdtsc",
        "get_vendor_id",
        "get_cpu_stepping",
#ifdef __BMI2__
        "is_fpu_aval",
        "is_avx_aval",
        "is_fma_aval",
        "is_aes_aval",
#endif
#endif
        "nop"
    );
}

// Some code excluded

MODINIT {  // Initialize module
    PyObject *m;
    m = PyModule_Create(&module);
    PyModule_AddObject(m, "__all__", create_all());
    PyModule_AddStringConstant(m, "__author__", __author__);
    PyModule_AddStringConstant(m, "__version__", __version__);
    if (m == NULL)
        return NULL;
    return m;
}
"""
History
Date User Action Args
2016-01-22 13:35:34Devyn Johnsonsetrecipients: + Devyn Johnson
2016-01-22 13:35:34Devyn Johnsonsetmessageid: <1453469734.25.0.137084363575.issue26178@psf.upfronthosting.co.za>
2016-01-22 13:35:34Devyn Johnsonlinkissue26178 messages
2016-01-22 13:35:33Devyn Johnsoncreate