summaryrefslogtreecommitdiff
path: root/Doc/includes/custom.c
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2018-04-07 18:14:03 +0200
committerGitHub <noreply@github.com>2018-04-07 18:14:03 +0200
commit1d80a561734b9932961c546b0897405a3bfbf3e6 (patch)
tree737793472ed6d3745d31fb56f2cb1f2b66429c69 /Doc/includes/custom.c
parentb405752dab95fa5dc65a19d94e798844d0378c61 (diff)
downloadcpython-git-1d80a561734b9932961c546b0897405a3bfbf3e6.tar.gz
bpo-33201: Modernize "Extension types" doc (GH-6337)
* bpo-33201: Modernize "Extension types" doc * Split tutorial and other topics * Some small fixes * Address some review comments * Rename noddy* to custom* and shoddy to sublist * Fix markup
Diffstat (limited to 'Doc/includes/custom.c')
-rw-r--r--Doc/includes/custom.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/Doc/includes/custom.c b/Doc/includes/custom.c
new file mode 100644
index 0000000000..fb2c7b2a43
--- /dev/null
+++ b/Doc/includes/custom.c
@@ -0,0 +1,39 @@
+#include <Python.h>
+
+typedef struct {
+ PyObject_HEAD
+ /* Type-specific fields go here. */
+} CustomObject;
+
+static PyTypeObject CustomType = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "custom.Custom",
+ .tp_doc = "Custom objects",
+ .tp_basicsize = sizeof(CustomObject),
+ .tp_itemsize = 0,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_new = PyType_GenericNew,
+};
+
+static PyModuleDef custommodule = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "custom",
+ .m_doc = "Example module that creates an extension type.",
+ .m_size = -1,
+};
+
+PyMODINIT_FUNC
+PyInit_custom(void)
+{
+ PyObject *m;
+ if (PyType_Ready(&CustomType) < 0)
+ return NULL;
+
+ m = PyModule_Create(&custommodule);
+ if (m == NULL)
+ return NULL;
+
+ Py_INCREF(&CustomType);
+ PyModule_AddObject(m, "Custom", (PyObject *) &CustomType);
+ return m;
+}