Skip to content

Commit

Permalink
Generate one source file for all architectures.
Browse files Browse the repository at this point in the history
This is nice because we can now call out to the Cython command instead
of having to use the unsupported Python interface.

--HG--
rename : src/llfuse.c => src/llfuse.h
extra : amend_source : a31969773ce7cea6398d27643ad08d56de5b75c5
  • Loading branch information
Nikratio committed Sep 2, 2015
1 parent 57cdcc0 commit c4a2c68
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ syntax: regexp
^doc/doctrees$

syntax: glob
src/llfuse_*.c
src/llfuse.c
src/llfuse*.so
test/.cache/
18 changes: 4 additions & 14 deletions Include/fuse_lowlevel.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ cdef extern from "fuse_lowlevel.h" nogil:
int FUSE_SET_ATTR_ATIME_NOW
int FUSE_SET_ATTR_MTIME_NOW

IF TARGET_PLATFORM == 'darwin':
ctypedef void(*setxattr_fn_t)(fuse_req_t req, fuse_ino_t ino, const_char *name,
const_char *value, size_t size, int flags,
uint32_t position)
ctypedef void(*getxattr_fn_t)(fuse_req_t req, fuse_ino_t ino, const_char *name,
size_t size, uint32_t position)
ELSE:
ctypedef void(*setxattr_fn_t)(fuse_req_t req, fuse_ino_t ino, const_char *name,
const_char *value, size_t size, int flags)
ctypedef void(*getxattr_fn_t)(fuse_req_t req, fuse_ino_t ino, const_char *name,
size_t size)

struct fuse_lowlevel_ops:
void (*init) (void *userdata, fuse_conn_info *conn)
void (*destroy) (void *userdata)
Expand Down Expand Up @@ -109,8 +97,10 @@ cdef extern from "fuse_lowlevel.h" nogil:
void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
fuse_file_info *fi)
void (*statfs) (fuse_req_t req, fuse_ino_t ino)
setxattr_fn_t setxattr
getxattr_fn_t getxattr
void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const_char *name,
const_char *value, size_t size, int flags)
void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const_char *name,
size_t size)
void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size)
void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const_char *name)
void (*access) (fuse_req_t req, fuse_ino_t ino, int mask)
Expand Down
59 changes: 0 additions & 59 deletions Include/libc/xattr.pxd

This file was deleted.

62 changes: 28 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import subprocess
import warnings
import re

# Disable Cython support in setuptools. It fails under some conditions
# (http://trac.cython.org/ticket/859), and we have our own build_cython command
Expand All @@ -39,6 +40,7 @@
raise SystemExit('Setuptools package not found. Please install from '
'https://pypi.python.org/pypi/setuptools')
from setuptools import Extension
from distutils.version import LooseVersion

# Add util to load path
basedir = os.path.abspath(os.path.dirname(sys.argv[0]))
Expand Down Expand Up @@ -190,45 +192,37 @@ def initialize_options(self):
pass

def finalize_options(self):
pass
self.extensions = self.distribution.ext_modules

def run(self):
try:
from Cython.Compiler.Main import compile as cython_compile
from Cython.Compiler import Options as DefaultOptions
except ImportError:
version = subprocess.check_output(['cython', '--version'],
universal_newlines=True,
stderr=subprocess.STDOUT)
except OSError:
raise SystemExit('Cython needs to be installed for this command')

# Cannot be passed directly to cython_compile()
DefaultOptions.warning_errors = True
DefaultOptions.fast_fail = True

directives = dict()
directives.update(DefaultOptions.extra_warnings)
directives['embedsignature'] = True
directives['language_level'] = 3

# http://trac.cython.org/cython_trac/ticket/714
directives['warn.maybe_uninitialized'] = False

options = {'include_path': [ os.path.join(basedir, 'Include') ],
'verbose': True, 'timestamps': False, 'compile_time_env': {},
'compiler_directives': directives }

for sysname in ('linux', 'freebsd', 'darwin'):
print('compiling llfuse.pyx to llfuse_%s.c...' % (sysname,))
options['compile_time_env']['TARGET_PLATFORM'] = sysname
options['output_file'] = os.path.join(basedir, 'src',
'llfuse_%s.c' % (sysname,))
res = cython_compile(os.path.join(basedir, 'src', 'llfuse.pyx'),
full_module_name='llfuse', **options)
if res.num_errors != 0:
raise SystemExit('Cython encountered errors.')

# distutils doesn't know that llfuse.c #includes other files
# and thus does not recompile unless we change the modification
# date.
os.utime(os.path.join(basedir, 'src', 'llfuse.c'), None)
hit = re.match('^Cython version (.+)$', version)
if not hit or LooseVersion(hit.group(1)) < "0.21.1":
raise SystemExit('Need Cython 0.21.1 or newer, found ' + version)

