build cleanup
[m6w6/ext-psi] / src / data.h
index 1d8414f8b231b03fd0d8166c5a02d560dbe3ea66..37658cc1f1794c82c94c38aeda74745e9e45441c 100644 (file)
 #include "plist.h"
 #include "validate.h"
 
 #include "plist.h"
 #include "validate.h"
 
-#define PSI_DEBUG 0x1
-#define PSI_SILENT 0x2
-
 #include <stdarg.h>
 #include <dlfcn.h>
 
 #include <stdarg.h>
 #include <dlfcn.h>
 
+#define PSI_DEBUG 0x1
+#define PSI_SILENT 0x2
+
 #ifndef RTLD_NEXT
 # define RTLD_NEXT ((void *) -1l)
 #endif
 #ifndef RTLD_NEXT
 # define RTLD_NEXT ((void *) -1l)
 #endif
 # define RTLD_DEFAULT ((void *) 0)
 #endif
 
 # define RTLD_DEFAULT ((void *) 0)
 #endif
 
+#if PSI_THREADED_PARSER
+zend_string *psi_string_init_interned(const char *buf, size_t len, int p);
+zend_string *psi_new_interned_string(zend_string *str);
+#else
+# define psi_string_init_interned zend_string_init_interned
+# define psi_new_interned_string zend_new_interned_string
+#endif
+
 static inline void *psi_dlsym(struct psi_plist *dllist, const char *name, const char *redir)
 {
        void *dl, *sym = NULL;
 static inline void *psi_dlsym(struct psi_plist *dllist, const char *name, const char *redir)
 {
        void *dl, *sym = NULL;
@@ -80,7 +88,9 @@ again:
 } while(0)
 #define PSI_DEBUG_DUMP(ctx, dump_func, ...) do { \
        if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \
 } while(0)
 #define PSI_DEBUG_DUMP(ctx, dump_func, ...) do { \
        if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \
-               dump_func(PSI_DATA(ctx)->debug_fd, __VA_ARGS__); \
+               struct psi_dump dump_ = {{ .fd = PSI_DATA(ctx)->debug_fd}, \
+                               .fun = (psi_dump_cb) dprintf}; \
+               dump_func(&dump_, __VA_ARGS__); \
        } \
 } while (0)
 
        } \
 } while (0)
 
@@ -88,12 +98,20 @@ union psi_dump_arg {
        void *hn;
        int fd;
 };
        void *hn;
        int fd;
 };
-typedef void (*psi_dump_cb)(union psi_dump_arg, const char *msg, ...);
+typedef int (*psi_dump_cb)(union psi_dump_arg, const char *msg, ...);
 struct psi_dump {
        union psi_dump_arg ctx;
        psi_dump_cb fun;
 };
 struct psi_dump {
        union psi_dump_arg ctx;
        psi_dump_cb fun;
 };
-#define PSI_DUMP(dump, ...) (dump)->fun((dump)->ctx, __VA_ARGS__)
+#define PSI_DUMP(dump, ...) do { \
+       struct psi_dump _dump_tmp, *_dump_ptr = dump; \
+       if (!_dump_ptr) { \
+               _dump_ptr = &_dump_tmp; \
+               _dump_tmp.ctx.fd = STDOUT_FILENO; \
+               _dump_tmp.fun = (psi_dump_cb) dprintf; \
+       } \
+       _dump_ptr->fun(_dump_ptr->ctx, __VA_ARGS__); \
+} while(0)
 
 #define PSI_DATA(D) ((struct psi_data *) (D))
 
 
 #define PSI_DATA(D) ((struct psi_data *) (D))
 
@@ -121,6 +139,6 @@ struct psi_data *psi_data_ctor(struct psi_data *data, psi_error_cb error, unsign
 struct psi_data *psi_data_ctor_with_dtors(struct psi_data *data, psi_error_cb error, unsigned flags);
 struct psi_data *psi_data_exchange(struct psi_data *dest, struct psi_data *src);
 void psi_data_dtor(struct psi_data *data);
 struct psi_data *psi_data_ctor_with_dtors(struct psi_data *data, psi_error_cb error, unsigned flags);
 struct psi_data *psi_data_exchange(struct psi_data *dest, struct psi_data *src);
 void psi_data_dtor(struct psi_data *data);
-void psi_data_dump(int fd, struct psi_data *data);
+void psi_data_dump(struct psi_dump *dump, struct psi_data *data);
 
 #endif
 
 #endif