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

Add Py_ABS and Py_STRINGIFY macros #65689

Closed
vstinner opened this issue May 13, 2014 · 2 comments
Closed

Add Py_ABS and Py_STRINGIFY macros #65689

vstinner opened this issue May 13, 2014 · 2 comments

Comments

@vstinner
Copy link
Member

BPO 21490
Nosy @vstinner
Files
  • abs_stringify.patch
  • 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 2014-05-14.15:31:25.453>
    created_at = <Date 2014-05-13.07:58:41.914>
    labels = []
    title = 'Add Py_ABS and Py_STRINGIFY macros'
    updated_at = <Date 2014-05-14.15:31:25.452>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2014-05-14.15:31:25.452>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-05-14.15:31:25.453>
    closer = 'vstinner'
    components = []
    creation = <Date 2014-05-13.07:58:41.914>
    creator = 'vstinner'
    dependencies = []
    files = ['35238']
    hgrepos = []
    issue_num = 21490
    keywords = ['patch']
    message_count = 2.0
    messages = ['218409', '218548']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue21490'
    versions = ['Python 3.5']

    @vstinner
    Copy link
    Member Author

    Attached patches replaces duplicated C macros with two new shared macros: Py_ABS(x) and Py_STRINGIFY(x).

    I didn't touch PC/pyconfig.h because it uses 3 macros to stringify instead of just 2 and I don't know why:
    ---

    /* We want COMPILER to expand to a string containing _MSC_VER's *value*.
     * This is horridly tricky, because the stringization operator only works
     * on macro arguments, and doesn't evaluate macros passed *as* arguments.
     * Attempts simpler than the following appear doomed to produce "_MSC_VER"
     * literally in the string.
     */
    #define _Py_PASTE_VERSION(SUFFIX) \
    	("[MSC v." _Py_STRINGIZE(_MSC_VER) " " SUFFIX "]")
    /* e.g., this produces, after compile-time string catenation,
     * 	("[MSC v.1200 32 bit (Intel)]")
     *
     * _Py_STRINGIZE(_MSC_VER) expands to
     * _Py_STRINGIZE1((_MSC_VER)) expands to
     * _Py_STRINGIZE2(_MSC_VER) but as this call is the result of token-pasting
     *      it's scanned again for macros and so further expands to (under MSVC 6)
     * _Py_STRINGIZE2(1200) which then expands to
     * "1200"
     */
    #define _Py_STRINGIZE(X) _Py_STRINGIZE1((X))
    #define _Py_STRINGIZE1(X) _Py_STRINGIZE2 ## X
    #define _Py_STRINGIZE2(X) #X

    Maybe it's time to drop these old macros (only required for MSVC 6?) and use Py_STRINGIFY? I will try with Visual Studio 2010.

    @serhiy-storchaka serhiy-storchaka changed the title Add Py_ABS and Py_STINGIFY macros Add Py_ABS and Py_STRINGIFY macros May 13, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 14, 2014

    New changeset 849efd365ab4 by Victor Stinner in branch 'default':
    Issue bpo-21490: Add new C macros: Py_ABS() and Py_STRINGIFY()
    http://hg.python.org/cpython/rev/849efd365ab4

    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant