Skip to content

Commit

Permalink
statx: fixed macro return type, method logic & using PyMem_RawCalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
YoSTEALTH committed May 30, 2024
1 parent e6ec8b6 commit 5b06989
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = {file="README.rst", content-type="text/x-rst"}
license = {file="LICENSE.txt", content-type="text"}
requires-python = ">=3.8"
dependencies = ["dynamic-import"]
description = "..."
description = "Liburing is Python + Cython wrapper around C Liburing, which is a helper to setup and tear-down io_uring instances."
classifiers = ["Topic :: Software Development",
"License :: Public Domain",
"Intended Audience :: Developers",
Expand Down
2 changes: 1 addition & 1 deletion src/liburing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dynamic_import import importer


__version__ = '2024.5.3'
__version__ = '2024.5.30'


importer(exclude_dir=['lib', 'include'])
Expand Down
14 changes: 7 additions & 7 deletions src/liburing/lib/statx.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ cdef extern from '<linux/stat.h>' nogil:
__S_IXOTH 'S_IXOTH'

# Macro
bint __S_ISLNK 'S_ISLNK'(mode_t m)
bint __S_ISREG 'S_ISREG'(mode_t m)
bint __S_ISDIR 'S_ISDIR'(mode_t m)
bint __S_ISCHR 'S_ISCHR'(mode_t m)
bint __S_ISBLK 'S_ISBLK'(mode_t m)
bint __S_ISFIFO 'S_ISFIFO'(mode_t m)
bint __S_ISSOCK 'S_ISSOCK'(mode_t m)
int __S_ISLNK 'S_ISLNK'(mode_t m)
int __S_ISREG 'S_ISREG'(mode_t m)
int __S_ISDIR 'S_ISDIR'(mode_t m)
int __S_ISCHR 'S_ISCHR'(mode_t m)
int __S_ISBLK 'S_ISBLK'(mode_t m)
int __S_ISFIFO 'S_ISFIFO'(mode_t m)
int __S_ISSOCK 'S_ISSOCK'(mode_t m)


cdef extern from * nogil: # '<fcntl.h>'
Expand Down
4 changes: 2 additions & 2 deletions src/liburing/statx.pxd
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from cpython.mem cimport PyMem_RawMalloc, PyMem_RawFree
from cpython.mem cimport PyMem_RawCalloc, PyMem_RawFree
from .error cimport memory_error
from .queue cimport *


cdef class statx:
cdef __statx *ptr
cdef __statx* ptr


cpdef void io_uring_prep_statx(io_uring_sqe sqe,
Expand Down
20 changes: 10 additions & 10 deletions src/liburing/statx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef class statx:
https://man7.org/linux/man-pages/man7/inode.7.html
'''
def __cinit__(self):
self.ptr = <__statx*>PyMem_RawMalloc(sizeof(__statx))
self.ptr = <__statx*>PyMem_RawCalloc(1, sizeof(__statx))
if self.ptr is NULL:
memory_error(self)

Expand Down Expand Up @@ -131,47 +131,47 @@ cdef class statx:
@property
def islink(self) -> bool:
''' Return True if mode is from a symbolic link. '''
return __S_ISLNK(self.ptr.stx_mode)
return __S_ISLNK(self.ptr.stx_mode) == 1

@property
def isfile(self) -> bool:
''' Return True if mode is from a regular file. '''
return __S_ISREG(self.ptr.stx_mode)
return __S_ISREG(self.ptr.stx_mode) == 1

@property
def isreg(self) -> bool:
''' Return True if mode is from a regular file. '''
return __S_ISREG(self.ptr.stx_mode)
return __S_ISREG(self.ptr.stx_mode) == 1

@property
def isdir(self) -> bool:
''' Return True if mode is from a directory. '''
return __S_ISDIR(self.ptr.stx_mode)
return __S_ISDIR(self.ptr.stx_mode) == 1

@property
def ischr(self) -> bool:
''' Return True if mode is from a character special device file. '''
return __S_ISCHR(self.ptr.stx_mode)
return __S_ISCHR(self.ptr.stx_mode) == 1

@property
def isblk(self) -> bool:
''' Return True if mode is from a block special device file. '''
return __S_ISBLK(self.ptr.stx_mode)
return __S_ISBLK(self.ptr.stx_mode) == 1

@property
def isfifo(self) -> bool:
''' Return True if mode is from a FIFO (named pipe). '''
return __S_ISFIFO(self.ptr.stx_mode)
return __S_ISFIFO(self.ptr.stx_mode) == 1

@property
def issock(self) -> bool:
''' Return True if mode is from a socket. '''
return __S_ISSOCK(self.ptr.stx_mode)
return __S_ISSOCK(self.ptr.stx_mode) == 1


cpdef inline void io_uring_prep_statx(io_uring_sqe sqe,
statx statxbuf,
const char *path,
const char* path,
int flags=0,
unsigned int mask=0,
int dfd=__AT_FDCWD) noexcept nogil:
Expand Down

0 comments on commit 5b06989

Please sign in to comment.