Python ctypes 模块,c_short() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ctypes.c_short()

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:touch-pay-client    作者:HackPucBemobi    | 项目源码 | 文件源码
def dataSources():
    """Return a list with [name, descrition]"""
    dsn = create_buffer(1024)
    desc = create_buffer(1024)
    dsn_len = c_short()
    desc_len = c_short()
    dsn_list = {}
    try:
        lock.acquire()
        if shared_env_h is None:
            AllocateEnv()
    finally:
        lock.release()
    while 1:
        ret = ODBC_API.SQLDataSources(shared_env_h, SQL_FETCH_NEXT, \
            dsn, len(dsn), ADDR(dsn_len), desc, len(desc), ADDR(desc_len))
        if ret == SQL_NO_DATA_FOUND:
            break
        elif not ret in (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO):
            ctrl_err(SQL_HANDLE_ENV, shared_env_h, ret)
        else:
            dsn_list[dsn.value] = desc.value
    return dsn_list
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def dataSources():
    """Return a list with [name, descrition]"""
    dsn = create_buffer(1024)
    desc = create_buffer(1024)
    dsn_len = c_short()
    desc_len = c_short()
    dsn_list = {}
    try:
        lock.acquire()
        if shared_env_h is None:
            AllocateEnv()
    finally:
        lock.release()
    while 1:
        ret = ODBC_API.SQLDataSources(shared_env_h, SQL_FETCH_NEXT, \
            dsn, len(dsn), ADDR(dsn_len), desc, len(desc), ADDR(desc_len))
        if ret == SQL_NO_DATA_FOUND:
            break
        elif not ret in (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO):
            ctrl_err(SQL_HANDLE_ENV, shared_env_h, ret)
        else:
            dsn_list[dsn.value] = desc.value
    return dsn_list
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def dataSources():
    """Return a list with [name, descrition]"""
    dsn = create_buffer(1024)
    desc = create_buffer(1024)
    dsn_len = c_short()
    desc_len = c_short()
    dsn_list = {}
    try:
        lock.acquire()
        if shared_env_h is None:
            AllocateEnv()
    finally:
        lock.release()
    while 1:
        ret = ODBC_API.SQLDataSources(shared_env_h, SQL_FETCH_NEXT, \
            dsn, len(dsn), ADDR(dsn_len), desc, len(desc), ADDR(desc_len))
        if ret == SQL_NO_DATA_FOUND:
            break
        elif not ret in (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO):
            ctrl_err(SQL_HANDLE_ENV, shared_env_h, ret)
        else:
            dsn_list[dsn.value] = desc.value
    return dsn_list
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_array_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER
        INTARRAY = c_int * 3
        ia = INTARRAY()
        self.assertEqual(len(ia), 3)
        self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])

        # Pointers are only compatible with arrays containing items of
        # the same type!
        LPINT = POINTER(c_int)
        LPINT.from_param((c_int*3)())
        self.assertRaises(TypeError, LPINT.from_param, c_short*3)
        self.assertRaises(TypeError, LPINT.from_param, c_long*3)
        self.assertRaises(TypeError, LPINT.from_param, c_uint*3)

