Changes to improve compatibility with Perl 5.8.
[perl-fuse.git] / Fuse.xs
diff --git a/Fuse.xs b/Fuse.xs
index 01fcafb..9e2504e 100755 (executable)
--- a/Fuse.xs
+++ b/Fuse.xs
@@ -3,23 +3,27 @@
 #include "perl.h"
 #include "XSUB.h"
 
-/*
- * XXX: Fuse on FreeBSD does not support extended attributes (see
- * /usr/local/share/doc/fusefs/kmod/doc.text). Also, 'extattr_set_file' syscall
- * declared in 'sys/extattr.h' does not accept any flags. We could either skip
- * defining XATTR_CREATE and XATTR_REPLACE constants (as further below, and
- * which breaks their usage if Perl module exports them), set them to some
- * dummy values, or not allow them to be exported at all on FreeBSD.
- */
-#ifndef __FreeBSD__
+#include <fuse.h>
+
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+# define XATTR_CREATE 1
+# define XATTR_REPLACE 2
+#else
 # include <sys/xattr.h>
 #endif
-#include <fuse.h>
 
 /* Determine if threads support should be included */
 #ifdef USE_ITHREADS
 # ifdef I_PTHREAD
 #  define FUSE_USE_ITHREADS
+#  if (PERL_VERSION < 10)
+#    define tTHX PerlInterpreter*
+#    define STR_WITH_LEN(s)  ("" s ""), (sizeof(s)-1)
+#    define hv_fetchs(hv,key,lval) Perl_hv_fetch(aTHX_ hv, STR_WITH_LEN(key), lval)
+#    define dMY_CXT_INTERP(interp) \
+       SV *my_cxt_sv = *hv_fetchs(interp->Imodglobal, MY_CXT_KEY, TRUE); \
+       my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*, SvUV(my_cxt_sv))
+#  endif
 # else
 #  warning "Sorry, I don't know how to handle ithreads on this architecture. Building non-threaded version"
 # endif
 typedef struct {
        SV *callback[N_CALLBACKS];
        HV *handles;
+#ifdef USE_ITHREADS
        tTHX self;
+#endif
        int threaded;
+#ifdef USE_ITHREADS
        perl_mutex mutex;
+#endif
 } my_cxt_t;
 START_MY_CXT;
 
@@ -54,6 +62,9 @@ tTHX master_interp = NULL;
 
 #define CLONE_INTERP(parent) S_clone_interp(parent)
 tTHX S_clone_interp(tTHX parent) {
+#if (PERL_VERSION < 10)
+       tTHX my_perl = parent;
+#endif
        dMY_CXT_INTERP(parent);
        if(MY_CXT.threaded) {
                MUTEX_LOCK(&MY_CXT.mutex);
@@ -737,7 +748,11 @@ int _PLfuse_fsync (const char *file, int datasync, struct fuse_file_info *fi) {
        return rv;
 }
 
+#if __FreeBSD__ >= 10
+int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags, uint32_t position) {
+#else
 int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) {
+#endif
        int rv;
        FUSE_CONTEXT_PRE;
        DEBUGf("setxattr begin\n");
@@ -760,7 +775,11 @@ int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_
        return rv;
 }
 
+#if __FreeBSD__ >= 10
+int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen, uint32_t position) {
+#else
 int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) {
+#endif
        int rv;
        FUSE_CONTEXT_PRE;
        DEBUGf("getxattr begin\n");
@@ -1516,14 +1535,19 @@ PROTOTYPES: DISABLE
 
 BOOT:
        MY_CXT_INIT;
+#ifdef USE_ITHREADS
        MY_CXT.self = aTHX;
+#endif
 
 void
 CLONE(...)
        PREINIT:
+#ifdef USE_ITHREADS
                int i;
                dTHX;
+#endif
        CODE:
+#ifdef USE_ITHREADS
                MY_CXT_CLONE;
                tTHX parent = MY_CXT.self;
                MY_CXT.self = my_perl;
@@ -1555,6 +1579,7 @@ CLONE(...)
                        clone_params_del(clone_param);
 #endif
                }
+#endif
 
 SV*
 fuse_get_context()