From 4b711c5600414b531253170aaa2dc669ac961002 Mon Sep 17 00:00:00 2001
From: Stefan Behnel <stefan_ml@behnel.de>
Date: Sat, 6 May 2017 08:03:01 +0200
Subject: [PATCH] include missing utility code when raising StopAsyncIteration

Closes #1692
---
 Cython/Compiler/Builtin.py | 9 ++++-----
 Cython/Compiler/Nodes.py   | 2 ++
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py
index d2b7782ac..f685faf96 100644
--- a/Cython/Compiler/Builtin.py
+++ b/Cython/Compiler/Builtin.py
@@ -21,6 +21,7 @@ pyexec_globals_utility_code = UtilityCode.load("PyExecGlobals", "Builtins.c")
 globals_utility_code = UtilityCode.load("Globals", "Builtins.c")
 
 builtin_utility_code = {
+    'StopAsyncIteration': UtilityCode.load_cached("StopAsyncIteration", "Coroutine.c"),
 }
 
 
@@ -326,6 +327,7 @@ builtin_types_table = [
                                     BuiltinMethod("pop",     "T",  "O", "PySet_Pop")]),
     ("frozenset", "PyFrozenSet_Type", []),
     ("Exception", "((PyTypeObject*)PyExc_Exception)[0]", []),
+    ("StopAsyncIteration", "((PyTypeObject*)__Pyx_PyExc_StopAsyncIteration)[0]", []),
 ]
 
 
@@ -381,6 +383,8 @@ def init_builtin_types():
             objstruct_cname = None
         elif name == 'Exception':
             objstruct_cname = "PyBaseExceptionObject"
+        elif name == 'StopAsyncIteration':
+            objstruct_cname = "PyBaseExceptionObject"
         else:
             objstruct_cname = 'Py%sObject' % name.capitalize()
         the_type = builtin_scope.declare_builtin_type(name, cname, utility, objstruct_cname)
@@ -407,11 +411,6 @@ def init_builtins():
         '__debug__', PyrexTypes.c_const_type(PyrexTypes.c_bint_type),
         pos=None, cname='(!Py_OptimizeFlag)', is_cdef=True)
 
-    entry = builtin_scope.declare_var(
-        'StopAsyncIteration', PyrexTypes.py_object_type,
-        pos=None, cname='__Pyx_PyExc_StopAsyncIteration')
-    entry.utility_code = UtilityCode.load_cached("StopAsyncIteration", "Coroutine.c")
-
     global list_type, tuple_type, dict_type, set_type, frozenset_type
     global bytes_type, str_type, unicode_type, basestring_type, slice_type
     global float_type, bool_type, type_type, complex_type, bytearray_type
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index b807cab8d..300455244 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -5667,6 +5667,8 @@ class RaiseStatNode(StatNode):
         if self.exc_type:
             self.exc_type.generate_evaluation_code(code)
             type_code = self.exc_type.py_result()
+            if self.exc_type.is_name:
+                code.globalstate.use_entry_utility_code(self.exc_type.entry)
         else:
             type_code = "0"
         if self.exc_value:
-- 
2.30.9