Skip to content

Commit

Permalink
Fix warnings (#27)
Browse files Browse the repository at this point in the history
* Fix warning about deprecated language='c++'
* Fix warnings about nogil before except
* Make i variables unsigned
* Fix warning about possibly unitialized i variable
  • Loading branch information
insolor authored Jan 8, 2024
1 parent c11c55c commit 225565a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

ext_modules = cythonize(
extensions,
language="c++",
annotate=False,
compiler_directives=compiler_directives,
)
Expand Down
4 changes: 2 additions & 2 deletions src/_dictionary.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ cdef extern from "../lib/dawgdic/src/dawgdic/dictionary.h" namespace "dawgdic":
ValueType value(BaseType index) nogil

# Reads a dictionary from an input stream.
bint Read(istream *input) nogil except +
bint Read(istream *input) except + nogil

# Writes a dictionry to an output stream.
bint Write(ostream *output) nogil except +
bint Write(ostream *output) except + nogil

# Exact matching.
bint Contains(CharType *key) nogil
Expand Down
13 changes: 9 additions & 4 deletions src/dawg.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cython: profile=False
# cython: embedsignature=True
# distutils: language=c++

cimport _dawg
cimport _dictionary_builder
Expand Down Expand Up @@ -580,7 +581,7 @@ cdef class BytesDAWG(CompletionDAWG):
cpdef list items(self, unicode prefix=""):
cdef bytes b_prefix = prefix.encode('utf8')
cdef bytes value
cdef int i
cdef unsigned int i
cdef list res = []
cdef char* raw_key
cdef char* raw_value
Expand All @@ -604,6 +605,8 @@ cdef class BytesDAWG(CompletionDAWG):
for i in range(0, completer.length()):
if raw_key[i] == self._c_payload_separator:
break
else:
continue

raw_value = &(raw_key[i])
raw_value_len = completer.length() - i
Expand All @@ -622,7 +625,7 @@ cdef class BytesDAWG(CompletionDAWG):
def iteritems(self, unicode prefix=""):
cdef bytes b_prefix = prefix.encode('utf8')
cdef bytes value
cdef int i
cdef unsigned int i
cdef char* raw_key
cdef char* raw_value
cdef int raw_value_len
Expand Down Expand Up @@ -658,7 +661,7 @@ cdef class BytesDAWG(CompletionDAWG):

cpdef list keys(self, unicode prefix=""):
cdef bytes b_prefix = prefix.encode('utf8')
cdef int i
cdef unsigned int i
cdef list res = []
cdef char* raw_key

Expand All @@ -676,14 +679,16 @@ cdef class BytesDAWG(CompletionDAWG):
for i in range(0, completer.length()):
if raw_key[i] == self._c_payload_separator:
break
else:
continue

u_key = raw_key[:i].decode('utf8')
res.append(u_key)
return res

def iterkeys(self, unicode prefix=""):
cdef bytes b_prefix = prefix.encode('utf8')
cdef int i
cdef unsigned int i
cdef char* raw_key

cdef BaseType index = self.dct.root()
Expand Down

0 comments on commit 225565a

Please sign in to comment.