fix: declare alloc_c_string before use in c++ wrapper

This commit is contained in:
Marcus Souchon
2025-06-27 16:56:47 +10:00
committed by Caelan
parent 756bdc66f7
commit c69f0cca6f

View File

@@ -31,12 +31,6 @@ static inline std::optional<std::string> to_cpp_string(const char* psz)
return psz == nullptr ? std::optional<std::string>("") : std::optional<std::string>(psz);
}
static inline char* alloc_c_string(const std::optional<std::string>& str)
{
if (!str.has_value()) { return nullptr; }
return alloc_c_string(str.value());
}
static inline char* alloc_c_string(const std::string& str)
{
char* result = new char[str.size() + 1]; // +1 for null-terminator
@@ -49,6 +43,12 @@ static inline char* alloc_c_string(const std::string& str)
return result;
}
static inline char* alloc_c_string(const std::optional<std::string>& str)
{
if (!str.has_value()) { return nullptr; }
return alloc_c_string(str.value());
}
static inline void free_c_string(char* str)
{
delete[] str;