-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add optional cython extension (#44)
- Loading branch information
Showing
11 changed files
with
396 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Build optional cython modules.""" | ||
|
||
import contextlib | ||
import os | ||
from distutils.command.build_ext import build_ext | ||
|
||
|
||
class BuildExt(build_ext): | ||
def build_extensions(self): | ||
try: | ||
super().build_extensions() | ||
except Exception: | ||
pass | ||
|
||
|
||
def build(setup_kwargs): | ||
if os.environ.get("SKIP_CYTHON", False): | ||
return | ||
with contextlib.suppress(Exception): | ||
from Cython.Build import cythonize | ||
|
||
setup_kwargs.update( | ||
dict( | ||
ext_modules=cythonize( | ||
[ | ||
"src/dbus_fast/_private/marshaller.py", | ||
"src/dbus_fast/_private/unmarshaller.py", | ||
] | ||
), | ||
cmdclass=dict(build_ext=BuildExt), | ||
) | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""cdefs for marshaller.py""" | ||
|
||
import cython | ||
|
||
|
||
cdef class Marshaller: | ||
|
||
cdef object signature_tree | ||
cdef object _buf | ||
cdef object body | ||
|
||
|
||
@cython.locals( | ||
offset=cython.ulong, | ||
) | ||
cpdef int align(self, unsigned long n) | ||
|
||
|
||
@cython.locals( | ||
signature_len=cython.uint, | ||
written=cython.uint, | ||
) | ||
cpdef write_string(self, object value, _ = *) | ||
|
||
@cython.locals( | ||
array_len=cython.uint, | ||
written=cython.uint, | ||
) | ||
cpdef write_array(self, object array, object type) | ||
|
||
@cython.locals( | ||
written=cython.uint, | ||
) | ||
cpdef write_single(self, object type_, object body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""cdefs for unmarshaller.py""" | ||
|
||
import cython | ||
|
||
from ..signature import SignatureType | ||
|
||
|
||
cdef unsigned int UINT32_SIZE | ||
cdef unsigned int HEADER_ARRAY_OF_STRUCT_SIGNATURE_POSITION | ||
cdef unsigned int HEADER_SIGNATURE_SIZE | ||
|
||
cdef class Unmarshaller: | ||
|
||
cdef object unix_fds | ||
cdef object buf | ||
cdef object view | ||
cdef unsigned int pos | ||
cdef object stream | ||
cdef object sock | ||
cdef object _message | ||
cdef object readers | ||
cdef unsigned int body_len | ||
cdef unsigned int serial | ||
cdef unsigned int header_len | ||
cdef object message_type | ||
cdef object flag | ||
cdef unsigned int msg_len | ||
cdef object _uint32_unpack | ||
|
||
|
||
@cython.locals( | ||
start_len=cython.ulong, | ||
missing_bytes=cython.ulong, | ||
) | ||
cpdef read_to_pos(self, unsigned long pos) | ||
|
||
cpdef read_string_cast(self, type_ = *) | ||
|
||
@cython.locals( | ||
beginning_pos=cython.ulong, | ||
array_length=cython.uint, | ||
) | ||
cpdef read_array(self, object type_) | ||
|
||
@cython.locals( | ||
o=cython.ulong, | ||
signature_len=cython.uint, | ||
) | ||
cpdef read_signature(self, type_ = *) | ||
|
||
@cython.locals( | ||
endian=cython.uint, | ||
protocol_version=cython.uint, | ||
) | ||
cpdef _read_header(self) | ||
|
||
@cython.locals( | ||
beginning_pos=cython.ulong, | ||
o=cython.ulong, | ||
signature_len=cython.uint, | ||
) | ||
cpdef header_fields(self, unsigned int header_length) |
Oops, something went wrong.