Update error.h

This commit is contained in:
blueloveTH 2022-11-11 19:35:31 +08:00
parent 0e6b8ab61b
commit 1be6d72a97

View File

@ -30,6 +30,7 @@ struct SourceMetadata {
} }
SourceMetadata(const char* source, _Str filename, CompileMode mode) { SourceMetadata(const char* source, _Str filename, CompileMode mode) {
source = strdup(source);
// Skip utf8 BOM if there is any. // Skip utf8 BOM if there is any.
if (strncmp(source, "\xEF\xBB\xBF", 3) == 0) source += 3; if (strncmp(source, "\xEF\xBB\xBF", 3) == 0) source += 3;
this->filename = filename; this->filename = filename;
@ -46,6 +47,10 @@ struct SourceMetadata {
ss << " " << line << '\n'; ss << " " << line << '\n';
return ss.str(); return ss.str();
} }
~SourceMetadata(){
free((void*)source);
}
}; };
typedef std::shared_ptr<SourceMetadata> _Source; typedef std::shared_ptr<SourceMetadata> _Source;