#else
# include "php_config.h"
#endif
+
#include "context.h"
#include "data.h"
#include "call.h"
+#include "php_psi.h"
+
#include "php.h"
#include "zend_exceptions.h"
#else
# define PARAM_PROLOGUE(separate) Z_PARAM_PROLOGUE(1, separate)
#endif
-ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame,
+bool psi_call_frame_parse_args(struct psi_call_frame *frame,
zend_execute_data *execute_data) {
size_t i, argc = psi_plist_count(frame->impl->func->args);
zend_error_handling zeh;
rv = zend_parse_parameters_none();
zend_restore_error_handling(&zeh);
- return rv;
+ return rv == SUCCESS;
}
ZEND_PARSE_PARAMETERS_START(
}
ZEND_PARSE_PARAMETERS_END_EX(
zend_restore_error_handling(&zeh);
- return FAILURE;
+ return false;
);
/* set up defaults */
}
zend_restore_error_handling(&zeh);
- return SUCCESS;
+ return true;
}
void psi_call_frame_enter(struct psi_call_frame *frame) {
frame->rpointer = rv_sym->ptr = rv_sym->ival_ptr;
}
-ZEND_RESULT_CODE psi_call_frame_do_let(struct psi_call_frame *frame) {
+bool psi_call_frame_do_let(struct psi_call_frame *frame) {
size_t i;
struct psi_let_stmt *let;
struct psi_decl_arg *arg;
}
}
- return SUCCESS;
+ return true;
}
-ZEND_RESULT_CODE psi_call_frame_do_assert(struct psi_call_frame *frame, enum psi_assert_kind kind) {
+bool psi_call_frame_do_assert(struct psi_call_frame *frame, enum psi_assert_kind kind) {
size_t i = 0;
struct psi_assert_stmt *ass;
if (ass->kind == kind) {
if (!psi_assert_stmt_exec(ass, frame)) {
psi_assert_stmt_throw(ass);
- return FAILURE;
+ return false;
}
}
}
- return SUCCESS;
+ return true;
}
void psi_call_frame_do_call(struct psi_call_frame *frame) {
efree(auto_list);
}
-#include "php_psi.h"
-
void psi_call_frame_free(struct psi_call_frame *frame) {
zend_hash_destroy(&frame->arguments);
zend_hash_destroy(&frame->symbols);
#ifndef PSI_CALL_H
#define PSI_CALL_H
+#include <stdbool.h>
#include "Zend/zend_types.h"
#include "data.h"
struct psi_call_frame *psi_call_frame_init(struct psi_context *context, struct psi_decl *decl, struct psi_impl *impl);
-ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame, zend_execute_data *execute_data);
+bool psi_call_frame_parse_args(struct psi_call_frame *frame, zend_execute_data *execute_data);
size_t psi_call_frame_num_var_args(struct psi_call_frame *frame);
size_t psi_call_frame_num_fixed_args(struct psi_call_frame *frame);
void **psi_call_frame_get_arg_pointers(struct psi_call_frame *frame);
void *psi_call_frame_get_rpointer(struct psi_call_frame *frame);
-ZEND_RESULT_CODE psi_call_frame_do_let(struct psi_call_frame *frame);
-ZEND_RESULT_CODE psi_call_frame_do_assert(struct psi_call_frame *frame, enum psi_assert_kind kind);
+bool psi_call_frame_do_let(struct psi_call_frame *frame);
+bool psi_call_frame_do_assert(struct psi_call_frame *frame, enum psi_assert_kind kind);
void psi_call_frame_do_call(struct psi_call_frame *frame);
void psi_call_frame_do_callback(struct psi_call_frame *frame, struct psi_call_frame_callback *cb);
void psi_call_frame_do_return(struct psi_call_frame *frame, zval *return_value);
}
struct psi_context_build_worker {
+#if PSI_THREADED_PARSER
pthread_t tid;
+#endif
struct psi_parser parser;
struct psi_parser_input *input;
- char psi_file[MAXPATHLEN];
+ char psi_file[PATH_MAX];
};
static struct psi_context_build_worker *psi_context_build_worker_init(
{
struct psi_context_build_worker *w = pecalloc(1, sizeof(*w), 1);
- if (MAXPATHLEN <= slprintf(w->psi_file, MAXPATHLEN, "%s/%s", dir, file)) {
+ if (PATH_MAX <= slprintf(w->psi_file, PATH_MAX, "%s/%s", dir, file)) {
C->error(PSI_DATA(C), NULL, PSI_WARNING, "Path to PSI file too long: %s/%s",
dir, file);
pefree(w, 1);
}
}
}
+ psi_plist_free(running);
}
+ psi_plist_free(workers);
psi_context_compile(C);
}
return psi_plist_eles(*eles);
}
-/*
-void psi_context_decl_func_array_elements(struct psi_context *C,
- struct psi_decl *fn, struct psi_plist **els)
-{
- void *type;
- size_t i;
-
- if (fn->func->var->pointer_level > 1) {
- type = C->ops->typeof_decl(C, PSI_T_POINTER);
- } else {
- type = psi_context_decl_type(C, fn->func->type);
- }
-
- for (i = 0; i < fn->func->var->array_size; ++i) {
- void *copy = C->ops->copyof_type(C, type);
- *els = psi_plist_add(*els, ©);
- }
-}
-
-void *psi_context_decl_func_type(struct psi_context *C, struct psi_decl *fn)
-{
- struct psi_decl_arg *darg = fn->func;
-
- if (darg->engine.type) {
- return darg->engine.type;
- }
-
- if (darg->var->pointer_level) {
- if (!darg->var->array_size) {
- return C->ops->typeof_decl(C, PSI_T_POINTER);
- } else {
- C->ops->composite_init(C, darg);
- return darg->engine.type;
- }
- }
-
- return psi_context_decl_type(C, darg->type);
-}
-*/
-
void psi_context_compile(struct psi_context *C)
{
psi_context_consts_init(C);
EG(current_module) = NULL;
}
-ZEND_RESULT_CODE psi_context_call(struct psi_context *C, zend_execute_data *execute_data, zval *return_value, struct psi_impl *impl)
+bool psi_context_call(struct psi_context *C, zend_execute_data *execute_data, zval *return_value, struct psi_impl *impl)
{
struct psi_call_frame *frame;
frame = psi_call_frame_init(C, impl->decl, impl);
- if (SUCCESS != psi_call_frame_parse_args(frame, execute_data)) {
+ if (!psi_call_frame_parse_args(frame, execute_data)) {
psi_call_frame_free(frame);
- return FAILURE;
+ return false;
}
psi_call_frame_enter(frame);
- if (SUCCESS != psi_call_frame_do_let(frame)) {
+ if (!psi_call_frame_do_let(frame)) {
psi_call_frame_do_return(frame, return_value);
psi_call_frame_free(frame);
- return FAILURE;
+ return false;
}
- if (SUCCESS != psi_call_frame_do_assert(frame, PSI_ASSERT_PRE)) {
+ if (!psi_call_frame_do_assert(frame, PSI_ASSERT_PRE)) {
psi_call_frame_do_return(frame, return_value);
psi_call_frame_free(frame);
- return FAILURE;
+ return false;
}
if (psi_call_frame_num_var_args(frame)) {
C->ops->call(frame);
}
- if (SUCCESS != psi_call_frame_do_assert(frame, PSI_ASSERT_POST)) {
+ if (!psi_call_frame_do_assert(frame, PSI_ASSERT_POST)) {
psi_call_frame_do_return(frame, return_value);
psi_call_frame_free(frame);
- return FAILURE;
+ return false;
}
psi_call_frame_do_return(frame, return_value);
psi_call_frame_do_free(frame);
psi_call_frame_free(frame);
- return SUCCESS;
+ return true;
}
#ifndef PSI_CONTEXT_H
#define PSI_CONTEXT_H
+#include <stdbool.h>
#include "token.h"
/* zend_function_entry */
void *psi_context_decl_arg_call_type(struct psi_context *C, struct psi_decl_arg *arg);
void *psi_context_decl_arg_full_type(struct psi_context *C, struct psi_decl_arg *arg);
-ZEND_RESULT_CODE psi_context_call(struct psi_context *C, zend_execute_data *execute_data, zval *return_value, struct psi_impl *impl);
+bool psi_context_call(struct psi_context *C, zend_execute_data *execute_data, zval *return_value, struct psi_impl *impl);
void psi_context_dump(struct psi_dump *dump, struct psi_context *C);
void psi_context_dtor(struct psi_context *C);
void psi_context_free(struct psi_context **C);
#if PSI_THREADED_PARSER
# include <pthread.h>
-pthread_mutex_t psi_string_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t psi_string_mutex = PTHREAD_MUTEX_INITIALIZER;
zend_string *psi_string_init_interned(const char *buf, size_t len, int p)
{
return true;
}
+#if PSI_THREADED_PARSER
+static void psi_smart_str_printf(smart_str *ss, const char *fmt, ...)
+{
+ va_list argv;
+ char *buf;
+ int len;
+
+ va_start(argv, fmt);
+ len = vasprintf(&buf, fmt, argv);
+ va_end(argv);
+
+ if (len != -1) {
+ smart_str_appendl_ex(ss, buf, len, 1);
+ free(buf);
+ }
+}
+#else
+# define psi_smart_str_printf smart_str_append_printf
+#endif
+
static inline zend_string *macro_to_constant(struct psi_parser *parser,
zend_string *name, struct psi_validate_scope *scope)
{
smart_str str = {0};
-
size_t i = 0;
struct psi_token *tok;
-
-#if HAVE_ASPRINTF
+#if PSI_THREADED_PARSER
int persistent = 1;
-
- smart_str_appendl_ex(&str, ZEND_STRL("const psi\\"), 1);
- smart_str_append_ex(&str, name, 1);
- smart_str_appendl_ex(&str, ZEND_STRL(" = "), 1);
#else
int persistent = 0;
-
- smart_str_append_printf(&str, "const psi\\%s = ", name->val);
#endif
+
+ psi_smart_str_printf(&str, "const psi\\%s = ", name->val);
if (scope->macro->exp) {
-#if HAVE_ASPRINTF
- char *astr = NULL;
- struct psi_dump dump = {{.hn = &astr},
- .fun = (psi_dump_cb) asprintf};
-#else
struct psi_dump dump = {{.hn = &str},
- .fun = (psi_dump_cb) smart_str_append_printf};
-#endif
+ .fun = (psi_dump_cb) psi_smart_str_printf};
psi_num_exp_dump(&dump, scope->macro->exp);
-#if HAVE_ASPRINTF
- smart_str_appends_ex(&str, astr, 1);
- free(astr);
-#endif
} else while (psi_plist_get(scope->macro->tokens, i++, &tok)) {
if (tok->type == PSI_T_QUOTED_STRING) {
smart_str_appendc_ex(&str, '"', persistent);