This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Python] Make use of PythonObject and PythonFormat in callbacks (NFC)
ClosedPublic

Authored by mib on Nov 17 2022, 5:09 PM.

Details

Summary

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.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Nov 17 2022, 5:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 5:09 PM
mib requested review of this revision.Nov 17 2022, 5:09 PM
labath accepted this revision.Nov 17 2022, 10:46 PM
labath added a subscriber: labath.

Cool. Thanks for doing that.

lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
191–194

Maybe something like:

template<typename T, char F> struct PassthroughFormat {
  static constexpr char format = F;
  static constexpr T get(T t) { return t; }
};

template<> struct PythonFormat<char *> : PassthroughFormat<char *, 's'>;
// etc.
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
1525

You need to do something with the error inside here. Log it perhaps (we have LLDB_LOG_ERROR for that)?

1558

same here (and elsewhere)

This revision is now accepted and ready to land.Nov 17 2022, 10:46 PM
mib marked 3 inline comments as done.Nov 17 2022, 11:54 PM
mib added inline comments.
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
191–194

More templates <3 !

mib updated this revision to Diff 476361.Nov 17 2022, 11:57 PM
mib marked an inline comment as done.

Implement @labath suggestions