Generated by Cython 0.28.5
Yellow lines hint at Python interaction.
Click on a line that starts with a "+
" to see the C code that Cython generated for it.
Raw output: cyxor.c
01: # This file is part of Xpra.
02: # Copyright (C) 2012-2018 Antoine Martin <antoine@devloop.org.uk>
03: # Xpra is released under the terms of the GNU GPL v2, or, at your option, any
04: # later version. See the file COPYING for details.
05:
06: #cython: wraparound=False
07: from __future__ import absolute_import
08:
09: from libc.stdint cimport uint32_t, uintptr_t
10: from xpra.buffers.membuf cimport getbuf, object_as_buffer, MemBuf
11:
12:
+13: def xor_str(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6codecs_3xor_5cyxor_1xor_str(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6codecs_3xor_5cyxor_1xor_str = {"xor_str", (PyCFunction)__pyx_pw_4xpra_6codecs_3xor_5cyxor_1xor_str, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_4xpra_6codecs_3xor_5cyxor_1xor_str(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_a = 0; PyObject *__pyx_v_b = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("xor_str (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_b,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("xor_str", 1, 2, 2, 1); __PYX_ERR(0, 13, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "xor_str") < 0)) __PYX_ERR(0, 13, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_a = values[0]; __pyx_v_b = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("xor_str", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 13, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("xpra.codecs.xor.cyxor.xor_str", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4xpra_6codecs_3xor_5cyxor_xor_str(__pyx_self, __pyx_v_a, __pyx_v_b); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6codecs_3xor_5cyxor_xor_str(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_b) { Py_ssize_t __pyx_v_alen; Py_ssize_t __pyx_v_blen; uintptr_t __pyx_v_ap; uintptr_t __pyx_v_bp; uintptr_t __pyx_v_op; struct __pyx_obj_4xpra_7buffers_6membuf_MemBuf *__pyx_v_out_buf = 0; unsigned char *__pyx_v_acbuf; unsigned char *__pyx_v_bcbuf; unsigned char *__pyx_v_ocbuf; uint32_t *__pyx_v_obuf; uint32_t *__pyx_v_abuf; uint32_t *__pyx_v_bbuf; unsigned int __pyx_v_i; unsigned int __pyx_v_j; unsigned int __pyx_v_steps; unsigned int __pyx_v_char_steps; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("xor_str", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("xpra.codecs.xor.cyxor.xor_str", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_out_buf); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple_ = PyTuple_Pack(18, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_alen, __pyx_n_s_blen, __pyx_n_s_ap, __pyx_n_s_bp, __pyx_n_s_op, __pyx_n_s_out_buf, __pyx_n_s_acbuf, __pyx_n_s_bcbuf, __pyx_n_s_ocbuf, __pyx_n_s_obuf, __pyx_n_s_abuf, __pyx_n_s_bbuf, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_steps, __pyx_n_s_char_steps); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6codecs_3xor_5cyxor_1xor_str, NULL, __pyx_n_s_xpra_codecs_xor_cyxor); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_xor_str, __pyx_t_1) < 0) __PYX_ERR(0, 13, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+14: assert len(a)==len(b), "cyxor cannot xor strings of different lengths (%s:%s vs %s:%s)" % (type(a), len(a), type(b), len(b))
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { __pyx_t_1 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 14, __pyx_L1_error) __pyx_t_2 = PyObject_Length(__pyx_v_b); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 14, __pyx_L1_error) if (unlikely(!((__pyx_t_1 == __pyx_t_2) != 0))) { __pyx_t_3 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 14, __pyx_L1_error) __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyObject_Length(__pyx_v_b); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 14, __pyx_L1_error) __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_a))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_a))); PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)Py_TYPE(__pyx_v_a))); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4); __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_b))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_b))); PyTuple_SET_ITEM(__pyx_t_6, 2, ((PyObject *)Py_TYPE(__pyx_v_b))); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_5); __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_cyxor_cannot_xor_strings_of_diff, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 14, __pyx_L1_error) } } #endif
+15: cdef Py_ssize_t alen = 0, blen = 0
__pyx_v_alen = 0; __pyx_v_blen = 0;
16: cdef uintptr_t ap
17: cdef uintptr_t bp
18: cdef uintptr_t op
+19: assert object_as_buffer(a, <const void **> &ap, &alen)==0, "cannot get buffer pointer for %s" % type(a)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_f_4xpra_7buffers_6membuf_object_as_buffer(__pyx_v_a, ((void const **)(&__pyx_v_ap)), (&__pyx_v_alen)) == 0) != 0))) { __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_cannot_get_buffer_pointer_for_s, ((PyObject *)Py_TYPE(__pyx_v_a))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 19, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); PyErr_SetObject(PyExc_AssertionError, __pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 19, __pyx_L1_error) } } #endif
+20: assert object_as_buffer(b, <const void **> &bp, &blen)==0, "cannot get buffer pointer for %s" % type(b)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_f_4xpra_7buffers_6membuf_object_as_buffer(__pyx_v_b, ((void const **)(&__pyx_v_bp)), (&__pyx_v_blen)) == 0) != 0))) { __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_cannot_get_buffer_pointer_for_s, ((PyObject *)Py_TYPE(__pyx_v_b))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); PyErr_SetObject(PyExc_AssertionError, __pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 20, __pyx_L1_error) } } #endif
+21: assert alen == blen, "python or cython bug? buffers don't have the same length?"
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_alen == __pyx_v_blen) != 0))) { PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_python_or_cython_bug_buffers_don); __PYX_ERR(0, 21, __pyx_L1_error) } } #endif
+22: cdef MemBuf out_buf = getbuf(alen)
__pyx_t_5 = __pyx_f_4xpra_7buffers_6membuf_getbuf(__pyx_v_alen); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_4xpra_7buffers_6membuf_MemBuf))))) __PYX_ERR(0, 22, __pyx_L1_error) __pyx_v_out_buf = ((struct __pyx_obj_4xpra_7buffers_6membuf_MemBuf *)__pyx_t_5); __pyx_t_5 = 0;
+23: op = <uintptr_t> out_buf.get_mem()
__pyx_v_op = ((uintptr_t)((struct __pyx_vtabstruct_4xpra_7buffers_6membuf_MemBuf *)__pyx_v_out_buf->__pyx_vtab)->get_mem(__pyx_v_out_buf));
+24: cdef unsigned char *acbuf = <unsigned char *> ap
__pyx_v_acbuf = ((unsigned char *)__pyx_v_ap);
+25: cdef unsigned char *bcbuf = <unsigned char *> bp
__pyx_v_bcbuf = ((unsigned char *)__pyx_v_bp);
+26: cdef unsigned char *ocbuf = <unsigned char *> op
__pyx_v_ocbuf = ((unsigned char *)__pyx_v_op);
+27: cdef uint32_t *obuf = <uint32_t*> op
__pyx_v_obuf = ((uint32_t *)__pyx_v_op);
+28: cdef uint32_t *abuf = <uint32_t*> ap
__pyx_v_abuf = ((uint32_t *)__pyx_v_ap);
+29: cdef uint32_t *bbuf = <uint32_t*> bp
__pyx_v_bbuf = ((uint32_t *)__pyx_v_bp);
30: cdef unsigned int i, j, steps, char_steps
+31: if (ap % 4)!=0 or (bp % 4!=0):
__pyx_t_8 = (((__pyx_v_ap % 4) != 0) != 0); if (!__pyx_t_8) { } else { __pyx_t_7 = __pyx_t_8; goto __pyx_L4_bool_binop_done; } __pyx_t_8 = (((__pyx_v_bp % 4) != 0) != 0); __pyx_t_7 = __pyx_t_8; __pyx_L4_bool_binop_done:; if (__pyx_t_7) { /* … */ goto __pyx_L3; }
32: #unaligned access, use byte at a time slow path:
+33: char_steps = alen
__pyx_v_char_steps = __pyx_v_alen;
+34: for 0 <= i < char_steps:
__pyx_t_9 = __pyx_v_char_steps; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {
+35: ocbuf[i] = acbuf[i] ^ bcbuf[i]
(__pyx_v_ocbuf[__pyx_v_i]) = ((__pyx_v_acbuf[__pyx_v_i]) ^ (__pyx_v_bcbuf[__pyx_v_i])); }
36: else:
37: #do 4 bytes at a time:
+38: steps = alen // 4
/*else*/ { __pyx_v_steps = __Pyx_div_Py_ssize_t(__pyx_v_alen, 4);
+39: if steps>0:
__pyx_t_7 = ((__pyx_v_steps > 0) != 0); if (__pyx_t_7) { /* … */ }
+40: for 0 <= i < steps:
__pyx_t_9 = __pyx_v_steps; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {
+41: obuf[i] = abuf[i] ^ bbuf[i]
(__pyx_v_obuf[__pyx_v_i]) = ((__pyx_v_abuf[__pyx_v_i]) ^ (__pyx_v_bbuf[__pyx_v_i])); }
42: #bytes at a time again at the end:
+43: char_steps = alen % 4
__pyx_v_char_steps = __Pyx_mod_Py_ssize_t(__pyx_v_alen, 4);
+44: if char_steps>0:
__pyx_t_7 = ((__pyx_v_char_steps > 0) != 0); if (__pyx_t_7) { /* … */ } } __pyx_L3:;
+45: for 0 <= i < char_steps:
__pyx_t_9 = __pyx_v_char_steps; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {
+46: j = alen-char_steps+i
__pyx_v_j = ((__pyx_v_alen - __pyx_v_char_steps) + __pyx_v_i);
+47: ocbuf[j] = acbuf[j] ^ bcbuf[j]
(__pyx_v_ocbuf[__pyx_v_j]) = ((__pyx_v_acbuf[__pyx_v_j]) ^ (__pyx_v_bcbuf[__pyx_v_j])); }
+48: return memoryview(out_buf)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_memoryview); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_out_buf)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;