mirror of
https://github.com/obgm/libcoap.git
synced 2026-10-29 22:15:49 +03:00
Revert "str.h: Fix coap_make_str_const() for C++"
This reverts commit 2309691770.
As the temporary object is cleaned up, the contents pointed to
by the coap_str_const_t object are destroyed.
This commit is contained in:
1 parent
2309691770
commit
3531087bb3
1 file changed
+6
-9
+6
-9
@@ -91,16 +91,13 @@ void coap_delete_str_const(coap_str_const_t *string);
|
||||
* @param string The const byte array to convert to a coap_str_const_t *
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C++" {
|
||||
#include <utility>
|
||||
template <typename T>
|
||||
coap_str_const_t *coap_make_str_const(T cstr) {
|
||||
coap_str_const_t s;
|
||||
s.length = sizeof(cstr)-1;
|
||||
s.s = reinterpret_cast<const uint8_t *>(cstr);
|
||||
return std::move(&s);
|
||||
}
|
||||
namespace libcoap {
|
||||
struct CoAPStrConst : coap_str_const_t {
|
||||
operator coap_str_const_t *() { return this; }
|
||||
};
|
||||
}
|
||||
#define coap_make_str_const(CStr) \
|
||||
libcoap::CoAPStrConst{sizeof(CStr)-1, reinterpret_cast<const uint8_t *>(CStr)}
|
||||
#else /* __cplusplus */
|
||||
#define coap_make_str_const(string) \
|
||||
(&(coap_str_const_t){sizeof(string)-1,(const uint8_t *)(string)})
|
||||
|
||||
Reference in new issue
Block a user