In C++ temporary object, created as part of expression, will alive for the end of full-expression. In AngelScript it is not?
In my implementation I have string in utf-16, and bytestr in utf-8, some native pseudocode:
class bytestr {
const char* data;
int_ptr get_cstr() const {
// return address of string data
return (int_ptr)data;
}
~bytestr() {
free(data);
}
};
class string {
bytestr toUtf8()const; // return converted to utf-8 bytestr
};
I creating wrapper for sqlite3, and write next:
class sqlite {
int_ptr db;
...
int exec(const string&in query) {
return sqlite3_exec(db, query.toUtf8().cstr);
}
}
In C++ temp object from query.toUtf8()
will alive for all call of sqlite3_exec
, and pointer from cstr stay valid, but in AngelScript after calling get_cstr
temp object destoyed, and sqlite3_exec
got invalid, freed pointer.
Is it bug or feature in AngelScript, and I must implicitly create temp variable?
int exec(const string&in query) {
bytestr tmp = query.toUtf8();
return sqlite3_exec(db, tmp.cstr);
}