Mailing List Archive

why include cpython/*.h, Need this macro ? # error "this header file must not be included directly"
#ifndef Py_LIMITED_API
# define Py_CPYTHON_FILEOBJECT_H
# include "cpython/fileobject.h"
# undef Py_CPYTHON_FILEOBJECT_H
#endif

cpython/fileobject.h
```
#ifndef Py_CPYTHON_FILEOBJECT_H
# error "this header file must not be included directly"
#endif
```

why not use #ifndef #define
cpython/fileobject.h
#ifndef Py_CPYTHON_FILEOBJECT_H
#define Py_CPYTHON_FILEOBJECT_H
....
#endif /* Py_CPYTHON_FILEOBJECT_H */
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/WME3T6N3XQ6GP7GXBBRHTCH3O37IJK5K/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: why include cpython/*.h, Need this macro ? # error "this header file must not be included directly" [ In reply to ]
10.01.21 09:53, junyixie ????:
> #ifndef Py_LIMITED_API
> # define Py_CPYTHON_FILEOBJECT_H
> # include "cpython/fileobject.h"
> # undef Py_CPYTHON_FILEOBJECT_H
> #endif
>
> cpython/fileobject.h
> ```
> #ifndef Py_CPYTHON_FILEOBJECT_H
> # error "this header file must not be included directly"
> #endif
> ```
>
> why not use #ifndef #define
> cpython/fileobject.h
> #ifndef Py_CPYTHON_FILEOBJECT_H
> #define Py_CPYTHON_FILEOBJECT_H
> ....
> #endif /* Py_CPYTHON_FILEOBJECT_H */

Because it will not produce compile-time error when you include that
header files directly.

The division of these declarations on few files is a deep implementation
detail. Header file "cpython/fileobject.h" is not a part of API and we
do not want users to use them directly and then fail because in next
feature (or even bugfix) release some declarations have been moved to
other files.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/UCKJUHCR4JLSPJKKQBKSUSRTNDBNARVI/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: why include cpython/*.h, Need this macro ? # error "this header file must not be included directly" [ In reply to ]
On Sun, Jan 10, 2021 at 9:27 PM Serhiy Storchaka <storchaka@gmail.com> wrote:
> Because it will not produce compile-time error when you include that
> header files directly.
>
> The division of these declarations on few files is a deep implementation
> detail. Header file "cpython/fileobject.h" is not a part of API and we
> do not want users to use them directly and then fail because in next
> feature (or even bugfix) release some declarations have been moved to
> other files.

Yeah, the cpython/ subdirectory is the API which is excluded from the
limited C API (Py_LIMITED_API macro). But for end users, #include
"Python.h" should be enough.

#ifndef Py_CPYTHON_FILEOBJECT_H
# error "this header file must not be included directly"
#endif

This is to prevent users to include the API by mistake. Only the
parent header file must be used, like #include "fileobject.h".

Victor
--
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/5OYSITFK3ZXI5WJO6OW7YNZJCUHPJFFW/
Code of Conduct: http://python.org/psf/codeofconduct/