|
14 | 14 | http://bugs.python.org/issue8108#msg102867 ? |
15 | 15 | */ |
16 | 16 |
|
| 17 | +#ifndef Py_BUILD_CORE_BUILTIN |
| 18 | +# define Py_BUILD_CORE_MODULE 1 |
| 19 | +#endif |
| 20 | + |
17 | 21 | /* Don't warn about deprecated functions, */ |
18 | 22 | #ifndef OPENSSL_API_COMPAT |
19 | 23 | // 0x10101000L == 1.1.1, 30000 == 3.0.0 |
|
24 | 28 | #define PY_SSIZE_T_CLEAN |
25 | 29 |
|
26 | 30 | #include "Python.h" |
| 31 | +#include "pycore_weakref.h" // _PyWeakref_GET_REF() |
27 | 32 |
|
28 | 33 | /* Include symbols from _socket module */ |
29 | 34 | #include "socketmodule.h" |
@@ -379,8 +384,14 @@ typedef enum { |
379 | 384 | #define ERRSTR(x) ERRSTR1("_ssl.c", Py_STRINGIFY(__LINE__), x) |
380 | 385 |
|
381 | 386 | /* Get the socket from a PySSLSocket, if it has one */ |
382 | | -#define GET_SOCKET(obj) ((obj)->Socket ? \ |
383 | | - (PySocketSockObject *) PyWeakref_GetObject((obj)->Socket) : NULL) |
| 387 | +static inline PySocketSockObject* GET_SOCKET(PySSLSocket *obj) { |
| 388 | + if (obj->Socket) { |
| 389 | + return (PySocketSockObject *)PyWeakref_GetObject(obj->Socket); |
| 390 | + } |
| 391 | + else { |
| 392 | + return NULL; |
| 393 | + } |
| 394 | +} |
384 | 395 |
|
385 | 396 | /* If sock is NULL, use a timeout of 0 second */ |
386 | 397 | #define GET_SOCKET_TIMEOUT(sock) \ |
@@ -2177,13 +2188,14 @@ PyDoc_STRVAR(PySSL_get_server_hostname_doc, |
2177 | 2188 | static PyObject * |
2178 | 2189 | PySSL_get_owner(PySSLSocket *self, void *c) |
2179 | 2190 | { |
2180 | | - PyObject *owner; |
2181 | | - |
2182 | | - if (self->owner == NULL) |
| 2191 | + if (self->owner == NULL) { |
2183 | 2192 | Py_RETURN_NONE; |
2184 | | - |
2185 | | - owner = PyWeakref_GetObject(self->owner); |
2186 | | - return Py_NewRef(owner); |
| 2193 | + } |
| 2194 | + PyObject *owner = _PyWeakref_GET_REF(self->owner); |
| 2195 | + if (owner == NULL) { |
| 2196 | + Py_RETURN_NONE; |
| 2197 | + } |
| 2198 | + return owner; |
2187 | 2199 | } |
2188 | 2200 |
|
2189 | 2201 | static int |
@@ -4393,14 +4405,13 @@ _servername_callback(SSL *s, int *al, void *args) |
4393 | 4405 | * will be passed. If both do not exist only then the C-level object is |
4394 | 4406 | * passed. */ |
4395 | 4407 | if (ssl->owner) |
4396 | | - ssl_socket = PyWeakref_GetObject(ssl->owner); |
| 4408 | + ssl_socket = _PyWeakref_GET_REF(ssl->owner); |
4397 | 4409 | else if (ssl->Socket) |
4398 | | - ssl_socket = PyWeakref_GetObject(ssl->Socket); |
| 4410 | + ssl_socket = _PyWeakref_GET_REF(ssl->Socket); |
4399 | 4411 | else |
4400 | | - ssl_socket = (PyObject *) ssl; |
| 4412 | + ssl_socket = Py_NewRef(ssl); |
4401 | 4413 |
|
4402 | | - Py_INCREF(ssl_socket); |
4403 | | - if (ssl_socket == Py_None) |
| 4414 | + if (ssl_socket == NULL) |
4404 | 4415 | goto error; |
4405 | 4416 |
|
4406 | 4417 | if (servername == NULL) { |
|
0 commit comments