Commit fafd9b4
committed
static allocation for PyModuleDef, to portably avoid leak check errors.
This PR solves the same issue as pybind#2019 (rolled back), but in a way that is
certain to be portable and will work for any leak checker.
The Python 3 documentation suggests `static` allocation for `PyModuleDef`:
* https://docs.python.org/3/c-api/module.html#initializing-c-modules
* The module definition struct, which holds all information needed to
create a module object. There is usually only one statically initialized
variable of this type for each module.
This PR changes the `PYBIND11_MODULE` macro accordingly: `static PyModuleDef mdef;`
The `pybind11::module::module` code is slightly refactored, with the idea
to make the future removal of Python 2 support straightforward.1 parent 41aa926 commit fafd9b4
2 files changed
Lines changed: 15 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
310 | 318 | | |
311 | 319 | | |
312 | 320 | | |
313 | 321 | | |
314 | 322 | | |
315 | 323 | | |
316 | | - | |
| 324 | + | |
317 | 325 | | |
318 | 326 | | |
319 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
857 | 857 | | |
858 | 858 | | |
859 | 859 | | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
| 860 | + | |
| 861 | + | |
864 | 862 | | |
865 | 863 | | |
866 | | - | |
| 864 | + | |
867 | 865 | | |
868 | 866 | | |
869 | 867 | | |
870 | 868 | | |
871 | | - | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
872 | 872 | | |
873 | 873 | | |
874 | 874 | | |
| |||
0 commit comments