Copy @x into a (modifiable) ctypes byte array
546483
def getBuffer(x):
    
    b = bytes(x)
    return (c_ubyte * len(b)).from_buffer_copy(bytes(x))
708593
def extern_store_tuple(self, context_handle, vals_ptr, vals_len):
    """"""
    c = self._ffi.from_handle(context_handle)
    return c.to_value(tuple(c.from_value(val[0]) for val in self._ffi.unpack(vals_ptr, vals_len)))
504450
def idaunpack(buf):
    
    buf = bytearray(buf)

    def nextval(o):
        val = buf[o] ; o += 1
        if val == 0xff:  # 32 bit value
            val, = struct.unpack_from(">L", buf, o)
            o += 4
            return val, o
        if val < 0x80:  # 7 bit value
            return val, o
        val <<= 8
        val |= buf[o] ; o += 1
        if val < 0xc000:  # 14 bit value
            return val & 0x3fff, o

        # 29 bit value
        val <<= 8
        val |= buf[o] ; o += 1
        val <<= 8
        val |= buf[o] ; o += 1
        return val & 0x1fffffff, o

    values = []
    o = 0
    while o < len(buf):
        val, o = nextval(o)
        values.append(val)
    return values
514440
def cfloat32_array_to_numpy(cptr, length):
    """"""
    if isinstance(cptr, ctypes.POINTER(ctypes.c_float)):
        return np.fromiter(cptr, dtype=np.float32, count=length)
    else:
        raise RuntimeError('Expected float pointer')
1102316
def _call(self, x, out):
        """"""
        with writable_array(out) as out_arr:
            resize_array(x.asarray(), self.range.shape, offset=self.offset,
                         pad_mode=self.pad_mode, pad_const=self.pad_const,
                         direction='forward', out=out_arr)
53275
def Binary(x):
    """"""
    if isinstance(x, text_type) and not (JYTHON or IRONPYTHON):
        return x.encode()
    return bytes(x)
562355
def cfloat64_array_to_numpy(cptr, length):
    """"""
    if isinstance(cptr, ctypes.POINTER(ctypes.c_double)):
        return np.fromiter(cptr, dtype=np.float64, count=length)
    else:
        raise RuntimeError('Expected double pointer')
289587
def to_byte(stype):
    
    output = []

    if stype in ('i8', 'u8'):
        return []

    if is_int_type(stype):
        output.append('ld a, l')
    elif stype == 'f16':
        output.append('ld a, e')
    elif stype == 'f':  # Converts C ED LH to byte
        output.append('call __FTOU32REG')
        output.append('ld a, l')
        REQUIRES.add('ftou32reg.asm')

    return output
336482
def ctype_for_encoding(self, encoding):
        """"""
        if encoding in self.typecodes:
            return self.typecodes[encoding]
        elif encoding[0:1] == b'^' and encoding[1:] in self.typecodes:
            return POINTER(self.typecodes[encoding[1:]])
        elif encoding[0:1] == b'^' and encoding[1:] in [CGImageEncoding,
                                                        NSZoneEncoding]:
            return c_void_p
        elif encoding[0:1] == b'r' and encoding[1:] in self.typecodes:
            return self.typecodes[encoding[1:]]
        elif encoding[0:2] == b'r^' and encoding[2:] in self.typecodes:
            return POINTER(self.typecodes[encoding[2:]])
        else:
            raise Exception('unknown encoding for %s: %s'
                            % (self.name, encoding))
993013
def hexdump(x, dump=False):
    
    s = ""
    x = bytes_encode(x)
    x_len = len(x)
    i = 0
    while i < x_len:
        s += "%04x  " % i
        for j in range(16):
            if i + j < x_len:
                s += "%02X " % orb(x[i + j])
            else:
                s += "   "
        s += " %s\n" % sane_color(x[i:i + 16])
        i += 16
    # remove trailing \n
    s = s[:-1] if s.endswith("\n") else s
    if dump:
        return s
    else:
        print(s)
621522
def get_bytes(self, *args, **kwargs):
        
        return super(XClient, self).get(*args, **kwargs)
869115
def _lvarx(ins):
    
    output = []

    l = eval(ins.quad[3])  # List of bytes to push
    label = tmp_label()
    offset = int(ins.quad[1])
    tmp = list(ins.quad)
    tmp[1] = label
    ins.quad = tmp
    AT_END.extend(_varx(ins))

    output.append('push ix')
    output.append('pop hl')
    output.append('ld bc, %i' % -offset)
    output.append('add hl, bc')
    output.append('ex de, hl')
    output.append('ld hl, %s' % label)
    output.append('ld bc, %i' % (len(l) * YY_TYPES[ins.quad[2]]))
    output.append('ldir')

    return output
76760
def serialize(self, buf, offset):
        
        fields = [ofproto.oxs_from_user(k, uv) for (k, uv)
                  in self.fields]

        hdr_pack_str = '!HH'
        field_offset = offset + struct.calcsize(hdr_pack_str)
        for (n, value, _) in fields:
            # No mask
            field_offset += ofproto.oxs_serialize(n, value, None, buf,
                                                  field_offset)

        reserved = 0
        length = field_offset - offset
        msg_pack_into(hdr_pack_str, buf, offset, reserved, length)
        self.length = length

        pad_len = utils.round_up(length, 8) - length
        msg_pack_into("%dx" % pad_len, buf, field_offset)

        return length + pad_len
1288104
def _ctypes_saved(parameter):
    
    if ("out" in parameter.direction and parameter.dimension is not None and
        ":" in parameter.dimension and ("allocatable" in parameter.modifiers or
                                        "pointer" in parameter.modifiers)):
        stype = _ctypes_dtype(parameter)
        name = "{}_t({})".format(parameter.name, parameter.dimension)
        return ("{}, allocatable, target, save :: {}".format(stype, name), True)
517046
def c2f(r, i, ctype_name):
    

    ftype = c2f_dict[ctype_name]
    return np.typeDict[ctype_name](ftype(r) + 1j * ftype(i))
752534
def int_to_var_bytes(x):
    
    if x < 253:
        return intbytes.to_bytes(x, 1)
    elif x < 65536:
        return bytearray([253]) + intbytes.to_bytes(x, 2)[::-1]
    elif x < 4294967296:
        return bytearray([254]) + intbytes.to_bytes(x, 4)[::-1]
    else:
        return bytearray([255]) + intbytes.to_bytes(x, 8)[::-1]
468912
def typeinfo_to_ctypes(info, return_value=False):
    

    tag = info.tag.value
    ptr = info.is_pointer

    mapping = {
        GITypeTag.BOOLEAN: gboolean,
        GITypeTag.INT8: gint8,
        GITypeTag.UINT8: guint8,
        GITypeTag.INT16: gint16,
        GITypeTag.UINT16: guint16,
        GITypeTag.INT32: gint32,
        GITypeTag.UINT32: guint32,
        GITypeTag.INT64: gint64,
        GITypeTag.UINT64: guint64,
        GITypeTag.FLOAT: gfloat,
        GITypeTag.DOUBLE: gdouble,
        GITypeTag.VOID: None,
        GITypeTag.GTYPE: GType,
        GITypeTag.UNICHAR: gunichar,
    }

    if ptr:
        if tag == GITypeTag.INTERFACE:
            return gpointer
        elif tag in (GITypeTag.UTF8, GITypeTag.FILENAME):
            if return_value:
                # ctypes does auto conversion to str and gives us no chance
                # to free the pointer if transfer=everything
                return gpointer
            else:
                return gchar_p
        elif tag == GITypeTag.ARRAY:
            return gpointer
        elif tag == GITypeTag.ERROR:
            return GErrorPtr
        elif tag == GITypeTag.GLIST:
            return GListPtr
        elif tag == GITypeTag.GSLIST:
            return GSListPtr
        else:
            if tag in mapping:
                return ctypes.POINTER(mapping[tag])
    else:
        if tag == GITypeTag.INTERFACE:
            iface = info.get_interface()
            iface_type = iface.type.value
            if iface_type == GIInfoType.ENUM:
                return guint32
            elif iface_type == GIInfoType.OBJECT:
                return gpointer
            elif iface_type == GIInfoType.STRUCT:
                return gpointer
            elif iface_type == GIInfoType.UNION:
                return gpointer
            elif iface_type == GIInfoType.FLAGS:
                return guint
            elif iface_type == GIInfoType.CALLBACK:
                return GCallback

            raise NotImplementedError(
                "Could not convert interface: %r to ctypes type" % iface.type)
        else:
            if tag in mapping:
                return mapping[tag]

    raise NotImplementedError("Could not convert %r to ctypes type" % info.tag)