cmd = ['cython', '-Wextra', '--force', '-3', '--fast-fail',
'--directive', 'embedsignature=True', '--include-dir',
os.path.join(basedir, 'Include'), '--verbose' ]
if DEVELOPER_MODE:
cmd.append('-Werror')

# Work around http://trac.cython.org/cython_trac/ticket/714
cmd += ['-X', 'warn.maybe_uninitialized=False' ]

for extension in self.extensions:
for file_ in extension.sources:
(file_, ext) = os.path.splitext(file_)
path = os.path.join(basedir, file_)
if ext != '.c':
continue
if os.path.exists(path + '.pyx'):
subprocess.check_call(cmd + [path + '.pyx'])

def fix_docutils():
'''Work around https://bitbucket.org/birkenfeld/sphinx/issue/1154/'''
Expand Down
50 changes: 14 additions & 36 deletions src/fuse_api.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,21 @@ def setxattr(path, name, bytes value, namespace='user'):
cdef char *cvalue
cdef char *cpath
cdef char *cname
cdef int cnamespace

IF TARGET_PLATFORM == 'freebsd':
cdef int cnamespace
if namespace == 'system':
cnamespace = xattr.EXTATTR_NAMESPACE_SYSTEM
else:
cnamespace = xattr.EXTATTR_NAMESPACE_USER
if namespace == 'system':
cnamespace = EXTATTR_NAMESPACE_SYSTEM
else:
cnamespace = EXTATTR_NAMESPACE_USER

path_b = str2bytes(path)
name_b = str2bytes(name)
PyBytes_AsStringAndSize(value, &cvalue, &len_)
cpath = <char*> path_b
cname = <char*> name_b


with nogil:
IF TARGET_PLATFORM == 'freebsd':
ret = xattr.extattr_set_file(cpath, cnamespace, cname,
cvalue, len_)
ELSE:
ret = xattr.setxattr(cpath, cname, cvalue, len_, 0)
ret = setxattr_p(cpath, cname, cvalue, len_, cnamespace)

if ret != 0:
raise OSError(errno.errno, strerror(errno.errno), path)
Expand Down Expand Up @@ -155,13 +149,12 @@ def getxattr(path, name, int size_guess=128, namespace='user'):
cdef char *cpath
cdef char *cname
cdef size_t bufsize
cdef int cnamespace

IF TARGET_PLATFORM == 'freebsd':
cdef int cnamespace
if namespace == 'system':
cnamespace = xattr.EXTATTR_NAMESPACE_SYSTEM
else:
cnamespace = xattr.EXTATTR_NAMESPACE_USER
if namespace == 'system':
cnamespace = EXTATTR_NAMESPACE_SYSTEM
else:
cnamespace = EXTATTR_NAMESPACE_USER

path_b = str2bytes(path)
name_b = str2bytes(name)
Expand All @@ -176,22 +169,11 @@ def getxattr(path, name, int size_guess=128, namespace='user'):

try:
with nogil:
IF TARGET_PLATFORM == 'freebsd':
ret = xattr.extattr_get_file(cpath, cnamespace, cname,
buf, bufsize)
if ret == bufsize:
ret = -1
errno.errno = errno.ERANGE
ELSE:
ret = xattr.getxattr(cpath, cname, buf, bufsize)
ret = getxattr_p(cpath, cname, buf, bufsize, cnamespace)

if ret < 0 and errno.errno == errno.ERANGE:
with nogil:
IF TARGET_PLATFORM == 'freebsd':
ret = xattr.extattr_get_file(cpath, cnamespace, cname,
NULL, 0)
ELSE:
ret = xattr.getxattr(cpath, cname, NULL, 0)
ret = getxattr_p(cpath, cname, NULL, 0, cnamespace)
if ret < 0:
raise OSError(errno.errno, strerror(errno.errno), path)
bufsize = <size_t> ret
Expand All @@ -201,11 +183,7 @@ def getxattr(path, name, int size_guess=128, namespace='user'):
cpython.exc.PyErr_NoMemory()

with nogil:
IF TARGET_PLATFORM == 'freebsd':
ret = xattr.extattr_get_file(cpath, cnamespace, cname,
buf, bufsize)
ELSE:
ret = xattr.getxattr(cpath, cname, buf, bufsize)
ret = getxattr_p(cpath, cname, buf, bufsize, cnamespace)

if ret < 0:
raise OSError(errno.errno, strerror(errno.errno), path)
Expand Down
69 changes: 33 additions & 36 deletions src/handlers.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -494,27 +494,25 @@ cdef void fuse_statfs (fuse_req_t req, fuse_ino_t ino) with gil:
if ret != 0:
log.error('fuse_statfs(): fuse_reply_* failed with %s', strerror(-ret))

IF TARGET_PLATFORM == 'darwin':
cdef void fuse_setxattr_darwin (fuse_req_t req, fuse_ino_t ino, const_char *cname,
const_char *cvalue, size_t size, int flags,
uint32_t position) with gil:
cdef int ret

