summaryrefslogtreecommitdiffstats
path: root/Modules/_ssl.h
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2021-04-17 18:06:38 (GMT)
committerGitHub <noreply@github.com>2021-04-17 18:06:38 (GMT)
commit7f1305ef9ea7234e1a5aacbea17490232e9b7dc2 (patch)
treeb9aa4b5736f61444b4ea0897cfde12a50cf58a54 /Modules/_ssl.h
parent76beadb8ff86eb2bb248bf918bfb20c4069932f4 (diff)
downloadcpython-7f1305ef9ea7234e1a5aacbea17490232e9b7dc2.zip
cpython-7f1305ef9ea7234e1a5aacbea17490232e9b7dc2.tar.gz
cpython-7f1305ef9ea7234e1a5aacbea17490232e9b7dc2.tar.bz2
bpo-42333: Port _ssl extension to multiphase initialization (PEP 489) (GH-23253)
- Introduce sslmodule_slots - Introduce sslmodulestate - Use sslmodulestate - Get rid of PyState_FindModule - Move new structs and helpers to header file - Use macros to access state - Keep a strong ref to socket type
Diffstat (limited to 'Modules/_ssl.h')
-rw-r--r--Modules/_ssl.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/Modules/_ssl.h b/Modules/_ssl.h
new file mode 100644
index 0000000..3fd517b
--- /dev/null
+++ b/Modules/_ssl.h
@@ -0,0 +1,45 @@
+#ifndef Py_SSL_H
+#define Py_SSL_H
+
+/*
+ * ssl module state
+ */
+typedef struct {
+ /* Types */
+ PyTypeObject *PySSLContext_Type;
+ PyTypeObject *PySSLSocket_Type;
+ PyTypeObject *PySSLMemoryBIO_Type;
+ PyTypeObject *PySSLSession_Type;
+ /* SSL error object */
+ PyObject *PySSLErrorObject;
+ PyObject *PySSLCertVerificationErrorObject;
+ PyObject *PySSLZeroReturnErrorObject;
+ PyObject *PySSLWantReadErrorObject;
+ PyObject *PySSLWantWriteErrorObject;
+ PyObject *PySSLSyscallErrorObject;
+ PyObject *PySSLEOFErrorObject;
+ /* Error mappings */
+ PyObject *err_codes_to_names;
+ PyObject *err_names_to_codes;
+ PyObject *lib_codes_to_names;
+ /* socket type from module CAPI */
+ PyTypeObject *Sock_Type;
+} _sslmodulestate;
+
+static struct PyModuleDef _sslmodule_def;
+
+Py_LOCAL_INLINE(_sslmodulestate*)
+get_ssl_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_sslmodulestate *)state;
+}
+
+#define get_state_type(type) \
+ (get_ssl_state(_PyType_GetModuleByDef(type, &_sslmodule_def)))
+#define get_state_ctx(c) (((PySSLContext *)(c))->state)
+#define get_state_sock(s) (((PySSLSocket *)(s))->ctx->state)
+#define get_state_mbio(b) ((_sslmodulestate *)PyType_GetModuleState(Py_TYPE(b)))
+
+#endif /* Py_SSL_H */