https://github.com/archlinux/svntogit-community/blob/b103146beee8b7c70d04685033a8536aed2e5aea/trunk/002-python310.patch
https://github.com/archlinux/svntogit-community/blob/b103146beee8b7c70d04685033a8536aed2e5aea/trunk/003-pyunicode.patch

https://www.virtualbox.org/changeset/90537/vbox
https://www.virtualbox.org/changeset/86623/vbox
--- a/src/libs/xpcom18a4/python/src/module/_xpcom.cpp
+++ b/src/libs/xpcom18a4/python/src/module/_xpcom.cpp
@@ -84,7 +84,11 @@
 #  define MANGLE_MODULE_INIT(a_Name)    RT_CONCAT(a_Name, MODULE_NAME_SUFFIX)
 # endif
 # ifdef VBOX_PYXPCOM_VERSIONED
-#  if   PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
+#  if   PY_VERSION_HEX >= 0x030a0000 && PY_VERSION_HEX < 0x030b0000
+#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_10")
+#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_10)
+
+#  elif   PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_9")
 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_9)
 
--- a/src/libs/xpcom18a4/python/Makefile.kmk
+++ b/src/libs/xpcom18a4/python/Makefile.kmk
@@ -4,7 +4,7 @@
 #
 
 #
-# Copyright (C) 2009-2017 Oracle Corporation
+# Copyright (C) 2009-2021 Oracle Corporation
 #
 # This file is part of VirtualBox Open Source Edition (OSE), as
 # available from http://www.virtualbox.org. This file is free software;
@@ -20,7 +20,7 @@
 
 #
 # List of supported Python versions, defining a number of
-# VBOX_PYTHON[26|27|31|32|32M|33|33M|34|34M|35|35M|36|36M|37|37M|38|38M|39|39M|DEF]_[INC|LIB] variables
+# VBOX_PYTHON[26|27|31|32|32M|33|33M|34|34M|35|35M|36|36M|37|37M|38|38M|39|39M|310|310M|DEF]_[INC|LIB] variables
 # which get picked up below.
 #
 ifeq ($(KBUILD_TARGET),darwin) # Relatively predictable, don't script.
@@ -646,6 +646,52 @@
  endif
 endif
 
+ifdef VBOX_PYTHON310_INC
+#
+# Python 3.10 version
+#
+DLLS += VBoxPython3_10
+VBoxPython3_10_EXTENDS    = VBoxPythonBase
+VBoxPython3_10_EXTENDS_BY = appending
+VBoxPython3_10_TEMPLATE   = XPCOM
+VBoxPython3_10_INCS       = $(VBOX_PYTHON310_INC)
+VBoxPython3_10_LIBS       = $(VBOX_PYTHON310_LIB)
+
+ ifdef VBOX_WITH_32_ON_64_MAIN_API
+  ifdef VBOX_PYTHON310_LIB_X86
+DLLS += VBoxPython3_10_x86
+VBoxPython3_10_x86_EXTENDS    = VBoxPythonBase_x86
+VBoxPython3_10_x86_EXTENDS_BY = appending
+VBoxPython3_10_x86_TEMPLATE   = XPCOM
+VBoxPython3_10_x86_INCS       = $(VBOX_PYTHON310_INC)
+VBoxPython3_10_x86_LIBS       = $(VBOX_PYTHON310_LIB_X86)
+  endif
+ endif
+endif
+
+ifdef VBOX_PYTHON310M_INC
+#
+# Python 3.10 version with pymalloc
+#
+DLLS += VBoxPython3_10m
+VBoxPython3_10m_EXTENDS    = VBoxPythonBase_m
+VBoxPython3_10m_EXTENDS_BY = appending
+VBoxPython3_10m_TEMPLATE   = XPCOM
+VBoxPython3_10m_INCS       = $(VBOX_PYTHON310M_INC)
+VBoxPython3_10m_LIBS       = $(VBOX_PYTHON310M_LIB)
+
+ ifdef VBOX_WITH_32_ON_64_MAIN_API
+  ifdef VBOX_PYTHON310M_LIB_X86
+DLLS += VBoxPython3_10m_x86
+VBoxPython3_10m_x86_EXTENDS    = VBoxPythonBase_x86_m
+VBoxPython3_10m_x86_EXTENDS_BY = appending
+VBoxPython3_10m_x86_TEMPLATE_  = XPCOM
+VBoxPython3_10m_x86_INCS       = $(VBOX_PYTHON310M_INC)
+VBoxPython3_10m_x86_LIBS       = $(VBOX_PYTHON310M_LIB_X86)
+  endif
+ endif
+endif
+
 ifdef VBOX_PYTHONDEF_INC
 #
 # Python without versioning
@@ -730,4 +776,3 @@
 
 
 include $(FILE_KBUILD_SUB_FOOTER)
-

--- a/src/libs/xpcom18a4/python/src/PyXPCOM.h
+++ b/src/libs/xpcom18a4/python/src/PyXPCOM.h
@@ -137,12 +137,14 @@
 #  define PyInt_Check(o) PyLong_Check(o)
 #  define PyInt_AsLong(o) PyLong_AsLong(o)
 #  define PyNumber_Int(o) PyNumber_Long(o)
-#  ifndef PyUnicode_AsUTF8
-#   define PyUnicode_AsUTF8(o) _PyUnicode_AsString(o)
+#  if !defined(Py_LIMITED_API) && PY_VERSION_HEX <= 0x03030000 /* 3.3 added PyUnicode_AsUTF8AndSize */
+#   ifndef PyUnicode_AsUTF8
+#    define PyUnicode_AsUTF8(o) _PyUnicode_AsString(o)
+#   endif
+#   ifndef PyUnicode_AsUTF8AndSize
+#    define PyUnicode_AsUTF8AndSize(o,s) _PyUnicode_AsStringAndSize(o,s)
+#   endif
 #  endif
-#  ifndef PyUnicode_AsUTF8AndSize
-#   define PyUnicode_AsUTF8AndSize(o,s) _PyUnicode_AsStringAndSize(o,s)
-#  endif
 typedef struct PyMethodChain
 {
     PyMethodDef *methods;

