hnakamur commented on PR #12060:
URL: https://github.com/apache/trafficserver/pull/12060#issuecomment-2758544483

   I changed the signature of `RecGetRecordString_Xmalloc` to
   ```
   td::pair<std::string_view, RecErrT> RecGetRecordString_Xmalloc(const char 
*name, bool lock = true);
   ```
   at 
https://github.com/hnakamur/trafficserver/compare/94a72272fcfe291ad5710b44b1c3069c94c27581...eliminate_deprecated_lib_records_apis_std_string_view
   However I don't think it's good since we need a lot of `const_cast<char *>` 
to free the allocated string.
   
   So I thought it would be better to return `std::string`.
   However `std::string{nullptr, 0}` will be prohibited in C++23 
(https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2166r1.html)
   Therefore we have to use `std::optional<string>` to distinguish `nullptr` 
and an empty string.
   
   So I changed the signature of the above function to
   ```
   std::pair<std::optional<std::string>, RecErrT> RecGetRecordStringAlloc(const 
char *name, bool lock = true);
   ```
   and also rename it to RecGetRecordStringAlloc since it does not use malloc 
anymore.
   This version is at 
https://github.com/hnakamur/trafficserver/compare/94a72272fcfe291ad5710b44b1c3069c94c27581...eliminate_deprecated_lib_records_apis_std_optional_string
   
   I changed the signature for integer and float version to return std::pair 
too.
   ```
   std::pair<RecInt, RecErrT>                     RecGetRecordInt(const char 
*name, bool lock = true);
   std::pair<RecFloat, RecErrT>                   RecGetRecordFloat(const char 
*name, bool lock = true);
   RecErrT                                        RecGetRecordString(const char 
*name, char *buf, int buf_len, bool lock = true);
   std::pair<std::optional<std::string>, RecErrT> RecGetRecordStringAlloc(const 
char *name, bool lock = true);
   std::pair<RecCounter, RecErrT>                 RecGetRecordCounter(const 
char *name, bool lock = true);
   ```
   
   I also changed `RecEstablishStaticConfigXxx` to inline functions like below:
   ```
   inline RecErrT RecEstablishStaticConfigInt(RecInt &rec_int, const char 
*name, bool lock = true);
   inline RecErrT RecEstablishStaticConfigInt32(int32_t &rec_int, const char 
*name, bool lock = true);
   inline RecErrT RecEstablishStaticConfigUInt32(uint32_t &rec_int, const char 
*name, bool lock = true);
   inline RecErrT RecEstablishStaticConfigString(RecString &rec_string, const 
char *name, bool lock = true);
   inline RecErrT RecEstablishStaticConfigFloat(RecFloat &rec_float, const char 
*name, bool lock = true);
   inline RecErrT RecEstablishStaticConfigByte(RecByte &rec_byte, const char 
*name, bool lock = true);
   ```
   I also added the following utility functions:
   ```
   inline char *ats_stringdup(std::optional<std::string> const &p);
   inline const char *ats_as_c_str(std::optional<std::string> const &p);
   ```
   
   Could you give me feedback about above changes?
   I'll make a proposal on ats-dev mailing list after waiting for a few days.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to