Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions 31 Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,37 @@ typedef struct _object {
struct _typeobject *ob_type;
} PyObject;

/* Cast argument to PyObject* type. */
#define _PyObject_CAST(op) ((PyObject*)(op))

typedef struct {
PyObject ob_base;
Py_ssize_t ob_size; /* Number of items in variable part */
} PyVarObject;

/* Cast argument to PyVarObject* type. */
#define _PyVarObject_CAST(op) ((PyVarObject*)(op))
/* sizeof(*op) doesn't work on Visual Studio with void*:
sizeof(void) raises a compilation error.

sizeof(*op) is incompatible with Py_LIMITED_API which doesn't define
structures. */
#if !defined(_MSC_VER) && !defined(Py_LIMITED_API)
/* _PyObject_CAST(op): Cast argument to PyObject* type.

Raise a compilation error if the argument type is PyObject or PyObject**.

Detect for example the bug "&item" instead of "item" in:

const char *func(PyObject *item) { return Py_TYPE(&item)->tp_name; }

Note: sizeof(op) doesn't evaluate 'op', so sizeof(op) has no side effect. */
# define _PyObject_CAST(op) \
((PyObject*)(op) + Py_BUILD_ASSERT_EXPR(sizeof(*(op)) != sizeof(op)))

/* _PyVarObject_CAST(op): Cast argument to PyVarObject* type.
Similar to _PyObject_CAST(). */
# define _PyVarObject_CAST(op) \
((PyVarObject*)(op) + Py_BUILD_ASSERT_EXPR(sizeof(*(op)) != sizeof(op)))
#else
# define _PyObject_CAST(op) ((PyObject*)(op))
# define _PyVarObject_CAST(op) ((PyVarObject*)(op))
#endif /* defined(_MSC_VER) */

#define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt)
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
Expand Down
9 changes: 3 additions & 6 deletions 9 Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5983,12 +5983,9 @@ PyInit__ssl(void)
PyModule_AddIntConstant(m, "PROTO_TLSv1_2", PY_PROTO_TLSv1_2);
PyModule_AddIntConstant(m, "PROTO_TLSv1_3", PY_PROTO_TLSv1_3);

#define addbool(m, key, value) \
do { \
PyObject *bool_obj = (value) ? Py_True : Py_False; \
Py_INCREF(bool_obj); \
PyModule_AddObject((m), (key), bool_obj); \
} while (0)
#define addbool(m, v, b) \
Py_INCREF((b) ? Py_True : Py_False); \
PyModule_AddObject((m), (v), (b) ? Py_True : Py_False);

#if HAVE_SNI
addbool(m, "HAS_SNI", 1);
Expand Down
3 changes: 1 addition & 2 deletions 3 Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
to avoid violating the invariants of the list
of weakrefs for ob. */
Py_DECREF(result);
result = proxy;
Py_INCREF(result);
Py_INCREF(result = proxy);
goto skip_insert;
}
prev = ref;
Expand Down
1 change: 1 addition & 0 deletions 1 Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Thread and interpreter state structures and their interfaces */

#include "Python.h"
#include "frameobject.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.