aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
diff options
context:
space:
mode:
authorMed Ismail Bennani <medismail.bennani@gmail.com>2022-11-17 23:55:52 -0800
committerMed Ismail Bennani <medismail.bennani@gmail.com>2022-11-18 13:56:48 -0800
commit288843a161f71148d7028e5153038006dd87e363 (patch)
treeb1127b4e404079a0488c659084d23954e52f0c85 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
parent7c96f61aaa4c8297e5cd1b96c6985f491e5f034f (diff)
downloadllvm-288843a161f71148d7028e5153038006dd87e363.zip
llvm-288843a161f71148d7028e5153038006dd87e363.tar.gz
llvm-288843a161f71148d7028e5153038006dd87e363.tar.bz2
[lldb/Python] Make use of PythonObject and PythonFormat in callbacks (NFC)
This patch extends the template specialization of PythonFormat structs and makes use of the pre-existing PythonObject class to format arguments and pass them to the right method, before calling it. This is a preparatory patch to merge PythonFormat with SWIGPythonBridge's GetPythonValueFormatString methods. Differential Revision: https://reviews.llvm.org/D138248 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h36
1 files changed, 24 insertions, 12 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 76ad47f..365d499 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -185,22 +185,34 @@ inline const char *py2_const_cast(const char *s) { return s; }
enum class PyInitialValue { Invalid, Empty };
+// DOC: https://docs.python.org/3/c-api/arg.html#building-values
template <typename T, typename Enable = void> struct PythonFormat;
-template <> struct PythonFormat<unsigned long long> {
- static constexpr char format = 'K';
- static auto get(unsigned long long value) { return value; }
+template <typename T, char F> struct PassthroughFormat {
+ static constexpr char format = F;
+ static constexpr T get(T t) { return t; }
};
-template <> struct PythonFormat<long long> {
- static constexpr char format = 'L';
- static auto get(long long value) { return value; }
-};
-
-template <> struct PythonFormat<PyObject *> {
- static constexpr char format = 'O';
- static auto get(PyObject *value) { return value; }
-};
+template <> struct PythonFormat<char *> : PassthroughFormat<char *, 's'> {};
+template <> struct PythonFormat<char> : PassthroughFormat<char, 'b'> {};
+template <>
+struct PythonFormat<unsigned char> : PassthroughFormat<unsigned char, 'B'> {};
+template <> struct PythonFormat<short> : PassthroughFormat<short, 'h'> {};
+template <>
+struct PythonFormat<unsigned short> : PassthroughFormat<unsigned short, 'H'> {};
+template <> struct PythonFormat<int> : PassthroughFormat<int, 'i'> {};
+template <>
+struct PythonFormat<unsigned int> : PassthroughFormat<unsigned int, 'I'> {};
+template <> struct PythonFormat<long> : PassthroughFormat<long, 'l'> {};
+template <>
+struct PythonFormat<unsigned long> : PassthroughFormat<unsigned long, 'k'> {};
+template <>
+struct PythonFormat<long long> : PassthroughFormat<long long, 'L'> {};
+template <>
+struct PythonFormat<unsigned long long>
+ : PassthroughFormat<unsigned long long, 'K'> {};
+template <>
+struct PythonFormat<PyObject *> : PassthroughFormat<PyObject *, 'O'> {};
template <typename T>
struct PythonFormat<