mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 21:10:19 +00:00
fix vargs
This commit is contained in:
parent
8bc4427c7c
commit
5c486d1317
@ -126,10 +126,10 @@ struct Lexer {
|
|||||||
[[nodiscard]] Error* lex_one_token(bool* eof) noexcept;
|
[[nodiscard]] Error* lex_one_token(bool* eof) noexcept;
|
||||||
|
|
||||||
/***** Error Reporter *****/
|
/***** Error Reporter *****/
|
||||||
[[nodiscard]] Error* _error(bool lexer_err, const char* type, const char* msg, va_list args, i64 userdata=0) noexcept;
|
[[nodiscard]] Error* _error(bool lexer_err, const char* type, const char* msg, va_list* args, i64 userdata=0) noexcept;
|
||||||
[[nodiscard]] Error* SyntaxError(const char* fmt, ...) noexcept;
|
[[nodiscard]] Error* SyntaxError(const char* fmt, ...) noexcept;
|
||||||
[[nodiscard]] Error* IndentationError(const char* msg) noexcept { return _error(true, "IndentationError", msg, {}); }
|
[[nodiscard]] Error* IndentationError(const char* msg) noexcept { return _error(true, "IndentationError", msg, NULL); }
|
||||||
[[nodiscard]] Error* NeedMoreLines() noexcept { return _error(true, "NeedMoreLines", "", {}, 0); }
|
[[nodiscard]] Error* NeedMoreLines() noexcept { return _error(true, "NeedMoreLines", "", NULL, 0); }
|
||||||
|
|
||||||
Lexer(VM* vm, std::shared_ptr<SourceData> src) noexcept;
|
Lexer(VM* vm, std::shared_ptr<SourceData> src) noexcept;
|
||||||
|
|
||||||
|
@ -1340,7 +1340,7 @@ Compiler::~Compiler(){
|
|||||||
Error* Compiler::SyntaxError(const char* msg, ...) noexcept{
|
Error* Compiler::SyntaxError(const char* msg, ...) noexcept{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, msg);
|
va_start(args, msg);
|
||||||
Error* e = lexer._error(false, "SyntaxError", msg, args);
|
Error* e = lexer._error(false, "SyntaxError", msg, &args);
|
||||||
e->lineno = err().line;
|
e->lineno = err().line;
|
||||||
e->cursor = err().start;
|
e->cursor = err().start;
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
@ -500,7 +500,7 @@ Error* Lexer::lex_one_token(bool* eof) noexcept{
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list args, i64 userdata) noexcept{
|
Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list* args, i64 userdata) noexcept{
|
||||||
PK_THREAD_LOCAL Error err;
|
PK_THREAD_LOCAL Error err;
|
||||||
err.type = type;
|
err.type = type;
|
||||||
err.src = src;
|
err.src = src;
|
||||||
@ -515,7 +515,11 @@ Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list
|
|||||||
err.lineno = -1;
|
err.lineno = -1;
|
||||||
err.cursor = NULL;
|
err.cursor = NULL;
|
||||||
}
|
}
|
||||||
vsnprintf(err.msg, sizeof(err.msg), msg, args);
|
if(args){
|
||||||
|
vsnprintf(err.msg, sizeof(err.msg), msg, *args);
|
||||||
|
}else{
|
||||||
|
std::strncpy(err.msg, msg, sizeof(err.msg));
|
||||||
|
}
|
||||||
err.userdata = userdata;
|
err.userdata = userdata;
|
||||||
return &err;
|
return &err;
|
||||||
}
|
}
|
||||||
@ -523,7 +527,7 @@ Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list
|
|||||||
Error* Lexer::SyntaxError(const char* fmt, ...) noexcept{
|
Error* Lexer::SyntaxError(const char* fmt, ...) noexcept{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
Error* err = _error(true, "SyntaxError", fmt, args);
|
Error* err = _error(true, "SyntaxError", fmt, &args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user