Improve handling of longer PV names#88
Conversation
asApp/src/save_restore.h
Outdated
| #define STRING_LEN MAX_STRING_SIZE /* EPICS max length for string PV */ | ||
| #define STATUS_STR_LEN 300 | ||
| #define PV_NAME_LEN 80 /* string containing a PV name */ | ||
| #define PV_NAME_LEN 256 /* string containing a PV name */ |
There was a problem hiding this comment.
The epics-base header file dbDefs.h has long defined a macro PVNAME_STRINGSZ with the size of the dbCommon::name member (currently 61). In fact I see one use of it in the verify.c file below.
The upstream macro isn't actually used in the generated *Record.h files but any change we make to the header would always be reflected in the dbCommon.dbd.pod file and vice versa. Using that upstream definition instead of defining your own would maintain backwards compatibility with other Base versions; if you need to add some margin then I would suggest keeping this macro and setting it from that.
There was a problem hiding this comment.
I now looked into why/when PV_NAME_LEN was changed to 80, and it happened back in 2005 in this commit: 5c4a1a4
To me it seems like there is no specific reason to change it to 80, it was probably just about making it larger than 40.
PVNAME_STRINGSZ is also the variable we patch in our epics base batch and you suggest to use that directly from the EPICS base header file? THat would probably make it even easier for us, as it would not require to patch autosave at all anymore?
Is PVNAME_STRINGSZ already available based on the current includes or would I need to add a specific new include? Should I in this case include dbDefs.h directly or is there a more generic include which will also provide the variable?
It probably would not actually make a difference in practice, but switching to PVNAME_STRINGSZ would reduce the default allowed PV length compared to the current version of autosave... not sure if that should be considered a breaking change.
There was a problem hiding this comment.
Inelegant, but avoiding a potentially breaking change is:
#define PV_NAME_LEN ((PVNAME_STRINGSZ>80) ? (PVNAME_STRINGSZ) : (80)) /* string containing a PV name */This compiles (I haven't done any further tests) which implies that PVNAME_STRINGSZ is available using the current includes.
There was a problem hiding this comment.
I used Ivans suggestion and removed the one location where it was directly used by now also using PV_NAME_LEN
There was a problem hiding this comment.
Actually, now it is broken. Removing the definition of PVNAME_STRINGSZ from verfiy.c now seems to show, that PVNAME_STRINGSZ is actually not included from EPICS base itself?
There was a problem hiding this comment.
Apologies, yes, you're quite right. Using my version of the #define without including dbDefs.h just falls through to the #define PVNAME_STRINGSZ 61 in verify.c, as you say.
There was a problem hiding this comment.
I reworked the second commit, properly inlcuded dbDefs.h and it should now use the central EPICS base definition for PV length, but for backwards compability falls back to 80, if PV length is smaller than 80
There was a problem hiding this comment.
Actually I decided to use PVNAME_SZ instead of PVNAME_STRINGSZ as in most places + 1 is being added to PV_NAME_LEN and this is the string length without the NUL terminator.
But now I am not sure if the usage is actually consistent across all other uses (which I have not changed)... Could use some help here in judging that...
save_restore.cuses 11 timesPV_NAME_LEN - 1- but it also defines
PV_NAME_LEN + 1in some definitions
There was a problem hiding this comment.
probably should add tests for that, but I don't feel confident enough to start with tests from scratch, as autosave does not seem to have tests for far...
fdbaff3 to
1ebfe8b
Compare
1ebfe8b to
0632ba7
Compare
autosave defines a
PV_NAME_LENfor the maximum allowed length of PVs. But there are various locations where the code uses other hard coded limits, which is sometimes 80 and sometimes 63.PV_NAME_LENmore consistently.Background
We are using a slightly patched version of EPICS base, which increases the PV length limit from 61 to 256. While the patch itself is very small, only changing two lines of code ( https://gitlab.kit.edu/kit/ibpt/controls/epics/distribution/epics-build-tool/-/blob/master/customizations/ibpt/patches/base/01-record-name-length.patch ), autosave is not compatible to that. We therefore use this patched version of autosave since around 2019.
At least one other institute recently also started using our EPICS base patch and were encountering the same issue with autosave, so the idea came up to submit the patch upstream. The currently used number for
PV_NAME_LENseemed to be arbitrary anyway, so we could as well define a higher number ;)