Commit b9d72051 authored by Kirill Smelkov's avatar Kirill Smelkov

*: uint8_t -> byte, unicode-codepint -> rune

We added byte and rune types in the previous patch. Let's use them now
throughout whole codebase where appropriate.

Currently the only place where unicode-codepoint is used is
_utf8_decode_rune. uint8_t was used in many places.
parent 83a1da99
...@@ -68,7 +68,6 @@ cdef extern from "Python.h": ...@@ -68,7 +68,6 @@ cdef extern from "Python.h":
from cython cimport no_gc from cython cimport no_gc
from libc.stdint cimport uint8_t
from libc.stdio cimport FILE from libc.stdio cimport FILE
pystrconv = None # = golang.strconv imported at runtime (see __init__.py) pystrconv = None # = golang.strconv imported at runtime (see __init__.py)
...@@ -1056,7 +1055,7 @@ _bstrustr_remove_unsupported_slots() ...@@ -1056,7 +1055,7 @@ _bstrustr_remove_unsupported_slots()
# NOTE the return type is str type of current python, so that quoted result # NOTE the return type is str type of current python, so that quoted result
# could be directly used in __repr__ or __str__ implementation. # could be directly used in __repr__ or __str__ implementation.
cdef _bpysmartquote_u3b2(s): # -> (unicode(py3)|bytes(py2), nonascii_escape) cdef _bpysmartquote_u3b2(s): # -> (unicode(py3)|bytes(py2), nonascii_escape)
# TODO change to `const uint8_t[::1] s` after strconv._quote is moved to pyx # TODO change to `const byte[::1] s` after strconv._quote is moved to pyx
if isinstance(s, bytearray): if isinstance(s, bytearray):
s = _bytearray_data(s) s = _bytearray_data(s)
assert isinstance(s, bytes), s assert isinstance(s, bytes), s
...@@ -1498,7 +1497,7 @@ cdef class _UnboundMethod(object): # they removed unbound methods on py3 ...@@ -1498,7 +1497,7 @@ cdef class _UnboundMethod(object): # they removed unbound methods on py3
# See also overview of patching bytes.{__repr__,__str__} near _bstringify. # See also overview of patching bytes.{__repr__,__str__} near _bstringify.
cdef object _missing = object() cdef object _missing = object()
cdef object _atidx_re = pyre.compile('.* at index ([0-9]+)$') cdef object _atidx_re = pyre.compile('.* at index ([0-9]+)$')
cdef _bprintf(const uint8_t[::1] fmt, xarg): # -> pybstr cdef _bprintf(const byte[::1] fmt, xarg): # -> pybstr
cdef bytearray out = bytearray() cdef bytearray out = bytearray()
cdef tuple argv = None # if xarg is tuple cdef tuple argv = None # if xarg is tuple
...@@ -1570,7 +1569,7 @@ cdef _bprintf(const uint8_t[::1] fmt, xarg): # -> pybstr ...@@ -1570,7 +1569,7 @@ cdef _bprintf(const uint8_t[::1] fmt, xarg): # -> pybstr
# differently - on b %r is aliased to %a. # differently - on b %r is aliased to %a.
cdef int i = 0 cdef int i = 0
cdef int l = len(fmt) cdef int l = len(fmt)
cdef uint8_t c cdef byte c
while i < l: while i < l:
c = fmt[i] c = fmt[i]
i += 1 i += 1
...@@ -1883,9 +1882,9 @@ assert _ucs2_build or sys.maxunicode >= 0x0010ffff # or ucs4 ...@@ -1883,9 +1882,9 @@ assert _ucs2_build or sys.maxunicode >= 0x0010ffff # or ucs4
# _utf8_decode_rune decodes next UTF8-character from byte string s. # _utf8_decode_rune decodes next UTF8-character from byte string s.
# #
# _utf8_decode_rune(s) -> (r, size) # _utf8_decode_rune(s) -> (r, size)
def _py_utf8_decode_rune(const uint8_t[::1] s): def _py_utf8_decode_rune(const byte[::1] s):
return _utf8_decode_rune(s) return _utf8_decode_rune(s)
cdef (int, int) _utf8_decode_rune(const uint8_t[::1] s): cdef (rune, int) _utf8_decode_rune(const byte[::1] s):
if len(s) == 0: if len(s) == 0:
return _rune_error, 0 return _rune_error, 0
...@@ -1918,7 +1917,7 @@ cdef (int, int) _utf8_decode_rune(const uint8_t[::1] s): ...@@ -1918,7 +1917,7 @@ cdef (int, int) _utf8_decode_rune(const uint8_t[::1] s):
# _utf8_decode_surrogateescape mimics s.decode('utf-8', 'surrogateescape') from py3. # _utf8_decode_surrogateescape mimics s.decode('utf-8', 'surrogateescape') from py3.
def _utf8_decode_surrogateescape(const uint8_t[::1] s): # -> unicode def _utf8_decode_surrogateescape(const byte[::1] s): # -> unicode
if PY_MAJOR_VERSION >= 3: if PY_MAJOR_VERSION >= 3:
if len(s) == 0: if len(s) == 0:
return u'' # avoid out-of-bounds slice access on &s[0] return u'' # avoid out-of-bounds slice access on &s[0]
......
...@@ -40,7 +40,7 @@ ELSE: ...@@ -40,7 +40,7 @@ ELSE:
from gevent import sleep as pygsleep from gevent import sleep as pygsleep
from libc.stdint cimport uint8_t, uint64_t from libc.stdint cimport uint64_t
from cpython cimport PyObject, Py_INCREF, Py_DECREF from cpython cimport PyObject, Py_INCREF, Py_DECREF
from cython cimport final from cython cimport final
...@@ -49,7 +49,7 @@ from golang.runtime._libgolang cimport _libgolang_runtime_ops, _libgolang_sema, ...@@ -49,7 +49,7 @@ from golang.runtime._libgolang cimport _libgolang_runtime_ops, _libgolang_sema,
from golang.runtime.internal cimport syscall from golang.runtime.internal cimport syscall
from golang.runtime cimport _runtime_thread from golang.runtime cimport _runtime_thread
from golang.runtime._runtime_pymisc cimport PyExc, pyexc_fetch, pyexc_restore from golang.runtime._runtime_pymisc cimport PyExc, pyexc_fetch, pyexc_restore
from golang cimport topyexc from golang cimport byte, topyexc
from libc.stdlib cimport calloc, free from libc.stdlib cimport calloc, free
from libc.errno cimport EBADF from libc.errno cimport EBADF
...@@ -343,7 +343,7 @@ cdef nogil: ...@@ -343,7 +343,7 @@ cdef nogil:
cdef: cdef:
bint _io_read(IOH* ioh, int* out_n, void *buf, size_t count): bint _io_read(IOH* ioh, int* out_n, void *buf, size_t count):
pygfobj = <object>ioh.pygfobj pygfobj = <object>ioh.pygfobj
cdef uint8_t[::1] mem = <uint8_t[:count]>buf cdef byte[::1] mem = <byte[:count]>buf
xmem = memoryview(mem) # to avoid https://github.com/cython/cython/issues/3900 on mem[:0]=b'' xmem = memoryview(mem) # to avoid https://github.com/cython/cython/issues/3900 on mem[:0]=b''
try: try:
# NOTE buf might be on stack, so it must not be accessed, e.g. from # NOTE buf might be on stack, so it must not be accessed, e.g. from
...@@ -380,7 +380,7 @@ cdef nogil: ...@@ -380,7 +380,7 @@ cdef nogil:
cdef: cdef:
bint _io_write(IOH* ioh, int* out_n, const void *buf, size_t count): bint _io_write(IOH* ioh, int* out_n, const void *buf, size_t count):
pygfobj = <object>ioh.pygfobj pygfobj = <object>ioh.pygfobj
cdef const uint8_t[::1] mem = <const uint8_t[:count]>buf cdef const byte[::1] mem = <const byte[:count]>buf
# NOTE buf might be on stack, so it must not be accessed, e.g. from # NOTE buf might be on stack, so it must not be accessed, e.g. from
# FileObjectThread, while our greenlet is parked (see STACK_DEAD_WHILE_PARKED # FileObjectThread, while our greenlet is parked (see STACK_DEAD_WHILE_PARKED
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment