ChatON:Fix partsLengths to int32_t type, instead of int

so that the size of the elements is explicit and fixed, so that
it is inturn in sync with the fixed int size specified wrt the
c-api, even with any c compilers with different idea about int.

avoid some ununsed vars, need to update compile flags later to
enable corresponding warnings.
This commit is contained in:
HanishKVC 2024-05-07 12:35:46 +05:30
parent b3a56545d6
commit 76791bad63

View file

@ -268,8 +268,8 @@ public:
return types; return types;
} }
std::vector<int> get_partslens() { std::vector<int32_t> get_partslens() {
std::vector<int> lens = {}; std::vector<int32_t> lens = {};
for(auto part: parts) { for(auto part: parts) {
lens.push_back(part.length()); lens.push_back(part.length());
} }
@ -362,7 +362,7 @@ inline bool chaton_tmpl_apply_single_ex(
const std::string &content, const std::string &content,
std::string &tagged, std::string &tagged,
std::string &types, std::string &types,
std::vector<int> &lens std::vector<int32_t> &lens
) { ) {
if (!chaton_tmpl_exists(tmpl)) { if (!chaton_tmpl_exists(tmpl)) {
return false; return false;
@ -392,7 +392,7 @@ inline size_t chaton_tmpl_apply_single(
std::string &tagged std::string &tagged
) { ) {
std::string types; std::string types;
std::vector<int> lens; std::vector<int32_t> lens;
if (!chaton_tmpl_apply_single_ex(tmpl, role, content, tagged, types, lens)) { if (!chaton_tmpl_apply_single_ex(tmpl, role, content, tagged, types, lens)) {
return -1; return -1;
} }
@ -418,8 +418,6 @@ inline size_t chat_tmpl_apply_single_capi(
const size_t destLength const size_t destLength
) { ) {
std::string tagged; std::string tagged;
std::string types;
std::vector<int> lens;
auto taggedLength = chaton_tmpl_apply_single(tmpl, role, content, tagged); auto taggedLength = chaton_tmpl_apply_single(tmpl, role, content, tagged);
if (taggedLength <= 0) { if (taggedLength <= 0) {
return taggedLength; return taggedLength;
@ -449,7 +447,7 @@ inline bool chaton_tmpl_apply_ex(
bool alertAssistantAtEnd, bool alertAssistantAtEnd,
std::string &tagged, std::string &tagged,
std::string &types, std::string &types,
std::vector<int> &lens std::vector<int32_t> &lens
) { ) {
if (!chaton_tmpl_exists(tmpl)) { if (!chaton_tmpl_exists(tmpl)) {
return false; return false;
@ -527,7 +525,7 @@ inline int32_t chaton_tmpl_apply(
std::string &tagged std::string &tagged
) { ) {
std::string types; std::string types;
std::vector<int> lens; std::vector<int32_t> lens;
if (!chaton_tmpl_apply_ex(tmpl, msgs, alertAssistantAtEnd, tagged, types, lens)) { if (!chaton_tmpl_apply_ex(tmpl, msgs, alertAssistantAtEnd, tagged, types, lens)) {
return -1; return -1;
} }
@ -578,12 +576,12 @@ inline int32_t chaton_tmpl_apply_capi(
// this additionally also returns info about the parts that make up // this additionally also returns info about the parts that make up
// the returned tagged message. // the returned tagged message.
// //
// partTypes and partLengths should be arrays that can accomodate the // partsTypes and partsLengths should be arrays that can accomodate the
// same number of elements belonging to its respective type. // same number of elements belonging to its respective type.
// Inturn the pNumParts should point to a int which specifies the // Inturn the pNumParts should point to a int which specifies the
// number of elements. // number of elements.
// If the generated tagged message has more parts than the specified // If the generated tagged message has more parts than the specified
// *pNumParts, then the logic copies partTypes and partLengths to the // *pNumParts, then the logic copies partsTypes and partsLengths to the
// specified length/NumOfParts only. Parallely it updates *pNumParts // specified length/NumOfParts only. Parallely it updates *pNumParts
// to the actual needed length (not including any terminating null char or so). // to the actual needed length (not including any terminating null char or so).
// //
@ -607,7 +605,7 @@ inline int32_t chaton_tmpl_apply_ex_capi(
} }
std::string taggedMsgs; std::string taggedMsgs;
std::string types; std::string types;
std::vector<int> lens; std::vector<int32_t> lens;
if (!chaton_tmpl_apply_ex(tmpl, vMsgs, alertAssistantAtEnd, taggedMsgs, types, lens)) { if (!chaton_tmpl_apply_ex(tmpl, vMsgs, alertAssistantAtEnd, taggedMsgs, types, lens)) {
return -1; return -1;
} }
@ -623,9 +621,7 @@ inline int32_t chaton_tmpl_apply_ex_capi(
strlcpy(partsTypes, types.c_str(), *pNumParts); strlcpy(partsTypes, types.c_str(), *pNumParts);
} }
if (partsLengths != nullptr) { if (partsLengths != nullptr) {
for(int i=0; i < *pNumParts; i++) { memcpy(partsLengths, lens.data(), (*pNumParts)*4);
partsLengths[i] = lens[i];
}
} }
} }
*pNumParts = types.length(); *pNumParts = types.length();