Skip to content

Avoid macros and static inline functions #18

@encukou

Description

@encukou

All functions should be exported as proper symbols, so they are usable without a C preprocessor/parser.

We expect a lot of exceptions, which should be added as alternatives to proper functions (as per #4).

Macros or static inline functions can override/shadow a function with the same name and behavior. The dance for that is:

Header file:

static inline returntype
_Py_Foo_impl(args)
{
    ...
}

PyAPI_FUNC(returntype) Py_Foo (args);

// speedup for C/C++
#define Py_Foo _Py_Foo_impl

.c file:

// at the end (after all calls to Py_Foo):
#undef Py_Foo

returntype
Py_Foo (args)
{
    return _Py_Foo_impl(args);
}

Let's have Argument Clinic generate the boilerplate?


Another exception are C-specific helper macros, like Py_VISIT or Py_MIN. IMO, the docs for these should document the internals clearly enough that people can rewrite them in other languages.
Unless they're not useful in other languages (like Py_UNREACHABLE or Py_UNUSED).

Metadata

Metadata

Assignees

No one assigned

    Labels

    guidelineTo be included in guidelines PEP

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions