Skip to content

[BUG]: latent slots macro conflicts with Qt project #5788

@SherlockNolan

Description

@SherlockNolan

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

3.1.0(latest)

Problem description

I have engaged in a project which combines qt and python. As is known to all that some old qt projects overuse the macro slots to define qt slots. And the code in pybind11.h (line 1341 slots[next_slot++] = {Py_mod_exec, reinterpret_cast<void *>(exec_fn)};) uses the conflicted macro slots. And msvc failed to compile the code.

I suggest the author to insert #undef slots and #define slots Q_SLOTS to avoid slots_array slots; bug. Or just simply rename the variable slots like pybind_slots if you like it.

Reproducible example code

/// Initialize an array of slots based on the supplied exec slot and options.
template <typename... Options>
static slots_array init_slots(int (*exec_fn)(PyObject *), Options &&...options) noexcept {
    /* NOTE: slots_array MUST be large enough to hold all possible options.  If you add an option
    here, you MUST also increase the size of slots_array in the type alias above! */
#undef slots
    slots_array slots;
    size_t next_slot = 0;

    if (exec_fn != nullptr) {
        slots[next_slot++] = {Py_mod_exec, reinterpret_cast<void *>(exec_fn)};
    }

#ifdef Py_mod_multiple_interpreters
    slots[next_slot++] = {Py_mod_multiple_interpreters, multi_interp_slot(options...)};
#endif

    if (gil_not_used_option(options...)) {
#if defined(Py_mod_gil) && defined(Py_GIL_DISABLED)
        slots[next_slot++] = {Py_mod_gil, Py_MOD_GIL_NOT_USED};
#endif
    }

    // slots must have a zero end sentinel
    slots[next_slot++] = {0, nullptr};

    return slots;
#define slots Q_SLOTS
}

Is this a regression? Put the last known working version here if it is.

Not a regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions