-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the documentation to multi-phase module init
- Loading branch information
Showing
6 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "hpy.h" | ||
|
||
// BEGIN | ||
HPyDef_SLOT(my_exec, HPy_mod_exec) | ||
int my_exec_impl(HPyContext *ctx, HPy mod) { | ||
|
||
// Some initialization: add types, constants, ... | ||
|
||
return 0; // success | ||
} | ||
|
||
static HPyDef *Methods[] = { | ||
&my_exec, // HPyDef_SLOT macro generated `my_exec` for us | ||
NULL, | ||
}; | ||
|
||
static HPyModuleDef mod_def = { | ||
.defines = Methods | ||
}; | ||
|
||
HPy_MODINIT(hpyinit, mod_def) | ||
// END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <Python.h> | ||
|
||
// BEGIN | ||
static struct PyModuleDef mod_def = { | ||
PyModuleDef_HEAD_INIT, | ||
.m_name = "legacyinit", | ||
.m_size = -1 | ||
}; | ||
|
||
PyMODINIT_FUNC | ||
PyInit_legacyinit(void) | ||
{ | ||
PyObject *mod = PyModule_Create(&mod_def); | ||
if (mod == NULL) return NULL; | ||
|
||
// Some initialization: add types, constants, ... | ||
|
||
return mod; | ||
} | ||
// END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters