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 support of bytes objects in PyBytes_FromFormatV() #55041

Closed
vstinner opened this issue Jan 5, 2011 · 3 comments
Closed

Add support of bytes objects in PyBytes_FromFormatV() #55041

vstinner opened this issue Jan 5, 2011 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@vstinner
Copy link
Member

vstinner commented Jan 5, 2011

BPO 10832
Nosy @vstinner
Files
  • pybytes_fromformat_y.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 2011-05-24.23:43:47.363>
    created_at = <Date 2011-01-05.02:55:05.972>
    labels = ['interpreter-core', 'invalid']
    title = 'Add support of bytes objects in PyBytes_FromFormatV()'
    updated_at = <Date 2011-05-24.23:43:47.361>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2011-05-24.23:43:47.361>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-05-24.23:43:47.363>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2011-01-05.02:55:05.972>
    creator = 'vstinner'
    dependencies = []
    files = ['20268']
    hgrepos = []
    issue_num = 10832
    keywords = ['patch']
    message_count = 3.0
    messages = ['125398', '125401', '136811']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue10832'
    versions = ['Python 3.3']

    @vstinner
    Copy link
    Member Author

    vstinner commented Jan 5, 2011

    It would be very practical use have a format, eg. '%y', to accept bytes object in PyBytes_FromFormatV().

    Example (extracted from posixmodule.c):

            k = PyBytes_AsString(key2);
            v = PyBytes_AsString(val2);
            len = PyBytes_GET_SIZE(key2) + PyBytes_GET_SIZE(val2) + 2;
            p = PyMem_NEW(char, len);
            if (p == NULL) { PyErr_NoMemory(); ... }
            PyOS_snprintf(p, len, "%s=%s", k, v);

    With %y, it can be written:

            p = PyBytes_FromFormat("%y=%y", key2, val2);
            if (p == NULL) { PyErr_NoMemory(); ... }

    The '%y' may also accept bytearray and any object with the buffer interface (as the 'y' format of PyArg_Parse*() functions).

    @vstinner vstinner added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 5, 2011
    @vstinner
    Copy link
    Member Author

    vstinner commented Jan 5, 2011

    Patch implementing this feature. It only supports bytes.

    @vstinner
    Copy link
    Member Author

    The "%y" format is useless for the posixmodule.c example (it doesn't simplify the code), and I cannot find another usage of this feature. So let's forget it :-)

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

    No branches or pull requests

    1 participant