##    def test_performance(self):
##        check_perf()
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def dataSources():
    """Return a list with [name, descrition]"""
    dsn = create_buffer(1024)
    desc = create_buffer(1024)
    dsn_len = c_short()
    desc_len = c_short()
    dsn_list = {}
    try:
        lock.acquire()
        if shared_env_h is None:
            AllocateEnv()
    finally:
        lock.release()
    while 1:
        ret = ODBC_API.SQLDataSources(shared_env_h, SQL_FETCH_NEXT, \
            dsn, len(dsn), ADDR(dsn_len), desc, len(desc), ADDR(desc_len))
        if ret == SQL_NO_DATA_FOUND:
            break
        elif not ret in (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO):
            ctrl_err(SQL_HANDLE_ENV, shared_env_h, ret)
        else:
            dsn_list[dsn.value] = desc.value
    return dsn_list
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:rekall-agent-server    作者:rekall-innovations    | 项目源码 | 文件源码
def dataSources():
    """Return a list with [name, descrition]"""
    dsn = create_buffer(1024)
    desc = create_buffer(1024)
    dsn_len = c_short()
    desc_len = c_short()
    dsn_list = {}
    try:
        lock.acquire()
        if shared_env_h is None:
            AllocateEnv()
    finally:
        lock.release()
    while 1:
        ret = ODBC_API.SQLDataSources(shared_env_h, SQL_FETCH_NEXT, \
            dsn, len(dsn), ADDR(dsn_len), desc, len(desc), ADDR(desc_len))
        if ret == SQL_NO_DATA_FOUND:
            break
        elif not ret in (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO):
            ctrl_err(SQL_HANDLE_ENV, shared_env_h, ret)
        else:
            dsn_list[dsn.value] = desc.value
    return dsn_list
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def _generate_data(self, num_bytes, offset):
        if self._bytes_per_sample == 1:
            start = offset
            samples = num_bytes
            bias = 127
            amplitude = 127
            data = (ctypes.c_ubyte * samples)()
        else:
            start = offset >> 1
            samples = num_bytes >> 1
            bias = 0
            amplitude = 32767
            data = (ctypes.c_short * samples)()
        step = self.frequency * (math.pi * 2) / self.audio_format.sample_rate
        envelope = self._envelope_array
        env_offset = offset // self._bytes_per_sample
        for i in range(samples):
            data[i] = int(math.sin(step * (i + start)) *
                          amplitude * envelope[i+env_offset] + bias)
        return data
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def _generate_data(self, num_bytes, offset):
        # XXX TODO consider offset
        if self._bytes_per_sample == 1:
            samples = num_bytes
            value = 127
            maximum = 255
            minimum = 0
            data = (ctypes.c_ubyte * samples)()
        else:
            samples = num_bytes >> 1
            value = 0
            maximum = 32767
            minimum = -32768
            data = (ctypes.c_short * samples)()
        step = (maximum - minimum) * self.frequency / self._sample_rate
        envelope = self._envelope_array
        env_offset = offset // self._bytes_per_sample
        for i in range(samples):
            value += step
            if value > maximum:
                value = minimum + (value % maximum)
            data[i] = int(value * envelope[i+env_offset])
        return data
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def _generate_data(self, num_bytes, offset):
        if self._bytes_per_sample == 1:
            start = offset
            samples = num_bytes
            bias = 127
            amplitude = 127
            data = (ctypes.c_ubyte * samples)()
        else:
            start = offset >> 1
            samples = num_bytes >> 1
            bias = 0
            amplitude = 32767
            data = (ctypes.c_short * samples)()
        self._advance(start)
        ring_buffer = self.ring_buffer
        decay = self.decay
        for i in range(samples):
            data[i] = int(ring_buffer[0] * amplitude + bias)
            ring_buffer.append(decay * (ring_buffer[0] + ring_buffer[1]) / 2)
        return data
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def _generate_data(self, bytes, offset):
        if self._bytes_per_sample == 1:
            start = offset
            samples = bytes
            bias = 127
            amplitude = 127
            data = (ctypes.c_ubyte * samples)()
        else:
            start = offset >> 1
            samples = bytes >> 1
            bias = 0
            amplitude = 32767
            data = (ctypes.c_short * samples)()
        step = self.frequency * (math.pi * 2) / self.audio_format.sample_rate
        for i in range(samples):
            data[i] = future_round(math.sin(step * (i + start)) * amplitude + bias)
        return data
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def _generate_data(self, bytes, offset):
        # XXX TODO consider offset
        if self._bytes_per_sample == 1:
            samples = bytes
            value = 127
            max = 255
            min = 0
            data = (ctypes.c_ubyte * samples)()
        else:
            samples = bytes >> 1
            value = 0
            max = 32767
            min = -32768
            data = (ctypes.c_short * samples)()
        step = (max - min) * 2 * self.frequency / self.audio_format.sample_rate
        for i in range(samples):
            value += step
            if value > max:
                value = max - (value - max)
                step = -step
            if value < min:
                value = min - (value - min)
                step = -step
            data[i] = future_round(value)
        return data
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def _generate_data(self, bytes, offset):
        # XXX TODO consider offset
        if self._bytes_per_sample == 1:
            samples = bytes
            value = 0
            amplitude = 255
            data = (ctypes.c_ubyte * samples)()
        else:
            samples = bytes >> 1
            value = -32768
            amplitude = 65535
            data = (ctypes.c_short * samples)()
        period = self.audio_format.sample_rate / self.frequency / 2
        count = 0
        for i in range(samples):
            count += 1
            if count == period:
                value = amplitude - value
                count = 0
            data[i] = future_round(value)
        return data
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def dataSources():
    """Return a list with [name, descrition]"""
    dsn = create_buffer(1024)
    desc = create_buffer(1024)
    dsn_len = c_short()
    desc_len = c_short()
    dsn_list = {}
    try:
        lock.acquire()
        if shared_env_h is None:
            AllocateEnv()
    finally:
        lock.release()
    while 1:
        ret = ODBC_API.SQLDataSources(shared_env_h, SQL_FETCH_NEXT, \
            dsn, len(dsn), ADDR(dsn_len), desc, len(desc), ADDR(desc_len))
        if ret == SQL_NO_DATA_FOUND:
            break
        elif not ret in (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO):
            ctrl_err(SQL_HANDLE_ENV, shared_env_h, ret)
        else:
            dsn_list[dsn.value] = desc.value
    return dsn_list
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_array_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER
        INTARRAY = c_int * 3
        ia = INTARRAY()
        self.assertEqual(len(ia), 3)
        self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])

        # Pointers are only compatible with arrays containing items of
        # the same type!
        LPINT = POINTER(c_int)
        LPINT.from_param((c_int*3)())
        self.assertRaises(TypeError, LPINT.from_param, c_short*3)
        self.assertRaises(TypeError, LPINT.from_param, c_long*3)
        self.assertRaises(TypeError, LPINT.from_param, c_uint*3)

##    def test_performance(self):
##        check_perf()
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_int_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
        LPINT = POINTER(c_int)

##        p = pointer(c_int(42))
##        x = LPINT.from_param(p)
        x = LPINT.from_param(pointer(c_int(42)))
        self.assertEqual(x.contents.value, 42)
        self.assertEqual(LPINT(c_int(42)).contents.value, 42)

        self.assertEqual(LPINT.from_param(None), None)

        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
        self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def dataSources():
    """Return a list with [name, descrition]"""
    dsn = create_buffer(1024)
    desc = create_buffer(1024)
    dsn_len = c_short()
    desc_len = c_short()
    dsn_list = {}
    try:
        lock.acquire()
        if shared_env_h is None:
            AllocateEnv()
    finally:
        lock.release()
    while 1:
        ret = ODBC_API.SQLDataSources(shared_env_h, SQL_FETCH_NEXT, \
            dsn, len(dsn), ADDR(dsn_len), desc, len(desc), ADDR(desc_len))
        if ret == SQL_NO_DATA_FOUND:
            break
        elif not ret in (SQL_SUCCESS, SQL_SUCCESS_WITH_INFO):
            ctrl_err(SQL_HANDLE_ENV, shared_env_h, ret)
        else:
            dsn_list[dsn.value] = desc.value
    return dsn_list
项目:StratoBalloon    作者:delattreb    | 项目源码 | 文件源码
def getshort(data, index):
        # return two bytes from data as a signed 16-bit value
        return c_short((data[index + 1] << 8) + data[index]).value
项目:PythonForWindows    作者:hakril    | 项目源码 | 文件源码
def read_short(self, addr):
        """Read a ``SHORT`` at ``addr``"""
        sizeof_short = sizeof(ctypes.c_short)
        return struct.unpack("<H", self.read_memory(addr, sizeof_short))[0]
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def test_byref_pointer(self):
        # The from_param class method of POINTER(typ) classes accepts what is
        # returned by byref(obj), it type(obj) == typ
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
        LPINT = POINTER(c_int)

        LPINT.from_param(byref(c_int(42)))

        self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
        self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def test_byref_pointerpointer(self):
        # See above
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref

        LPLPINT = POINTER(POINTER(c_int))
        LPLPINT.from_param(byref(pointer(c_int(42))))

        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
        if c_int != c_long:
            self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def test_array_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER
        INTARRAY = c_int * 3
        ia = INTARRAY()
        self.assertEqual(len(ia), 3)
        self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])

        # Pointers are only compatible with arrays containing items of
        # the same type!
        LPINT = POINTER(c_int)
        LPINT.from_param((c_int*3)())
        self.assertRaises(TypeError, LPINT.from_param, c_short*3)
        self.assertRaises(TypeError, LPINT.from_param, c_long*3)
        self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
项目:touch-pay-client    作者:HackPucBemobi    | 项目源码 | 文件源码
def _NumOfCols(self):
        """Get the number of cols"""
        if not self.connection:
            self.close()

        NOC = c_short()
        ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
        if ret != SQL_SUCCESS:
            check_success(self, ret)
        return NOC.value
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def _NumOfCols(self):
        """Get the number of cols"""
        if not self.connection:
            self.close()

        NOC = c_short()
        ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
        if ret != SQL_SUCCESS:
            check_success(self, ret)
        return NOC.value
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def _NumOfCols(self):
        """Get the number of cols"""
        if not self.connection:
            self.close()

        NOC = c_short()
        ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
        if ret != SQL_SUCCESS:
            check_success(self, ret)
        return NOC.value
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_byref_pointer(self):
        # The from_param class method of POINTER(typ) classes accepts what is
        # returned by byref(obj), it type(obj) == typ
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
        LPINT = POINTER(c_int)

        LPINT.from_param(byref(c_int(42)))

        self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
        self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_byref_pointerpointer(self):
        # See above
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref

        LPLPINT = POINTER(POINTER(c_int))
        LPLPINT.from_param(byref(pointer(c_int(42))))

        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
        if c_int != c_long:
            self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
项目:pytari2600    作者:ajgrah2000    | 项目源码 | 文件源码
def addc(self, a, b, c):

        if 0 == self.pc_state.P.get_D():
            r  = ctypes.c_short(a + b + c).value
            rc = ctypes.c_byte(a + b + c).value
            self.pc_state.P.set_N((0,1)[0x80 == (rc & 0x80)])
            self.pc_state.P.set_Z((0,1)[rc == 0x0])
            self.pc_state.P.set_V((0,1)[rc != r])   # Overflow

            r = ((a & 0xFF) + (b & 0xFF) + c) & 0xFFFF
            self.pc_state.P.set_C((0,1)[0x100 == (r & 0x100)])
            result = (a + b + c)
        elif 1 == self.pc_state.P.get_D():
            # Decimal Addition
            # FIXME need to fix flags
            #
            r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) + ((b>>4) & 0xF)* 10 + ((b & 0xF) %10) + c).value
            rc = ctypes.c_byte(a + b + c).value # ???? TODO
            self.pc_state.P.set_N((0,1)[r < 0])
            self.pc_state.P.set_Z((0,1)[rc == 0x0])
            # self.pc_state.P.V = (rc != r) ? 1:0;   # Overflow

            self.pc_state.P.set_C((0,1)[(r > 99) or (r < 0)])
            result = (((((r/10) % 10) << 4) & 0xf0) + (r%10))

        return result & 0xFF
项目:pytari2600    作者:ajgrah2000    | 项目源码 | 文件源码
def subc(self, a, b, c):

        if 0 == self.pc_state.P.get_D():
            r  = ctypes.c_short(ctypes.c_byte(a).value - ctypes.c_byte(b).value - ctypes.c_byte(c).value).value
            rs = ctypes.c_byte((a - b - c) & 0xFF).value
            self.pc_state.P.set_N((0,1)[0x80 == (rs & 0x80)]) # Negative
            self.pc_state.P.set_Z((0,1)[rs == 0])   # Zero
            self.pc_state.P.set_V((0,1)[r != rs])   # Overflow

            r = a - b - c 
            self.pc_state.P.set_C((1,0)[0x100 == (r & 0x100)]) # Carry (not borrow
            result = a - b - c
        elif 1 == self.pc_state.P.get_D():
            # Decimal subtraction
            # FIXME need to fix flags

            r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) - (((b>>4) & 0xF)* 10 + ((b & 0xF) %10)) - c).value

            # rc = a + b + c
            self.pc_state.P.set_N((0,1)[r < 0])
            self.pc_state.P.set_Z((0,1)[r == 0x0])
            #  Need to check/fix conditions for V
            # self.pc_state.P.V = (rc != r) ? 1:0;   # Overflow
            self.pc_state.P.set_V(1)   # Overflow

            self.pc_state.P.set_C((0,1)[(r >= 0) and (r <= 99)])
            result = (((int(r/10) % 10) << 4) & 0xf0) + (r%10)

        return result & 0xFF
项目:pytari2600    作者:ajgrah2000    | 项目源码 | 文件源码
def cmp(self, a, b):
        r = ctypes.c_short(ctypes.c_byte(a).value - ctypes.c_byte(b).value).value
        rs = ctypes.c_byte(a - b).value
        self.pc_state.P.set_N((0,1)[0x80 == (rs & 0x80)])    # Negative
        self.pc_state.P.set_Z((0,1)[rs == 0])              # Zero
        r = (a & 0xFF) - (b & 0xFF)
        self.pc_state.P.set_C((1,0)[0x100 == (r & 0x100)]) # Carry (not borrow)
项目:pytari2600    作者:ajgrah2000    | 项目源码 | 文件源码
def addc(self, a, b, c):

        if 0 == self.pc_state.P.get_D():
            r  = ctypes.c_short(a + b + c).value
            rc = ctypes.c_byte(a + b + c).value
            self.pc_state.P.set_N((0,1)[0x80 == (rc & 0x80)])
            self.pc_state.P.set_Z((0,1)[rc == 0x0])
            self.pc_state.P.set_V((0,1)[rc != r])   # Overflow

            r = ((a & 0xFF) + (b & 0xFF) + c) & 0xFFFF
            self.pc_state.P.set_C((0,1)[0x100 == (r & 0x100)])
            result = (a + b + c)
        elif 1 == self.pc_state.P.get_D():
            # Decimal Addition
            # FIXME need to fix flags
            #
            r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) + ((b>>4) & 0xF)* 10 + ((b & 0xF) %10) + c).value
            rc = ctypes.c_byte(a + b + c).value # ???? TODO
            self.pc_state.P.set_N((0,1)[r < 0])
            self.pc_state.P.set_Z((0,1)[rc == 0x0])
            # self.pc_state.P.V = (rc != r) ? 1:0;   # Overflow

            self.pc_state.P.set_C((0,1)[(r > 99) or (r < 0)])
            result = ((((int(r/10) % 10) << 4) & 0xf0) + (r%10))

        return result & 0xFF
项目:pytari2600    作者:ajgrah2000    | 项目源码 | 文件源码
def subc(self, a, b, c):

        if 0 == self.pc_state.P.get_D():
            r  = ctypes.c_short(ctypes.c_byte(a).value - ctypes.c_byte(b).value - ctypes.c_byte(c).value).value
            rs = ctypes.c_byte((a - b - c) & 0xFF).value
            self.pc_state.P.set_N((0,1)[0x80 == (rs & 0x80)]) # Negative
            self.pc_state.P.set_Z((0,1)[rs == 0])   # Zero
            self.pc_state.P.set_V((0,1)[r != rs])   # Overflow

            r = a - b - c 
            self.pc_state.P.set_C((1,0)[0x100 == (r & 0x100)]) # Carry (not borrow
            result = a - b - c
        elif 1 == self.pc_state.P.get_D():
            # Decimal subtraction
            # FIXME need to fix flags

            r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) - (((b>>4) & 0xF)* 10 + ((b & 0xF) %10)) - c).value

            # rc = a + b + c
            self.pc_state.P.set_N((0,1)[r < 0])
            self.pc_state.P.set_Z((0,1)[r == 0x0])
            #  Need to check/fix conditions for V
            # self.pc_state.P.V = (rc != r) ? 1:0;   # Overflow
            self.pc_state.P.set_V(1)   # Overflow

            self.pc_state.P.set_C((0,1)[(r >= 0) and (r <= 99)])
            result = (((int(r/10) % 10) << 4) & 0xf0) + (r%10)

        return result & 0xFF
