Skip to content

Commit

Permalink
Fix linker error in some cases with STH_PythonAppVar::ID_* class fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Aug 6, 2024
1 parent 5294ffb commit 78da170
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/TIVarFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace tivars
{
const constexpr char TypeHandlers::STH_PythonAppVar::ID_CODE[];
const constexpr char TypeHandlers::STH_PythonAppVar::ID_SCRIPT[];

/*** Constructors ***/

Expand Down
13 changes: 8 additions & 5 deletions src/TypeHandlers/STH_PythonAppVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

namespace tivars::TypeHandlers
{
const constexpr char STH_PythonAppVar::ID_CODE[];
const constexpr char STH_PythonAppVar::ID_SCRIPT[];

data_t STH_PythonAppVar::makeDataFromString(const std::string& str, const options_t& options, const TIVarFile* _ctx)
{
(void)options;
Expand All @@ -32,8 +35,8 @@ namespace tivars::TypeHandlers
data_t data(2 + length);
data[0] = (uint8_t)(length & 0xFF);
data[1] = (uint8_t)((length >> 8) & 0xFF);
memcpy(&data[2], &STH_PythonAppVar::ID_CODE, sizeof(STH_PythonAppVar::ID_CODE));
memcpy(&data[2+sizeof(STH_PythonAppVar::ID_CODE)], &str[0], str.size());
memcpy(&data[2], &ID_CODE, sizeof(ID_CODE));
memcpy(&data[2+sizeof(ID_CODE)], &str[0], str.size());

return data;
}
Expand All @@ -46,7 +49,7 @@ namespace tivars::TypeHandlers
const size_t byteCount = data.size();
const size_t lengthDat = byteCount - 2;

if (byteCount < 2 + sizeof(STH_PythonAppVar::ID_CODE))
if (byteCount < 2 + sizeof(ID_CODE))
{
throw std::invalid_argument("Invalid data array. Need at least 6 bytes, got " + std::to_string(lengthDat));
}
Expand All @@ -58,8 +61,8 @@ namespace tivars::TypeHandlers
throw std::invalid_argument("Invalid data array. Expected " + std::to_string(lengthExp) + " bytes, got " + std::to_string(lengthDat));
}

if (memcmp(STH_PythonAppVar::ID_CODE, &(data[2]), strlen(STH_PythonAppVar::ID_CODE)) != 0
&& memcmp(STH_PythonAppVar::ID_SCRIPT, &(data[2]), strlen(STH_PythonAppVar::ID_SCRIPT)) != 0)
if (memcmp(ID_CODE, &(data[2]), strlen(ID_CODE)) != 0
&& memcmp(ID_SCRIPT, &(data[2]), strlen(ID_SCRIPT)) != 0)
{
throw std::invalid_argument("Invalid data array. Magic header 'PYCD' or 'PYSC' not found");
}
Expand Down
2 changes: 2 additions & 0 deletions src/TypeHandlers/TH_GenericAppVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace tivars::TypeHandlers
{
const constexpr char TypeHandlers::STH_PythonAppVar::ID_CODE[];

data_t TH_GenericAppVar::makeDataFromString(const std::string& str, const options_t& options, const TIVarFile* _ctx)
{
return STH_DataAppVar::makeDataFromString(str, options);
Expand Down

0 comments on commit 78da170

Please sign in to comment.