-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Eliminate deprecated lib records apis #12060
base: master
Are you sure you want to change the base?
Eliminate deprecated lib records apis #12060
Conversation
e6e7852
to
9c4a6e8
Compare
9c4a6e8
to
5b728d3
Compare
5b728d3
to
09744e6
Compare
Note we need to initialize val to zero since it is not modified when the config is not found.
09744e6
to
4d8bd36
Compare
[approve ci autest 2] |
Do we want to return value instead of passing in a pointer and return a std::string_view instead of a char*? |
|
RecErrT RecLinkConfigInt(const char *name, RecInt *rec_int); | |
RecErrT RecLinkConfigInt32(const char *name, int32_t *p_int32); | |
RecErrT RecLinkConfigUInt32(const char *name, uint32_t *p_uint32); | |
RecErrT RecLinkConfigFloat(const char *name, RecFloat *rec_float); | |
RecErrT RecLinkConfigCounter(const char *name, RecCounter *rec_counter); | |
RecErrT RecLinkConfigString(const char *name, RecString *rec_string); | |
RecErrT RecLinkConfigByte(const char *name, RecByte *rec_byte); |
For example, RecEstablishStaticConfigStringAlloc
calls RecLinkConfigString
.
https://github.com/hnakamur/trafficserver/blob/4d8bd3638cc0683b12773bedf0a6a27df6e109af/src/records/RecCore.cc#L915-L922
RecErrT
RecEstablishStaticConfigStringAlloc(const char *name, RecString *rec_string, bool lock)
{
if (RecLinkConfigString(name, rec_string) == REC_ERR_OKAY) {
ats_free(*rec_string);
}
return RecGetRecordStringOrNullptr_Xmalloc(name, rec_string, lock);
}
other functions can be changed to return the config value and take a pointer to RecErrT err
or bool found
As for other functions, there are few use cases which needs to know wether the config is found or not, for example:
https://github.com/hnakamur/trafficserver/blob/4d8bd3638cc0683b12773bedf0a6a27df6e109af/src/mgmt/config/FileManager.cc#L280-L281
int enabled;
bool found = RecGetRecordIntOrZero("proxy.config.body_factory.enable_customizations", &enabled) == REC_ERR_OKAY;
We can change RecGetRecordIntOrZero to return the config value and take a pointer to RecErrT instead.
RecInt RecGetRecordIntOrZero3(const char *name, RecErrT *err = nullptr, bool lock = true);
RecInt
RecGetRecordIntOrZero2(const char *name, RecErrT *err, bool lock)
{
RecData data;
RecErrT rec_err = RecGetRecord_Xmalloc(name, RECD_INT, &data, lock);
if (err) {
*err = rec_err;
}
return rec_err == REC_ERR_OKAY ? data.rec_int : 0;
}
However we need one more line after rewriting to use this version.
RecErrT rec_err;
int enabled = RecGetRecordIntOrZero2("proxy.config.body_factory.enable_customizations", &rec_err);
bool found = rec_err == REC_ERR_OKAY;
Maybe we can take a pointer to bool instead of RecErrT.
RecInt RecGetRecordIntOrZero3(const char *name, bool *found = nullptr, bool lock = true);
RecInt
RecGetRecordIntOrZero3(const char *name, bool *found, bool lock)
{
RecData data;
RecErrT rec_err = RecGetRecord_Xmalloc(name, RECD_INT, &data, lock);
if (found) {
*found = rec_err == REC_ERR_OKAY;
}
return rec_err == REC_ERR_OKAY ? data.rec_int : 0;
}
bool found;
int enabled = RecGetRecordIntOrZero2("proxy.config.body_factory.enable_customizations", &found);
I welcome other suggestions if any.
Another candidate would be returning |
Also, how about change the type of the
|
This pull request is meant to resolve Eliminate deprecated lib records APIs · Issue #4468 · apache/trafficserver