项目:alljoyn_python    作者:glennpierce    | 项目源码 | 文件源码
def GetInt16(self):
        value = C.c_short()
        self._GetInt16(self.handle, C.byref(value))
        return value.value
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def _NumOfCols(self):
        """Get the number of cols"""
        if not self.connection:
            self.close()

        NOC = c_short()
        ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
        if ret != SQL_SUCCESS:
            check_success(self, ret)
        return NOC.value
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_byref_pointer(self):
        # The from_param class method of POINTER(typ) classes accepts what is
        # returned by byref(obj), it type(obj) == typ
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
        LPINT = POINTER(c_int)

        LPINT.from_param(byref(c_int(42)))

        self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
        self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_byref_pointerpointer(self):
        # See above
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref

        LPLPINT = POINTER(POINTER(c_int))
        LPLPINT.from_param(byref(pointer(c_int(42))))

        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
        if c_int != c_long:
            self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_array_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER
        INTARRAY = c_int * 3
        ia = INTARRAY()
        self.assertEqual(len(ia), 3)
        self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])

        # Pointers are only compatible with arrays containing items of
        # the same type!
        LPINT = POINTER(c_int)
        LPINT.from_param((c_int*3)())
        self.assertRaises(TypeError, LPINT.from_param, c_short*3)
        self.assertRaises(TypeError, LPINT.from_param, c_long*3)
        self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_byref_pointer(self):
        # The from_param class method of POINTER(typ) classes accepts what is
        # returned by byref(obj), it type(obj) == typ
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
        LPINT = POINTER(c_int)

        LPINT.from_param(byref(c_int(42)))

        self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
        self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_byref_pointerpointer(self):
        # See above
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref

        LPLPINT = POINTER(POINTER(c_int))
        LPLPINT.from_param(byref(pointer(c_int(42))))

        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
        if c_int != c_long:
            self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_array_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER
        INTARRAY = c_int * 3
        ia = INTARRAY()
        self.assertEqual(len(ia), 3)
        self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])

        # Pointers are only compatible with arrays containing items of
        # the same type!
        LPINT = POINTER(c_int)
        LPINT.from_param((c_int*3)())
        self.assertRaises(TypeError, LPINT.from_param, c_short*3)
        self.assertRaises(TypeError, LPINT.from_param, c_long*3)
        self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def test_byref_pointer(self):
        # The from_param class method of POINTER(typ) classes accepts what is
        # returned by byref(obj), it type(obj) == typ
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
        LPINT = POINTER(c_int)

        LPINT.from_param(byref(c_int(42)))

        self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
        if c_int != c_long:
            self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
        self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def test_byref_pointerpointer(self):
        # See above
        from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref

        LPLPINT = POINTER(POINTER(c_int))
        LPLPINT.from_param(byref(pointer(c_int(42))))

        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
        if c_int != c_long:
            self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
        self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def test_array_pointers(self):
        from ctypes import c_short, c_uint, c_int, c_long, POINTER
        INTARRAY = c_int * 3
        ia = INTARRAY()
        self.assertEqual(len(ia), 3)
        self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])

        # Pointers are only compatible with arrays containing items of
        # the same type!
        LPINT = POINTER(c_int)
        LPINT.from_param((c_int*3)())
        self.assertRaises(TypeError, LPINT.from_param, c_short*3)
        self.assertRaises(TypeError, LPINT.from_param, c_long*3)
        self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
项目:rekall-agent-server    作者:rekall-innovations    | 项目源码 | 文件源码
def _NumOfCols(self):
        """Get the number of cols"""
        if not self.connection:
            self.close()

        NOC = c_short()
        ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
        if ret != SQL_SUCCESS:
            check_success(self, ret)
        return NOC.value