From c1a4591bfb0ad37991a4681513acd7622fa368d5 Mon Sep 17 00:00:00 2001 From: Daniel Wilton Date: Sun, 23 Mar 2025 01:01:56 +0000 Subject: [PATCH 1/2] Add UTF-8 encoding info to PyModule_AddStringConstant docs --- Doc/c-api/module.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index f7f4d37d4c721f..9681a37b6608e6 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -633,7 +633,7 @@ state: Add a string constant to *module* as *name*. This convenience function can be used from the module's initialization function. The string *value* must be - ``NULL``-terminated. + ``NULL``-terminated and UTF-8 encoded. Return ``-1`` with an exception set on error, ``0`` on success. This is a convenience function that calls From c3dbb4b0c5eeaad1067eda9bb38542ad2a3b2e78 Mon Sep 17 00:00:00 2001 From: Daniel Wilton Date: Sun, 23 Mar 2025 01:04:02 +0000 Subject: [PATCH 2/2] Add more detail to the PyModule_AddStringMacro docs --- Doc/c-api/module.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index 9681a37b6608e6..29292da2e1a78c 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -651,7 +651,13 @@ state: .. c:macro:: PyModule_AddStringMacro(module, macro) - Add a string constant to *module*. + Add a string constant to *module*. The name and the value are taken from + *macro*. For example ``PyModule_AddStrMacro(module, STRINGLIB_TYPE_NAME)`` + adds the string constant *STRINGLIB_TYPE_NAME* with the value of + *STRINGLIB_TYPE_NAME* to *module*. The string *value* must be + ``NULL``-terminated and UTF-8 encoded. + Return ``-1`` with an exception set on error, ``0`` on success. + .. c:function:: int PyModule_AddType(PyObject *module, PyTypeObject *type)