if position != 0:
log.error('fuse_setxattr(): non-zero position (%d) not supported', position)
ret = fuse_reply_err(req, errno.EIO)
if ret != 0:
log.error('fuse_setxattr(): fuse_reply_err failed with %s', strerror(-ret))
return

# Filter out flags that don't make any sense for a FUSE
# file system, but that FUSE4x nevertheless stupidly
# passes through.
# (cf. https://groups.google.com/d/msg/fuse4x/bRnh7J_nsts/Z7raJ06DB4sJ)
flags &= ~(xattr.XATTR_NOFOLLOW | xattr.XATTR_NODEFAULT |
xattr.XATTR_NOSECURITY)
fuse_setxattr(req, ino, cname, cvalue, size, flags)
cdef void fuse_setxattr_darwin (fuse_req_t req, fuse_ino_t ino, const_char *cname,
const_char *cvalue, size_t size, int flags,
uint32_t position) with gil:
cdef int ret

if position != 0:
log.error('fuse_setxattr(): non-zero position (%d) not supported', position)
ret = fuse_reply_err(req, errno.EIO)
if ret != 0:
log.error('fuse_setxattr(): fuse_reply_err failed with %s', strerror(-ret))
return

# Filter out flags that don't make any sense for a FUSE
# file system, but that FUSE4x nevertheless stupidly
# passes through.
# (cf. https://groups.google.com/d/msg/fuse4x/bRnh7J_nsts/Z7raJ06DB4sJ)
flags &= ~(XATTR_NOFOLLOW | XATTR_NODEFAULT |
XATTR_NOSECURITY)
fuse_setxattr(req, ino, cname, cvalue, size, flags)

cdef void fuse_setxattr (fuse_req_t req, fuse_ino_t ino, const_char *cname,
const_char *cvalue, size_t size, int flags) with gil:
Expand All @@ -528,17 +526,17 @@ cdef void fuse_setxattr (fuse_req_t req, fuse_ino_t ino, const_char *cname,
if ino == FUSE_ROOT_ID and string.strcmp(cname, 'fuse_stacktrace') == 0:
operations.stacktrace()
else:
IF TARGET_PLATFORM == 'freebsd':
if PLATFORM == PLATFORM_DARWIN:
# No known flags
with lock:
operations.setxattr(ino, name, value)
ELSE:
else:
# Make sure we know all the flags
if flags & ~(xattr.XATTR_CREATE | xattr.XATTR_REPLACE):
if flags & ~(XATTR_CREATE | XATTR_REPLACE):
raise ValueError('unknown flag(s): %o' % flags)

with lock:
if flags & xattr.XATTR_CREATE: # Attribute must not exist
if flags & XATTR_CREATE: # Attribute must not exist
try:
operations.getxattr(ino, name)
except FUSEError as e:
Expand All @@ -547,7 +545,7 @@ cdef void fuse_setxattr (fuse_req_t req, fuse_ino_t ino, const_char *cname,
else:
raise FUSEError(errno.EEXIST)

elif flags & xattr.XATTR_REPLACE: # Attribute must exist
elif flags & XATTR_REPLACE: # Attribute must exist
operations.getxattr(ino, name)

operations.setxattr(ino, name, value)
Expand All @@ -561,18 +559,17 @@ cdef void fuse_setxattr (fuse_req_t req, fuse_ino_t ino, const_char *cname,
if ret != 0:
log.error('fuse_setxattr(): fuse_reply_* failed with %s', strerror(-ret))

IF TARGET_PLATFORM == 'darwin':
cdef void fuse_getxattr_darwin (fuse_req_t req, fuse_ino_t ino, const_char *cname,
size_t size, uint32_t position) with gil:
cdef int ret
cdef void fuse_getxattr_darwin (fuse_req_t req, fuse_ino_t ino, const_char *cname,
size_t size, uint32_t position) with gil:
cdef int ret

if position != 0:
log.error('fuse_getxattr(): non-zero position (%d) not supported' % position)
ret = fuse_reply_err(req, errno.EIO)
if ret != 0:
log.error('fuse_getxattr(): fuse_reply_* failed with %s', strerror(-ret))
else:
fuse_getxattr(req, ino, cname, size)
if position != 0:
log.error('fuse_getxattr(): non-zero position (%d) not supported' % position)
ret = fuse_reply_err(req, errno.EIO)
if ret != 0:
log.error('fuse_getxattr(): fuse_reply_* failed with %s', strerror(-ret))
else:
fuse_getxattr(req, ino, cname, size)

cdef void fuse_getxattr (fuse_req_t req, fuse_ino_t ino, const_char *cname,
size_t size) with gil:
Expand Down
Loading

0 comments on commit c4a2c68

Please sign in to comment.