From 213f561fd894924adbf33d83da272e9d80d3295e Mon Sep 17 00:00:00 2001
From: Robert Bradshaw <robertwb@math.washington.edu>
Date: Tue, 26 Aug 2008 00:06:52 -0700
Subject: [PATCH] long long indexing failed when sizeof(long long) <
 sizeof(Py_ssize_t)

---
 Cython/Compiler/ExprNodes.py  |  2 +-
 Cython/Compiler/PyrexTypes.py |  4 ++++
 tests/run/longlongindex.pyx   | 18 ++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 tests/run/longlongindex.pyx

diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index 253ff7493..1fd34af67 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -1423,7 +1423,7 @@ class IndexNode(ExprNode):
             elif not skip_child_analysis:
                 self.index.analyse_types(env)
             if self.base.type.is_pyobject:
-                if self.index.type.is_int:
+                if self.index.type.is_int and not self.index.type.is_longlong:
                     self.original_index_type = self.index.type
                     self.index = self.index.coerce_to(PyrexTypes.c_py_ssize_t_type, env).coerce_to_simple(env)
                     if getting:
diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py
index e2e7b455d..2561d9c71 100644
--- a/Cython/Compiler/PyrexTypes.py
+++ b/Cython/Compiler/PyrexTypes.py
@@ -29,6 +29,7 @@ class PyrexType(BaseType):
     #  is_extension_type     boolean     Is a Python extension type
     #  is_numeric            boolean     Is a C numeric type
     #  is_int                boolean     Is a C integer type
+    #  is_longlong           boolean     Is a long long or unsigned long long.
     #  is_float              boolean     Is a C floating point type
     #  is_void               boolean     Is the C void type
     #  is_array              boolean     Is a C array type
@@ -79,6 +80,7 @@ class PyrexType(BaseType):
     is_builtin_type = 0
     is_numeric = 0
     is_int = 0
+    is_longlong = 0
     is_float = 0
     is_void = 0
     is_array = 0
@@ -553,12 +555,14 @@ class CULongType(CUIntType):
 
 class CLongLongType(CUIntType):
 
+    is_longlong = 1
     to_py_function = "PyLong_FromLongLong"
     from_py_function = "__pyx_PyInt_AsLongLong"
 
 
 class CULongLongType(CUIntType):
 
+    is_longlong = 1
     to_py_function = "PyLong_FromUnsignedLongLong"
     from_py_function = "__pyx_PyInt_AsUnsignedLongLong"
 
diff --git a/tests/run/longlongindex.pyx b/tests/run/longlongindex.pyx
new file mode 100644
index 000000000..87dcfe5e8
--- /dev/null
+++ b/tests/run/longlongindex.pyx
@@ -0,0 +1,18 @@
+__doc__ = """
+    >>> D = set_longlong(2**40, 2**50, 2, "yelp")
+    >>> D[2**40]
+    'yelp'
+    >>> D[2**50]
+    'yelp'
+    >>> D[2]
+    'yelp'
+"""
+
+ctypedef long long foo
+
+def set_longlong(long long ob, foo x, long y, val):
+    tank = {}
+    tank[ob] = val
+    tank[x] = val
+    tank[y] = val
+    return tank
-- 
2.30.9