Skip to content

Simple extension module in C sets errno=2 somewhere #129606

@sobolevn

Description

@sobolevn

Bug report

Reproduction:

// asm_builtins/mod.c
#include <Python.h>

static PyObject *
print(PyObject *self, PyObject *args)
{
    Py_RETURN_NONE;
}

PyDoc_STRVAR(print__doc__,
"print($module, /, *args)\n"
"--\n"
"\n"
"Print passed args as strings.");


static PyMethodDef module_methods[] = {
    {"print", (PyCFunction)print, METH_VARARGS, print__doc__},
    {NULL}  // sentinel
};


static struct PyModuleDef asm_builtins_spec = {
    PyModuleDef_HEAD_INIT,
    "asm_builtins",
    PyDoc_STR("Builtins re-implemented in ASM"),
    -1,
    module_methods
};


PyMODINIT_FUNC PyInit_asm_builtins(void) {
    printf("errno = %d\n", errno);  // this will print `errno=2`
    return PyModule_Create(&asm_builtins_spec);
}

I created a repro here: https://github.com/sobolevn/errno-2-repro

You can see that all actions with Python versions from 3.9 to 3.13 print the same errno on Linux (tested on macos as well - the same).

But, other than that - there are no exceptions / failures / bugs / etc. Everything works.

Is it a bug? Or am I missing something obvious?

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixestopic-C-APItype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions