diff --git a/docs/index.md b/docs/index.md index 46f5b4b..12abc6c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -58,6 +58,33 @@ build-backend = "setuptools.build_meta" PyAwaitable needs to be installed as both a runtime dependency and build time dependency. +## Vendored Copies + +PyAwaitable ships a vendorable version of each release, containing both a `pyawaitable.c` and `pyawaitable.h` file. For many user, it's much easier to vendor PyAwaitable than use it off PyPI. + +Initialization is slightly different on a vendored version - instead of using `pyawaitable_init`, you are to use `pyawaitable_vendor_init`, which takes a module object. For example: + +```c +#include "pyawaitable.h" +/* ... */ + +PyMODINIT_FUNC +PyInit_foo(void) +{ + PyObject *m = PyModule_Create(/* ... */); + if (!m) + return NULL; + + if (pyawaitable_init_vendor(m) < 0) + { + Py_DECREF(m); + return NULL; + } + + return m; +} +``` + ## Acknowledgements Special thanks to: diff --git a/include/vendor.h b/include/vendor.h index f494897..a728e0f 100644 --- a/include/vendor.h +++ b/include/vendor.h @@ -10,18 +10,18 @@ * (If you're seeing this message from a vendored copy, you're fine) */ -#define PYAWAITABLE_ADD_TYPE(m, tp) \ - do \ - { \ - Py_INCREF(&tp); \ - if (PyType_Ready(&tp) < 0) { \ - Py_DECREF(&tp); \ - return -1; \ - } \ - if (PyModule_AddObject(m, #tp, (PyObject *)&tp) < 0) { \ - Py_DECREF(&tp); \ - return -1; \ - } \ +#define PYAWAITABLE_ADD_TYPE(m, tp) \ + do \ + { \ + Py_INCREF(&tp); \ + if (PyType_Ready(&tp) < 0) { \ + Py_DECREF(&tp); \ + return -1; \ + } \ + if (PyModule_AddObject(m, #tp, (PyObject *) &tp) < 0) { \ + Py_DECREF(&tp); \ + return -1; \ + } \ } while (0) #define PYAWAITABLE_MAJOR_VERSION 1 @@ -42,6 +42,7 @@ #define PyAwaitable_ABI pyawaitable_abi #define PyAwaitable_Type PyAwaitableType #define PyAwaitable_AwaitFunction pyawaitable_await_function +#define PyAwaitable_VendorInit pyawaitable_vendor_init #endif static int