Skip to content

Replace trivial Py_BuildValue() with direct C API call #110093

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Py_BuildValue() is a powerful tool which can be used to create complex Python structures. But in some cases it is used to create a Python objects from a C value for which a special C API exists. Since Py_BuildValue() adds some overhead (parsing the format string, copying va_list, several levels of recursive calls), it is less efficient than direct call of the corresponding C API. For example Py_BuildValue("i", x) can be replaced with PyLong_FromLong((int)x) or simply PyLong_FromLong(x), Py_BuildValue("(OO)", x, y) can be replaced with PyTuple_Pack(2, x, y).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions