bpo-40170: PyObject_GET_WEAKREFS_LISTPTR() becomes a function (GH-19377)

Convert the PyObject_GET_WEAKREFS_LISTPTR() macro to a function to
hide implementation details: the macro accessed directly to the
PyTypeObject.tp_weaklistoffset member.

Add _PyObject_GET_WEAKREFS_LISTPTR() static inline function to the
internal C API.
diff --git a/Include/cpython/objimpl.h b/Include/cpython/objimpl.h
index 8e3c964..2f802e9 100644
--- a/Include/cpython/objimpl.h
+++ b/Include/cpython/objimpl.h
@@ -138,8 +138,7 @@
 /* Test if a type supports weak references */
 #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
 
-#define PyObject_GET_WEAKREFS_LISTPTR(o) \
-    ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
+PyAPI_FUNC(PyObject **) PyObject_GET_WEAKREFS_LISTPTR(PyObject *op);
 
 #ifdef __cplusplus
 }
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 10a5746..002b700 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -87,6 +87,13 @@
 extern void _Py_PrintReferenceAddresses(FILE *);
 #endif
 
+static inline PyObject **
+_PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
+{
+    Py_ssize_t offset = Py_TYPE(op)->tp_weaklistoffset;
+    return (PyObject **)((char *)op + offset);
+}
+
 #ifdef __cplusplus
 }
 #endif