This is an archive of the discontinued LLVM Phabricator instance.

Wrap edit line configuration calls into helper functions
ClosedPublic

Authored by nealsid on Apr 25 2021, 1:25 AM.

Details

Summary

Currently we call el_set directly to configure the editor in the libedit wrapper. There are some cases in which this causes extra casting, but we pass captureless lambdas as function pointers, which should work out of the box. Since el_set takes varargs, if the cast is incorrect or if the cast is not present, it causes a run time failure rather than compile error. This change makes it so a few different types of configuration is done inside a helper function to provide type safety and eliminate that casting. I didn't do all edit line configuration because I'm not sure how important it was in other cases and it might require something more general keep up with libedit's signature. I'm open to suggestions, though.

Diff Detail

Event Timeline

nealsid requested review of this revision.Apr 25 2021, 1:25 AM
nealsid created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2021, 1:25 AM
teemperor accepted this revision.Apr 26 2021, 2:58 PM
teemperor added a subscriber: teemperor.

LGTM, thanks!

I can to land this for you, but first let's wait a bit to see if anyone else has any comments.

This revision is now accepted and ready to land.Apr 26 2021, 2:58 PM
JDevlieghere accepted this revision.Apr 26 2021, 3:23 PM

LGTM. I wonder if we would want to wrap this in a macro to get rid of the EditLineConstString duplication while keeping the type safety.

LGTM. I wonder if we would want to wrap this in a macro to get rid of the EditLineConstString duplication while keeping the type safety.

Thanks! I looked into removing the EditLineConstString, but I wasn't a fan of having two preprocessor macro expansions. Maybe it could be a template function wchar_t or char. I also tried some template specialization where the functions to call into the edit line library could be instantiated when used, but it didn't really appear to save much because all the method signatures for edit line parameters have to be manually maintained, and some of them still take varargs even after specifying the edit line op parameter., e.g.:

template<int N> void editLineCaller();

template<>
void editLineCaller<EL_ADDFN>(param1Type param1, param2Type param2) {

el_set(EL_ADFN, param1, param2);

. . .
}

Friendly ping - let me know if I misunderstood the comments or if anything else is needed! Thanks again.

Friendly ping - let me know if I misunderstood the comments or if anything else is needed! Thanks again.

Thanks for the explanation, I don't have a strong opinion on the matter and the current patch is an improvement so let's ship it.

This revision was landed with ongoing or failed builds.Apr 30 2021, 3:33 AM
This revision was automatically updated to reflect the committed changes.