Commit 4a761906 authored by Stefan Behnel's avatar Stefan Behnel

make code usages of Python "long" compatible with Py2/Py3

parent 958593e9
...@@ -163,7 +163,7 @@ distutils_settings = { ...@@ -163,7 +163,7 @@ distutils_settings = {
'language': transitive_str, 'language': transitive_str,
} }
@cython.locals(start=long, end=long) @cython.locals(start=cython.Py_ssize_t, end=cython.Py_ssize_t)
def line_iter(source): def line_iter(source):
if isinstance(source, basestring): if isinstance(source, basestring):
start = 0 start = 0
...@@ -254,8 +254,10 @@ class DistutilsInfo(object): ...@@ -254,8 +254,10 @@ class DistutilsInfo(object):
value = getattr(extension, key) + list(value) value = getattr(extension, key) + list(value)
setattr(extension, key, value) setattr(extension, key, value)
@cython.locals(start=long, q=long, single_q=long, double_q=long, hash_mark=long, @cython.locals(start=cython.Py_ssize_t, q=cython.Py_ssize_t,
end=long, k=long, counter=long, quote_len=long) single_q=cython.Py_ssize_t, double_q=cython.Py_ssize_t,
hash_mark=cython.Py_ssize_t, end=cython.Py_ssize_t,
k=cython.Py_ssize_t, counter=cython.Py_ssize_t, quote_len=cython.Py_ssize_t)
def strip_string_literals(code, prefix='__Pyx_L'): def strip_string_literals(code, prefix='__Pyx_L'):
""" """
Normalizes every string literal to be of the form '__Pyx_Lxxx', Normalizes every string literal to be of the form '__Pyx_Lxxx',
......
...@@ -13,10 +13,11 @@ cython.declare(error=object, warning=object, warn_once=object, InternalError=obj ...@@ -13,10 +13,11 @@ cython.declare(error=object, warning=object, warn_once=object, InternalError=obj
unicode_type=object, str_type=object, bytes_type=object, type_type=object, unicode_type=object, str_type=object, bytes_type=object, type_type=object,
Builtin=object, Symtab=object, Utils=object, find_coercion_error=object, Builtin=object, Symtab=object, Utils=object, find_coercion_error=object,
debug_disposal_code=object, debug_temp_alloc=object, debug_coercion=object, debug_disposal_code=object, debug_temp_alloc=object, debug_coercion=object,
bytearray_type=object, slice_type=object) bytearray_type=object, slice_type=object, _py_int_types=object)
import os.path import sys
import copy import copy
import os.path
import operator import operator
from .Errors import error, warning, warn_once, InternalError, CompileError from .Errors import error, warning, warn_once, InternalError, CompileError
...@@ -52,6 +53,12 @@ except ImportError: ...@@ -52,6 +53,12 @@ except ImportError:
bytes = str # Python 2 bytes = str # Python 2
if sys.version_info[0] >= 3:
_py_int_types = int
else:
_py_int_types = (int, long)
class NotConstant(object): class NotConstant(object):
_obj = None _obj = None
...@@ -123,8 +130,9 @@ def check_negative_indices(*nodes): ...@@ -123,8 +130,9 @@ def check_negative_indices(*nodes):
Used to find (potential) bugs inside of "wraparound=False" sections. Used to find (potential) bugs inside of "wraparound=False" sections.
""" """
for node in nodes: for node in nodes:
if (node is None if node is None or (
or not isinstance(node.constant_result, (int, float, long))): not isinstance(node.constant_result, _py_int_types) and
not isinstance(node.constant_result, float)):
continue continue
if node.constant_result < 0: if node.constant_result < 0:
warning(node.pos, warning(node.pos,
...@@ -2466,7 +2474,7 @@ class IteratorNode(ExprNode): ...@@ -2466,7 +2474,7 @@ class IteratorNode(ExprNode):
item_count = len(self.sequence.args) item_count = len(self.sequence.args)
if self.sequence.mult_factor is None: if self.sequence.mult_factor is None:
final_size = item_count final_size = item_count
elif isinstance(self.sequence.mult_factor.constant_result, (int, long)): elif isinstance(self.sequence.mult_factor.constant_result, _py_int_types):
final_size = item_count * self.sequence.mult_factor.constant_result final_size = item_count * self.sequence.mult_factor.constant_result
code.putln("if (%s >= %s) break;" % (self.counter_cname, final_size)) code.putln("if (%s >= %s) break;" % (self.counter_cname, final_size))
if self.reversed: if self.reversed:
...@@ -3609,7 +3617,7 @@ class IndexNode(ExprNode): ...@@ -3609,7 +3617,7 @@ class IndexNode(ExprNode):
wraparound = ( wraparound = (
bool(code.globalstate.directives['wraparound']) and bool(code.globalstate.directives['wraparound']) and
self.original_index_type.signed and self.original_index_type.signed and
not (isinstance(self.index.constant_result, (int, long)) not (isinstance(self.index.constant_result, _py_int_types)
and self.index.constant_result >= 0)) and self.index.constant_result >= 0))
boundscheck = bool(code.globalstate.directives['boundscheck']) boundscheck = bool(code.globalstate.directives['boundscheck'])
return ", %s, %d, %s, %d, %d, %d" % ( return ", %s, %d, %s, %d, %d, %d" % (
...@@ -4336,7 +4344,7 @@ class SliceIndexNode(ExprNode): ...@@ -4336,7 +4344,7 @@ class SliceIndexNode(ExprNode):
start = '%s + %d' % (self.base.type.size, start) start = '%s + %d' % (self.base.type.size, start)
else: else:
start += total_length start += total_length
if isinstance(slice_size, (int, long)): if isinstance(slice_size, _py_int_types):
slice_size -= start slice_size -= start
else: else:
slice_size = '%s - (%s)' % (slice_size, start) slice_size = '%s - (%s)' % (slice_size, start)
...@@ -4351,7 +4359,7 @@ class SliceIndexNode(ExprNode): ...@@ -4351,7 +4359,7 @@ class SliceIndexNode(ExprNode):
except ValueError: except ValueError:
int_target_size = None int_target_size = None
else: else:
compile_time_check = isinstance(slice_size, (int, long)) compile_time_check = isinstance(slice_size, _py_int_types)
if compile_time_check and slice_size < 0: if compile_time_check and slice_size < 0:
if int_target_size > 0: if int_target_size > 0:
...@@ -6443,8 +6451,8 @@ class SequenceNode(ExprNode): ...@@ -6443,8 +6451,8 @@ class SequenceNode(ExprNode):
mult_factor = self.mult_factor mult_factor = self.mult_factor
if mult_factor.type.is_int: if mult_factor.type.is_int:
c_mult = mult_factor.result() c_mult = mult_factor.result()
if isinstance(mult_factor.constant_result, (int,long)) \ if (isinstance(mult_factor.constant_result, _py_int_types) and
and mult_factor.constant_result > 0: mult_factor.constant_result > 0):
size_factor = ' * %s' % mult_factor.constant_result size_factor = ' * %s' % mult_factor.constant_result
elif mult_factor.type.signed: elif mult_factor.type.signed:
size_factor = ' * ((%s<0) ? 0:%s)' % (c_mult, c_mult) size_factor = ' * ((%s<0) ? 0:%s)' % (c_mult, c_mult)
...@@ -6870,7 +6878,8 @@ class TupleNode(SequenceNode): ...@@ -6870,7 +6878,8 @@ class TupleNode(SequenceNode):
if not all(child.is_literal for child in node.args): if not all(child.is_literal for child in node.args):
return node return node
if not node.mult_factor or ( if not node.mult_factor or (
node.mult_factor.is_literal and isinstance(node.mult_factor.constant_result, (int, long))): node.mult_factor.is_literal and
isinstance(node.mult_factor.constant_result, _py_int_types)):
node.is_temp = False node.is_temp = False
node.is_literal = True node.is_literal = True
else: else:
...@@ -7002,7 +7011,7 @@ class ListNode(SequenceNode): ...@@ -7002,7 +7011,7 @@ class ListNode(SequenceNode):
elif (dst_type.is_array or dst_type.is_ptr) and dst_type.base_type is not PyrexTypes.c_void_type: elif (dst_type.is_array or dst_type.is_ptr) and dst_type.base_type is not PyrexTypes.c_void_type:
array_length = len(self.args) array_length = len(self.args)
if self.mult_factor: if self.mult_factor:
if isinstance(self.mult_factor.constant_result, (int, long)): if isinstance(self.mult_factor.constant_result, _py_int_types):
if self.mult_factor.constant_result <= 0: if self.mult_factor.constant_result <= 0:
error(self.pos, "Cannot coerce non-positively multiplied list to '%s'" % dst_type) error(self.pos, "Cannot coerce non-positively multiplied list to '%s'" % dst_type)
else: else:
...@@ -10230,7 +10239,7 @@ class DivNode(NumBinopNode): ...@@ -10230,7 +10239,7 @@ class DivNode(NumBinopNode):
func = compile_time_binary_operators[self.operator] func = compile_time_binary_operators[self.operator]
if self.operator == '/' and self.truedivision is None: if self.operator == '/' and self.truedivision is None:
# => true div for floats, floor div for integers # => true div for floats, floor div for integers
if isinstance(op1, (int,long)) and isinstance(op2, (int,long)): if isinstance(op1, _py_int_types) and isinstance(op2, _py_int_types):
func = compile_time_binary_operators['//'] func = compile_time_binary_operators['//']
return func return func
...@@ -10515,7 +10524,7 @@ class PowNode(NumBinopNode): ...@@ -10515,7 +10524,7 @@ class PowNode(NumBinopNode):
def py_operation_function(self, code): def py_operation_function(self, code):
if (self.type.is_pyobject and if (self.type.is_pyobject and
self.operand1.constant_result == 2 and self.operand1.constant_result == 2 and
isinstance(self.operand1.constant_result, (int, long)) and isinstance(self.operand1.constant_result, _py_int_types) and
self.operand2.type is py_object_type): self.operand2.type is py_object_type):
code.globalstate.use_utility_code(UtilityCode.load_cached('PyNumberPow2', 'Optimize.c')) code.globalstate.use_utility_code(UtilityCode.load_cached('PyNumberPow2', 'Optimize.c'))
if self.inplace: if self.inplace:
......
...@@ -10,11 +10,16 @@ cython.declare(sys=object, os=object, copy=object, ...@@ -10,11 +10,16 @@ cython.declare(sys=object, os=object, copy=object,
py_object_type=object, ModuleScope=object, LocalScope=object, ClosureScope=object, py_object_type=object, ModuleScope=object, LocalScope=object, ClosureScope=object,
StructOrUnionScope=object, PyClassScope=object, StructOrUnionScope=object, PyClassScope=object,
CppClassScope=object, UtilityCode=object, EncodedString=object, CppClassScope=object, UtilityCode=object, EncodedString=object,
absolute_path_length=cython.Py_ssize_t, error_type=object) absolute_path_length=cython.Py_ssize_t, error_type=object, _py_int_types=object)
import sys, os, copy import sys, os, copy
from itertools import chain from itertools import chain
if sys.version_info[0] >= 3:
_py_int_types = int
else:
_py_int_types = (int, long)
from . import Builtin from . import Builtin
from .Errors import error, warning, InternalError, CompileError from .Errors import error, warning, InternalError, CompileError
from . import Naming from . import Naming
...@@ -4951,7 +4956,7 @@ class SingleAssignmentNode(AssignmentNode): ...@@ -4951,7 +4956,7 @@ class SingleAssignmentNode(AssignmentNode):
if node.type.is_array and node.type.size: if node.type.is_array and node.type.size:
stop_node = ExprNodes.IntNode( stop_node = ExprNodes.IntNode(
self.pos, value=str(node.type.size), self.pos, value=str(node.type.size),
constant_result=(node.type.size if isinstance(node.type.size, (int, long)) constant_result=(node.type.size if isinstance(node.type.size, _py_int_types)
else ExprNodes.constant_value_not_set)) else ExprNodes.constant_value_not_set))
else: else:
error(self.pos, "C array iteration requires known end index") error(self.pos, "C array iteration requires known end index")
...@@ -4977,7 +4982,7 @@ class SingleAssignmentNode(AssignmentNode): ...@@ -4977,7 +4982,7 @@ class SingleAssignmentNode(AssignmentNode):
elif node.type.is_array: elif node.type.is_array:
slice_size = node.type.size slice_size = node.type.size
if not isinstance(slice_size, (int, long)): if not isinstance(slice_size, _py_int_types):
return # might still work when coercing to Python return # might still work when coercing to Python
else: else:
return return
......
from __future__ import absolute_import from __future__ import absolute_import
import sys
import copy
import codecs
from . import TypeSlots from . import TypeSlots
from .ExprNodes import not_a_constant from .ExprNodes import not_a_constant
import cython import cython
cython.declare(UtilityCode=object, EncodedString=object, BytesLiteral=object, cython.declare(UtilityCode=object, EncodedString=object, BytesLiteral=object,
Nodes=object, ExprNodes=object, PyrexTypes=object, Builtin=object, Nodes=object, ExprNodes=object, PyrexTypes=object, Builtin=object,
UtilNodes=object) UtilNodes=object, _py_int_types=object)
if sys.version_info[0] >= 3:
_py_int_types = int
else:
_py_int_types = (int, long)
from . import Nodes from . import Nodes
from . import ExprNodes from . import ExprNodes
...@@ -20,9 +29,6 @@ from .StringEncoding import EncodedString, BytesLiteral ...@@ -20,9 +29,6 @@ from .StringEncoding import EncodedString, BytesLiteral
from .Errors import error from .Errors import error
from .ParseTreeTransforms import SkipDeclarations from .ParseTreeTransforms import SkipDeclarations
import copy
import codecs
try: try:
from __builtin__ import reduce from __builtin__ import reduce
except ImportError: except ImportError:
...@@ -444,7 +450,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -444,7 +450,7 @@ class IterationTransform(Visitor.EnvTransform):
stop = filter_none_node(index.stop) stop = filter_none_node(index.stop)
step = filter_none_node(index.step) step = filter_none_node(index.step)
if step: if step:
if not isinstance(step.constant_result, (int,long)) \ if not isinstance(step.constant_result, _py_int_types) \
or step.constant_result == 0 \ or step.constant_result == 0 \
or step.constant_result > 0 and not stop \ or step.constant_result > 0 and not stop \
or step.constant_result < 0 and not start: or step.constant_result < 0 and not start:
...@@ -683,7 +689,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -683,7 +689,7 @@ class IterationTransform(Visitor.EnvTransform):
else: else:
step = args[2] step = args[2]
step_pos = step.pos step_pos = step.pos
if not isinstance(step.constant_result, (int, long)): if not isinstance(step.constant_result, _py_int_types):
# cannot determine step direction # cannot determine step direction
return node return node
step_value = step.constant_result step_value = step.constant_result
...@@ -708,8 +714,8 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -708,8 +714,8 @@ class IterationTransform(Visitor.EnvTransform):
bound1, bound2 = bound2, bound1 bound1, bound2 = bound2, bound1
abs_step = abs(step_value) abs_step = abs(step_value)
if abs_step != 1: if abs_step != 1:
if (isinstance(bound1.constant_result, (int, long)) and if (isinstance(bound1.constant_result, _py_int_types) and
isinstance(bound2.constant_result, (int, long))): isinstance(bound2.constant_result, _py_int_types)):
# calculate final bounds now # calculate final bounds now
if step_value < 0: if step_value < 0:
begin_value = bound2.constant_result begin_value = bound2.constant_result
...@@ -3852,12 +3858,12 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -3852,12 +3858,12 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
def _calculate_constant_seq(self, node, sequence_node, factor): def _calculate_constant_seq(self, node, sequence_node, factor):
if factor.constant_result != 1 and sequence_node.args: if factor.constant_result != 1 and sequence_node.args:
if isinstance(factor.constant_result, (int, long)) and factor.constant_result <= 0: if isinstance(factor.constant_result, _py_int_types) and factor.constant_result <= 0:
del sequence_node.args[:] del sequence_node.args[:]
sequence_node.mult_factor = None sequence_node.mult_factor = None
elif sequence_node.mult_factor is not None: elif sequence_node.mult_factor is not None:
if (isinstance(factor.constant_result, (int, long)) and if (isinstance(factor.constant_result, _py_int_types) and
isinstance(sequence_node.mult_factor.constant_result, (int, long))): isinstance(sequence_node.mult_factor.constant_result, _py_int_types)):
value = sequence_node.mult_factor.constant_result * factor.constant_result value = sequence_node.mult_factor.constant_result * factor.constant_result
sequence_node.mult_factor = ExprNodes.IntNode( sequence_node.mult_factor = ExprNodes.IntNode(
sequence_node.mult_factor.pos, sequence_node.mult_factor.pos,
......
...@@ -13,9 +13,10 @@ cython.declare(Nodes=object, ExprNodes=object, EncodedString=object, ...@@ -13,9 +13,10 @@ cython.declare(Nodes=object, ExprNodes=object, EncodedString=object,
Future=object, Options=object, error=object, warning=object, Future=object, Options=object, error=object, warning=object,
Builtin=object, ModuleNode=object, Utils=object, Builtin=object, ModuleNode=object, Utils=object,
re=object, _unicode=object, _bytes=object, re=object, _unicode=object, _bytes=object,
partial=object, reduce=object) partial=object, reduce=object, _IS_PY3=cython.bint)
import re import re
import sys
from unicodedata import lookup as lookup_unicodechar from unicodedata import lookup as lookup_unicodechar
from functools import partial, reduce from functools import partial, reduce
...@@ -31,6 +32,8 @@ from .. import Utils ...@@ -31,6 +32,8 @@ from .. import Utils
from . import Future from . import Future
from . import Options from . import Options
_IS_PY3 = sys.version_info[0] >= 3
class Ctx(object): class Ctx(object):
# Parsing context # Parsing context
...@@ -759,8 +762,6 @@ def wrap_compile_time_constant(pos, value): ...@@ -759,8 +762,6 @@ def wrap_compile_time_constant(pos, value):
return ExprNodes.BoolNode(pos, value=value) return ExprNodes.BoolNode(pos, value=value)
elif isinstance(value, int): elif isinstance(value, int):
return ExprNodes.IntNode(pos, value=rep) return ExprNodes.IntNode(pos, value=rep)
elif isinstance(value, long):
return ExprNodes.IntNode(pos, value=rep, longness="L")
elif isinstance(value, float): elif isinstance(value, float):
return ExprNodes.FloatNode(pos, value=rep) return ExprNodes.FloatNode(pos, value=rep)
elif isinstance(value, _unicode): elif isinstance(value, _unicode):
...@@ -775,6 +776,8 @@ def wrap_compile_time_constant(pos, value): ...@@ -775,6 +776,8 @@ def wrap_compile_time_constant(pos, value):
else: else:
# error already reported # error already reported
return None return None
elif not _IS_PY3 and isinstance(value, long):
return ExprNodes.IntNode(pos, value=rep, longness="L")
error(pos, "Invalid type for compile-time constant: %r (type %s)" error(pos, "Invalid type for compile-time constant: %r (type %s)"
% (value, value.__class__.__name__)) % (value, value.__class__.__name__))
return None return None
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import sys
import inspect import inspect
from . import TypeSlots from . import TypeSlots
...@@ -19,6 +20,14 @@ from . import Future ...@@ -19,6 +20,14 @@ from . import Future
import cython import cython
cython.declare(_PRINTABLE=tuple)
if sys.version_info >= 3:
_PRINTABLE = (bytes, str, int, float)
else:
_PRINTABLE = (str, unicode, long, int, float)
class TreeVisitor(object): class TreeVisitor(object):
""" """
Base class for writing visitors for a Cython tree, contains utilities for Base class for writing visitors for a Cython tree, contains utilities for
...@@ -94,7 +103,7 @@ class TreeVisitor(object): ...@@ -94,7 +103,7 @@ class TreeVisitor(object):
continue continue
elif isinstance(value, list): elif isinstance(value, list):
value = u'[...]/%d' % len(value) value = u'[...]/%d' % len(value)
elif not isinstance(value, (str, unicode, long, int, float)): elif not isinstance(value, _PRINTABLE):
continue continue
else: else:
value = repr(value) value = repr(value)
......
...@@ -405,7 +405,7 @@ class CythonBase(object): ...@@ -405,7 +405,7 @@ class CythonBase(object):
# Closed over free variable # Closed over free variable
if cur_lineno > cython_func.lineno: if cur_lineno > cython_func.lineno:
if cyvar.type == PythonObject: if cyvar.type == PythonObject:
return long(gdb.parse_and_eval(cyvar.cname)) return int(gdb.parse_and_eval(cyvar.cname))
return True return True
return False return False
......
...@@ -269,7 +269,7 @@ class PyObjectPtr(object): ...@@ -269,7 +269,7 @@ class PyObjectPtr(object):
return PyTypeObjectPtr(self.field('ob_type')) return PyTypeObjectPtr(self.field('ob_type'))
def is_null(self): def is_null(self):
return 0 == long(self._gdbval) return 0 == int(self._gdbval)
def is_optimized_out(self): def is_optimized_out(self):
''' '''
...@@ -330,7 +330,7 @@ class PyObjectPtr(object): ...@@ -330,7 +330,7 @@ class PyObjectPtr(object):
return '<%s at remote 0x%x>' % (self.tp_name, self.address) return '<%s at remote 0x%x>' % (self.tp_name, self.address)
return FakeRepr(self.safe_tp_name(), return FakeRepr(self.safe_tp_name(),
long(self._gdbval)) int(self._gdbval))
def write_repr(self, out, visited): def write_repr(self, out, visited):
''' '''
...@@ -432,7 +432,7 @@ class PyObjectPtr(object): ...@@ -432,7 +432,7 @@ class PyObjectPtr(object):
return gdb.lookup_type(cls._typename).pointer() return gdb.lookup_type(cls._typename).pointer()
def as_address(self): def as_address(self):
return long(self._gdbval) return int(self._gdbval)
class PyVarObjectPtr(PyObjectPtr): class PyVarObjectPtr(PyObjectPtr):
...@@ -553,7 +553,7 @@ class PyTypeObjectPtr(PyObjectPtr): ...@@ -553,7 +553,7 @@ class PyTypeObjectPtr(PyObjectPtr):
tp_name = self.safe_tp_name() tp_name = self.safe_tp_name()
# New-style class: # New-style class:
return InstanceProxy(tp_name, attr_dict, long(self._gdbval)) return InstanceProxy(tp_name, attr_dict, int(self._gdbval))
def write_repr(self, out, visited): def write_repr(self, out, visited):
# Guard against infinite loops: # Guard against infinite loops:
...@@ -751,7 +751,7 @@ class PyInstanceObjectPtr(PyObjectPtr): ...@@ -751,7 +751,7 @@ class PyInstanceObjectPtr(PyObjectPtr):
in_dict = self.pyop_field('in_dict').proxyval(visited) in_dict = self.pyop_field('in_dict').proxyval(visited)
# Old-style class: # Old-style class:
return InstanceProxy(cl_name, in_dict, long(self._gdbval)) return InstanceProxy(cl_name, in_dict, int(self._gdbval))
def write_repr(self, out, visited): def write_repr(self, out, visited):
# Guard against infinite loops: # Guard against infinite loops:
...@@ -836,9 +836,9 @@ class PyLongObjectPtr(PyObjectPtr): ...@@ -836,9 +836,9 @@ class PyLongObjectPtr(PyObjectPtr):
#define PyLong_SHIFT 30 #define PyLong_SHIFT 30
#define PyLong_SHIFT 15 #define PyLong_SHIFT 15
''' '''
ob_size = long(self.field('ob_size')) ob_size = int(self.field('ob_size'))
if ob_size == 0: if ob_size == 0:
return long(0) return int(0)
ob_digit = self.field('ob_digit') ob_digit = self.field('ob_digit')
...@@ -971,7 +971,7 @@ class PyFrameObjectPtr(PyObjectPtr): ...@@ -971,7 +971,7 @@ class PyFrameObjectPtr(PyObjectPtr):
if self.is_optimized_out(): if self.is_optimized_out():
return None return None
f_trace = self.field('f_trace') f_trace = self.field('f_trace')
if long(f_trace) != 0: if int(f_trace) != 0:
# we have a non-NULL f_trace: # we have a non-NULL f_trace:
return self.f_lineno return self.f_lineno
else: else:
...@@ -1203,7 +1203,7 @@ class PyUnicodeObjectPtr(PyObjectPtr): ...@@ -1203,7 +1203,7 @@ class PyUnicodeObjectPtr(PyObjectPtr):
# From unicodeobject.h: # From unicodeobject.h:
# Py_ssize_t length; /* Length of raw Unicode data in buffer */ # Py_ssize_t length; /* Length of raw Unicode data in buffer */
# Py_UNICODE *str; /* Raw Unicode buffer */ # Py_UNICODE *str; /* Raw Unicode buffer */
field_length = long(self.field('length')) field_length = int(self.field('length'))
field_str = self.field('str') field_str = self.field('str')
# Gather a list of ints from the Py_UNICODE array; these are either # Gather a list of ints from the Py_UNICODE array; these are either
...@@ -2321,11 +2321,11 @@ def _pointervalue(gdbval): ...@@ -2321,11 +2321,11 @@ def _pointervalue(gdbval):
""" """
# don't convert with int() as it will raise a RuntimeError # don't convert with int() as it will raise a RuntimeError
if gdbval.address is not None: if gdbval.address is not None:
return long(gdbval.address) return int(gdbval.address)
else: else:
# the address attribute is None sometimes, in which case we can # the address attribute is None sometimes, in which case we can
# still convert the pointer to an int # still convert the pointer to an int
return long(gdbval) return int(gdbval)
def pointervalue(gdbval): def pointervalue(gdbval):
...@@ -2517,7 +2517,7 @@ class FixGdbCommand(gdb.Command): ...@@ -2517,7 +2517,7 @@ class FixGdbCommand(gdb.Command):
warnings.filterwarnings('ignore', r'.*', RuntimeWarning, warnings.filterwarnings('ignore', r'.*', RuntimeWarning,
re.escape(__name__)) re.escape(__name__))
try: try:
long(gdb.parse_and_eval("(void *) 0")) == 0 int(gdb.parse_and_eval("(void *) 0")) == 0
except RuntimeError: except RuntimeError:
pass pass
# warnings.resetwarnings() # warnings.resetwarnings()
......
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