+ zend_error_cb(type, fn, ln, msg, argv);
+}
+
+static void psi_object_free(zend_object *o)
+{
+ psi_object *obj = PSI_OBJ(NULL, o);
+
+ if (obj->data) {
+ /* FIXME: how about registering a destructor?
+ // free(obj->data); */
+ obj->data = NULL;
+ }
+ zend_object_std_dtor(o);
+}
+
+static zend_object *psi_object_init(zend_class_entry *ce)
+{
+ psi_object *o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+
+ zend_object_std_init(&o->std, ce);
+ object_properties_init(&o->std, ce);
+ o->std.handlers = &psi_object_handlers;
+ return &o->std;
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_psi_dump, 0, 0, 0)
+ ZEND_ARG_INFO(0, stream)
+ZEND_END_ARG_INFO();
+static PHP_FUNCTION(psi_dump) {
+ php_stream *s;
+ zval *r = NULL;
+ int fd = STDOUT_FILENO;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &r)) {
+ return;
+ }
+ if (r) {
+ php_stream_from_zval(s, r);
+
+ if (SUCCESS != php_stream_cast(s, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void **)&fd, 1)) {
+ RETURN_FALSE;
+ }
+ }
+ PSI_ContextDump(&PSI_G(context), fd);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_psi_validate, 0, 0, 1)
+ ZEND_ARG_INFO(0, file)
+ZEND_END_ARG_INFO();
+static PHP_FUNCTION(psi_validate) {
+ zend_string *file;
+ PSI_Parser P;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "P", &file)) {
+ return;
+ }
+
+ if (!PSI_ParserInit(&P, file->val, psi_error_wrapper, 0)) {
+ RETURN_FALSE;
+ }
+
+ while (0 < PSI_ParserScan(&P)) {
+ PSI_ParserParse(&P, PSI_TokenAlloc(&P));
+ if (P.num == PSI_T_EOF) {
+ break;
+ }
+ }
+ PSI_ParserParse(&P, NULL);
+
+ if (0 == PSI_ContextValidateData(NULL, PSI_DATA(&P)) && !P.errors) {
+ RETVAL_TRUE;
+ } else {
+ RETVAL_FALSE;
+ }
+ PSI_ParserDtor(&P);
+}
+
+static PHP_MINIT_FUNCTION(psi)
+{
+ PSI_ContextOps *ops = NULL;
+ zend_class_entry ce = {0};
+