X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ferror.c;h=8abb68695ea294c3b1b35175d2fb0a080978f29b;hp=2d764bcdaed5ba035852f035809b57d9e4bf0157;hb=44bd65fe60fb83fa4c3bbb0d4c679d2b70a096df;hpb=2f5af21b263403997e154658635d6b6e6eaab453 diff --git a/src/error.c b/src/error.c index 2d764bc..8abb686 100644 --- a/src/error.c +++ b/src/error.c @@ -28,9 +28,78 @@ #else # include "php_config.h" #endif +#include "data.h" -#include -#include +/* zend_error_cb */ +#include "Zend/zend.h" +/* is executing/compiling query API */ +#include "Zend/zend_compile.h" +#include "Zend/zend_execute.h" -#include "error.h" +/* PG(), strlcpy, vslprintf */ +#include "php.h" +void psi_error_wrapper(struct psi_data *context, struct psi_token *t, int type, const char *msg, ...) +{ + va_list argv; + const char *fn = NULL; + unsigned ln = 0; + + if (context) { + if (context->flags & PSI_SILENT) { + /* context->last_error may be an argument to print */ + char error[sizeof(context->last_error)]; + + va_start(argv, msg); + vslprintf(error, sizeof(error), msg, argv); + va_end(argv); + + memcpy(context->last_error, error, + sizeof(context->last_error)); + return; + } + } + + if (t) { + fn = t->file->val; + ln = t->line; + } else if (zend_is_executing()) { + fn = zend_get_executed_filename(); + ln = zend_get_executed_lineno(); + } else if (zend_is_compiling()) { + fn = zend_get_compiled_filename()->val; + ln = zend_get_compiled_lineno(); + } else { + fn = "PSI module startup"; + } + + va_start(argv, msg); + psi_verror(type, fn, ln, msg, argv); + va_end(argv); + + va_start(argv, msg); + PSI_DEBUG_LOCK(context, + PSI_DEBUG_PRINTV(context, msg, argv); + PSI_DEBUG_PRINT(context, "\n"); + ); + va_end(argv); + + if (context) { + strlcpy(context->last_error, PG(last_error_message), + sizeof(context->last_error)); + } +} + +void psi_error(int type, const char *fn, unsigned ln, const char *msg, ...) +{ + va_list argv; + + va_start(argv, msg); + psi_verror(type, fn, ln, msg, argv); + va_end(argv); +} + +void psi_verror(int type, const char *fn, unsigned ln, const char *msg, va_list argv) +{ + zend_error_cb(type, fn, ln, msg, argv); +}