+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &string, &flags)) {
+ return;
+ }
+
+ if (!psi_parser_init(&P, psi_error_wrapper, flags)) {
+ RETURN_FALSE;
+ }
+ if (!(I = psi_parser_open_string(&P, string->val, string->len))) {
+ psi_parser_dtor(&P);
+ RETURN_FALSE;
+ }
+
+ psi_parser_parse(&P, I);
+ psi_data_ctor(&D, P.error, P.flags);
+ RETVAL_BOOL(psi_data_validate(&D, PSI_DATA(&P)) && !P.errors);
+ psi_data_dtor(&D);
+ psi_parser_dtor(&P);
+ free(I);
+}
+
+static PHP_MINIT_FUNCTION(psi)
+{
+ struct psi_context_ops *ops = NULL;
+ zend_class_entry ce = {0};
+ unsigned flags = 0;
+
+ REGISTER_INI_ENTRIES();
+
+ zend_register_long_constant(ZEND_STRL("PSI_DEBUG"), PSI_DEBUG, CONST_CS|CONST_PERSISTENT, module_number);
+ zend_register_long_constant(ZEND_STRL("PSI_SILENT"), PSI_SILENT, CONST_CS|CONST_PERSISTENT, module_number);
+
+ INIT_NS_CLASS_ENTRY(ce, "psi", "object", NULL);
+ psi_class_entry = zend_register_internal_class_ex(&ce, NULL);
+ psi_class_entry->create_object = psi_object_init;
+
+ memcpy(&psi_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ psi_object_handlers.offset = XtOffsetOf(psi_object, std);
+ psi_object_handlers.free_obj = psi_object_free;
+ psi_object_handlers.clone_obj = NULL;
+
+#ifdef HAVE_LIBJIT
+ if (!strcasecmp(PSI_G(engine), "jit")) {
+ ops = psi_libjit_ops();
+ } else
+#endif
+#ifdef HAVE_LIBFFI
+ ops = psi_libffi_ops();
+#endif
+
+ if (!ops) {
+ php_error(E_WARNING, "No PSI engine found");
+ return FAILURE;
+ }
+
+ if (psi_check_env("PSI_DEBUG")) {
+ flags |= PSI_DEBUG;
+ }
+ if (psi_check_env("PSI_SILENT")) {
+ flags |= PSI_SILENT;
+ }
+
+ PSI_G(search_path) = pemalloc(strlen(PSI_G(directory)) + strlen(psi_cpp_search) + 1 + 1, 1);
+ sprintf(PSI_G(search_path), "%s:%s", PSI_G(directory), psi_cpp_search);
+
+ PSI_G(context) = psi_context_init(NULL, ops, psi_error_wrapper, flags);
+ psi_context_build(PSI_G(context), PSI_G(directory));
+