summaryrefslogtreecommitdiff
path: root/cffi/backend_ctypes.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-01-31 16:30:40 +0100
committerArmin Rigo <arigo@tunes.org>2015-01-31 16:30:40 +0100
commitf303a39e29a56599dd0ca65080c170c80798cd1d (patch)
tree87fb9966c1200dc86c429228a553dd7f0603c0e2 /cffi/backend_ctypes.py
parent7f409da47287b5d226d46361aa01d65a168c18a9 (diff)
downloadcffi-f303a39e29a56599dd0ca65080c170c80798cd1d.tar.gz
Python 3 fixes
Diffstat (limited to 'cffi/backend_ctypes.py')
-rw-r--r--cffi/backend_ctypes.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
index 7fcde57..5cc0c2a 100644
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -2,11 +2,10 @@ import ctypes, ctypes.util, operator, sys
from . import model
if sys.version_info < (3,):
- integer_types = (int, long)
bytechr = chr
else:
unicode = str
- integer_types = int
+ long = int
xrange = range
bytechr = lambda num: bytes([num])
@@ -181,7 +180,7 @@ class CTypesGenericPtr(CTypesData):
address = 0
elif isinstance(source, CTypesData):
address = source._cast_to_integer()
- elif isinstance(source, integer_types):
+ elif isinstance(source, (int, long)):
address = source
else:
raise TypeError("bad type for cast to %r: %r" %
@@ -358,7 +357,7 @@ class CTypesBackend(object):
is_signed = (ctype(-1).value == -1)
#
def _cast_source_to_int(source):
- if isinstance(source, (integer_types, float)):
+ if isinstance(source, (int, long, float)):
source = int(source)
elif isinstance(source, CTypesData):
source = source._cast_to_integer()
@@ -399,7 +398,7 @@ class CTypesBackend(object):
if kind == 'bool':
@classmethod
def _cast_from(cls, source):
- if not isinstance(source, (integer_types, float)):
+ if not isinstance(source, (int, long, float)):
source = _cast_source_to_int(source)
return cls(bool(source))
def __int__(self):
@@ -438,7 +437,7 @@ class CTypesBackend(object):
if kind == 'int' or kind == 'byte' or kind == 'bool':
@staticmethod
def _to_ctypes(x):
- if not isinstance(x, integer_types):
+ if not isinstance(x, (int, long)):
if isinstance(x, CTypesData):
x = int(x)
else:
@@ -465,7 +464,7 @@ class CTypesBackend(object):
if kind == 'float':
@staticmethod
def _to_ctypes(x):
- if not isinstance(x, (integer_types, float, CTypesData)):
+ if not isinstance(x, (int, long, float, CTypesData)):
raise TypeError("float expected, got %s" %
type(x).__name__)
return ctype(x).value
@@ -529,14 +528,14 @@ class CTypesBackend(object):
self._own = True
def __add__(self, other):
- if isinstance(other, integer_types):
+ if isinstance(other, (int, long)):
return self._new_pointer_at(self._address +
other * self._bitem_size)
else:
return NotImplemented
def __sub__(self, other):
- if isinstance(other, integer_types):
+ if isinstance(other, (int, long)):
return self._new_pointer_at(self._address -
other * self._bitem_size)
elif type(self) is type(other):
@@ -611,7 +610,7 @@ class CTypesBackend(object):
def __init__(self, init):
if length is None:
- if isinstance(init, integer_types):
+ if isinstance(init, (int, long)):
len1 = init
init = None
elif kind == 'char' and isinstance(init, bytes):
@@ -686,7 +685,7 @@ class CTypesBackend(object):
return CTypesPtr._arg_to_ctypes(value)
def __add__(self, other):
- if isinstance(other, integer_types):
+ if isinstance(other, (int, long)):
return CTypesPtr._new_pointer_at(
ctypes.addressof(self._blob) +
other * ctypes.sizeof(BItem._ctype))