internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: cython/cython

Issue:
Cannot copy C arrays in nogil functions
This code:

```
cdef void foo() nogil:
    cdef double[16] x
    cdef double[16] y
    y[:] = x[:]
    y = x
```

throws the compile time error "Slicing Python object not allowed without gil" for both assignments. However, the generated code in both cases is a simple memcpy and doesn't require the GIL.


Discussion:

Resolving patch:
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -4583,7 +4583,10 @@ def analyse_types(self, env, getting=True):
         self.is_temp = 1
         return self
 
-    nogil_check = Node.gil_error
+    def nogil_check(self, env):
+        if not self.base.type.is_array:
+            self.gil_error()
+
     gil_message = "Slicing Python object"
 
     get_slice_utility_code = TempitaUtilityCode.load(


Test patch:
diff --git a/tests/compile/nogil_array.pyx b/tests/compile/nogil_array.pyx
new file mode 100644
--- /dev/null
+++ b/tests/compile/nogil_array.pyx
@@ -0,0 +1,8 @@
+# mode: compile
+
+cdef void foo() nogil:
+    cdef double[16] x
+    cdef double[16] y
+    # both of these operations should be allowed in a nogil function
+    y[:] = x[:]
+    y = x
Repository: cython/cython

Issue:
dict.pop() calls not optimized
`dict.pop()` could be optimized as calling `_PyDict_Pop()`, but instead it calls the Python-facing method object.


Discussion:

Resolving patch:
diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py
--- a/Cython/Compiler/Optimize.py
+++ b/Cython/Compiler/Optimize.py
@@ -2913,6 +2913,27 @@ def _handle_simple_method_dict_setdefault(self, node, function, args, is_unbound
             may_return_none=True,
             utility_code=load_c_utility('dict_setdefault'))
 
+    PyDict_Pop_func_type = PyrexTypes.CFuncType(
+        PyrexTypes.py_object_type, [
+            PyrexTypes.CFuncTypeArg("dict", PyrexTypes.py_object_type, None),
+            PyrexTypes.CFuncTypeArg("key", PyrexTypes.py_object_type, None),
+            PyrexTypes.CFuncTypeArg("default", PyrexTypes.py_object_type, None),
+            ])
+
+    def _handle_simple_method_dict_pop(self, node, function, args, is_unbound_method):
+        """Replace dict.pop() by a call to _PyDict_Pop().
+        """
+        if len(args) == 2:
+            args.append(ExprNodes.NullNode(node.pos))
+        elif len(args) != 3:
+            self._error_wrong_arg_count('dict.pop', node, args, "2 or 3")
+            return node
+
+        return self._substitute_method_call(
+            node, function,
+            "_PyDict_Pop", self.PyDict_Pop_func_type,
+            'pop', is_unbound_method, args)
+
     Pyx_PyInt_BinopInt_func_type = PyrexTypes.CFuncType(
         PyrexTypes.py_object_type, [
             PyrexTypes.CFuncTypeArg("op1", PyrexTypes.py_object_type, None),


Test patch:
diff --git a/tests/run/dict_pop.pyx b/tests/run/dict_pop.pyx
new file mode 100644
--- /dev/null
+++ b/tests/run/dict_pop.pyx
@@ -0,0 +1,34 @@
+
+cimport cython
+
+@cython.test_assert_path_exists("//PythonCapiCallNode")
+@cython.test_fail_if_path_exists("//AttributeNode")
+def dict_pop(dict d, key):
+    """
+    >>> d = { 1: 10, 2: 20 }
+    >>> dict_pop(d, 1)
+    (10, {2: 20})
+    >>> dict_pop(d, 3)
+    Traceback (most recent call last):
+    KeyError: 3
+    >>> dict_pop(d, 2)
+    (20, {})
+    """
+    return d.pop(key), d
+
+
+@cython.test_assert_path_exists("//PythonCapiCallNode")
+@cython.test_fail_if_path_exists("//AttributeNode")
+def dict_pop_default(dict d, key, default):
+    """
+    >>> d = { 1: 10, 2: 20 }
+    >>> dict_pop_default(d, 1, "default")
+    (10, {2: 20})
+    >>> dict_pop_default(d, 3, None)
+    (None, {2: 20})
+    >>> dict_pop_default(d, 3, "default")
+    ('default', {2: 20})
+    >>> dict_pop_default(d, 2, "default")
+    (20, {})
+    """
+    return d.pop(key, default), d
Repository: cython/cython

Issue:
No .c line in traceback during module init
Since the introduction of the disabling of `.c` lines in tracebacks, such line numbers are unconditionally not shown during the module init code:
```
      __Pyx_AddTraceback("init sage.structure.coerce_maps", 0, __pyx_lineno, __pyx_filename);
```
Since I find these `.c` line numbers really handy for debugging, I consider it a serious regression.


Discussion:
I guess the reason for that disabling should be fixed anyway by #2199.

Resolving patch:
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -2459,10 +2459,9 @@ def generate_module_init_func(self, imported_modules, env, code):
         code.put_label(code.error_label)
         for cname, type in code.funcstate.all_managed_temps():
             code.put_xdecref(cname, type)
-        # module state might not be ready for traceback generation with C-line handling yet
         code.putln('if (%s) {' % env.module_cname)
         code.putln('if (%s) {' % env.module_dict_cname)
-        code.put_add_traceback("init %s" % env.qualified_name, include_cline=False)
+        code.put_add_traceback("init %s" % env.qualified_name)
         code.globalstate.use_utility_code(Nodes.traceback_utility_code)
         # Module reference and module dict are in global variables which might still be needed
         # for cleanup, atexit code, etc., so leaking is better than crashing.


Test patch:
Repository: cython/cython

Issue:
Cython embedsignature gives useless information for memoryviews in Sphinx
Hi,
The embedsignature option in Cython gives call signature information for Sphinx to document, but it is not useful when describing memoryviews. 

This is the source:
```
def foo(double[::1] n):
    ....
```
And this is the call signature printed in Sphinx

> foo(__Pyx_memviewslice n)

So it loses the type information, along with the dimension and stride. Is it possible to add this in? Or is this something that should be addressed from the Sphinx-autodoc side? 

Thanks!


Discussion:
Definitely a bug, thanks for the report. The code for this is in the `EmbedSignature` tree transformation in `AutoDocTransform.py`, probably easy to fix. Want to give it a try?

Resolving patch:
diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py
--- a/Cython/Compiler/PyrexTypes.py
+++ b/Cython/Compiler/PyrexTypes.py
@@ -653,8 +653,9 @@ def declaration_code(self, entity_code,
         assert not pyrex
         assert not dll_linkage
         from . import MemoryView
+        base_code = self.__str__() if for_display else MemoryView.memviewslice_cname
         return self.base_declaration_code(
-                MemoryView.memviewslice_cname,
+                base_code,
                 entity_code)
 
     def attributes_known(self):


Test patch:
Repository: cython/cython

Issue:
Cython embedsignature gives useless information for memoryviews in Sphinx
Hi,
The embedsignature option in Cython gives call signature information for Sphinx to document, but it is not useful when describing memoryviews. 

This is the source:
```
def foo(double[::1] n):
    ....
```
And this is the call signature printed in Sphinx

> foo(__Pyx_memviewslice n)

So it loses the type information, along with the dimension and stride. Is it possible to add this in? Or is this something that should be addressed from the Sphinx-autodoc side? 

Thanks!


Discussion:
Definitely a bug, thanks for the report. The code for this is in the `EmbedSignature` tree transformation in `AutoDocTransform.py`, probably easy to fix. Want to give it a try?

Resolving patch:
diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py
--- a/Cython/Compiler/PyrexTypes.py
+++ b/Cython/Compiler/PyrexTypes.py
@@ -653,8 +653,9 @@ def declaration_code(self, entity_code,
         assert not pyrex
         assert not dll_linkage
         from . import MemoryView
+        base_code = str(self) if for_display else MemoryView.memviewslice_cname
         return self.base_declaration_code(
-                MemoryView.memviewslice_cname,
+                base_code,
                 entity_code)
 
     def attributes_known(self):


Test patch:
diff --git a/tests/run/embedsignatures.pyx b/tests/run/embedsignatures.pyx
--- a/tests/run/embedsignatures.pyx
+++ b/tests/run/embedsignatures.pyx
@@ -428,6 +428,7 @@ cdef class Foo:
     def m28(self, a: list(range(3))[::1]): pass
     def m29(self, a: list(range(3))[0:1:1]): pass
     def m30(self, a: list(range(3))[7, 3:2:1, ...]): pass
+    def m31(self, double[::1] a): pass
 
 __doc__ += ur"""
 >>> print(Foo.m00.__doc__)
@@ -522,4 +523,7 @@ Foo.m29(self, a: list(range(3))[0:1:1])
 
 >>> print(Foo.m30.__doc__)
 Foo.m30(self, a: list(range(3))[7, 3:2:1, ...])
+
+>>> print(Foo.m31.__doc__)
+Foo.m31(self, double[::1] a)
 """
Repository: cython/cython

Issue:
Generates invalid C when omitting self in lambda
I'm using Cython version 0.29.7.

Part of the error message (full message attached: [output.txt](https://github.com/cython/cython/files/3207113/output.txt)):
```
AA/bug.c:830:57: error: expected identifier or ‘(’ before ‘.’ token
 struct __pyx_obj_2AA_3bug___pyx_scope_struct____pyx_base.func;
```

Here's a quick example to reproduce, including a workaround.

```
# cython: language_level=3
cdef class FBase():
    def __init__(self):
        pass
        
    def __cinit__(self):
        pass
        
    cdef func(self, whatever):
        pass
        

cdef class Bug(FBase):
    def __init__(self):
        pass
        
    cdef check(self, x):
        return x
        
    cdef func(self, whatever):
        a = [1, 2, 3]
        min(a, key=lambda x: self.check(x))

        # This generates correct C, but doesn't work in Python:
        # min(a, key=lambda self, x: self.check(x))

        # Workaround:
        # import functools
        # min(a, key=functools.partial(lambda self, x: self.check(x), self))
```




Discussion:

Resolving patch:
diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py
--- a/Cython/Compiler/ParseTreeTransforms.py
+++ b/Cython/Compiler/ParseTreeTransforms.py
@@ -2738,9 +2738,12 @@ def create_class_from_scope(self, node, target_module_scope, inner_node=None):
             node.needs_outer_scope = True
             return
 
+        # entry.cname can contain periods (eg. a derived C method of a class).
+        # We want to use the cname as part of a C struct name, so we replace
+        # periods with double underscores.
         as_name = '%s_%s' % (
             target_module_scope.next_id(Naming.closure_class_prefix),
-            node.entry.cname)
+            node.entry.cname.replace('.','__'))
 
         entry = target_module_scope.declare_c_class(
             name=as_name, pos=node.pos, defining=True,


Test patch:
diff --git a/tests/run/closure_in_derived_class_T2967.pyx b/tests/run/closure_in_derived_class_T2967.pyx
new file mode 100644
--- /dev/null
+++ b/tests/run/closure_in_derived_class_T2967.pyx
@@ -0,0 +1,18 @@
+# mode: run
+# tag: closures
+# ticket: 2967
+
+cdef class BaseClass:
+    cdef func(self):
+        pass
+cdef class ClosureInsideExtensionClass(BaseClass):
+    """
+    >>> y = ClosureInsideExtensionClass(42)
+    >>> y.test(42)
+    43
+    """
+    cdef func(self):
+        a = 1
+        return (lambda x : x+a)
+    def test(self, b):
+        return self.func()(b)
Repository: cython/cython

Issue:
cdiv and cmod incorrect?
I was looking at the definitions of `cdiv` and `cmod` in Shadow.py. These seem to give incorrect results for some operands. For example, in C99:

```
4 / -4 == -1    4 % -4 == 0
4 / -2 == -2    4 % -2 == 0
4 / -1 == -4    4 % -1 == 0
```

But these functions would return:

```
cdiv(4, -4) == 0    cmod(4, -4) == 4
cdiv(4, -2) == -1    cmod(4, -2) == 2
cdiv(4, -1) == -3    cmod(4, -1) == 1
```

That's based on just running those definitions in the Python interpreter. Perhaps Cython handles them specially, and doesn't in fact give the incorrect results above. Still, why not include correct Python code? The following would work:

```
def cdiv(a, b):
    if a < 0:
        a = -a
        b = -b
    if b < 0:
        return (a + b + 1) // b
    return a // b

def cmod(a, b):
    r = a % b
    if (a*b) < 0 and r: r -= b
    return r
```

Sorry if this is just me misunderstanding some magic behind the scenes stuff.


Discussion:
Thanks for looking at this! Please feel free to send a PR, or if you don't have the time I can fix them. 
You might want to make sure that your new functions work properly with the test found here:
https://github.com/cython/cython/blob/master/tests/run/cdivision_CEP_516.pyx#L27-L28

Resolving patch:
diff --git a/Cython/Shadow.py b/Cython/Shadow.py
--- a/Cython/Shadow.py
+++ b/Cython/Shadow.py
@@ -146,14 +146,16 @@ def compile(f):
 # Special functions
 
 def cdiv(a, b):
-    q = a / b
-    if q < 0:
-        q += 1
-    return q
+    if a < 0:
+        a = -a
+        b = -b
+    if b < 0:
+        return (a + b + 1) // b
+    return a // b
 
 def cmod(a, b):
     r = a % b
-    if (a*b) < 0:
+    if (a * b) < 0 and r:
         r -= b
     return r
 


Test patch:
diff --git a/tests/run/cdivision_CEP_516.pyx b/tests/run/cdivision_CEP_516.pyx
--- a/tests/run/cdivision_CEP_516.pyx
+++ b/tests/run/cdivision_CEP_516.pyx
@@ -27,6 +27,9 @@ True
 >>> [test_cdiv_cmod(a, b) for a, b in v]
 [(1, 7), (-1, -7), (1, -7), (-1, 7)]
 
+>>> [test_cdiv_cmod(a, b) for a, b in [(4, -4), (4, -2), (4, -1)]]
+[(-1, 0), (-2, 0), (-4, 0)]
+
 >>> all([mod_int_py(a,b) == a % b for a in range(-10, 10) for b in range(-10, 10) if b != 0])
 True
 >>> all([div_int_py(a,b) == a // b for a in range(-10, 10) for b in range(-10, 10) if b != 0])
Repository: cython/cython

Issue:
Unexpected propagation of Cython's build_ext options
From, https://github.com/cython/cython/blob/ee1b02191853e40a0078114c29de5cf7d794ba66/Cython/Distutils/old_build_ext.py#L87-L89 Cython's `build_ext` starts using and modifying distutils' options attributes directly instead of making a copy of them.

If using setuptools' `setup` function (most likely the case) and Cython is installed then setuptools will successfully (and unconditionally) [import Cython's `build_ext`](https://github.com/pypa/setuptools/blob/af4e065b58789fd67fdbc897af981b670f01099b/setuptools/command/build_ext.py#L17), therefore Cython's modifications to these lists do happen and is, more than anything, confusing whenever using directly or subclassing distutils' `build_ext` that these options appear out of "nowhere".


Discussion:

Resolving patch:
diff --git a/Cython/Distutils/old_build_ext.py b/Cython/Distutils/old_build_ext.py
--- a/Cython/Distutils/old_build_ext.py
+++ b/Cython/Distutils/old_build_ext.py
@@ -84,9 +84,9 @@ class old_build_ext(_build_ext.build_ext):
     description = "build C/C++ and Cython extensions (compile/link to build directory)"
 
     sep_by = _build_ext.build_ext.sep_by
-    user_options = _build_ext.build_ext.user_options
-    boolean_options = _build_ext.build_ext.boolean_options
-    help_options = _build_ext.build_ext.help_options
+    user_options = _build_ext.build_ext.user_options[:]
+    boolean_options = _build_ext.build_ext.boolean_options[:]
+    help_options = _build_ext.build_ext.help_options[:]
 
     # Add the pyrex specific data.
     user_options.extend([


Test patch:
Repository: cython/cython

Issue:
compiler crash with ctuple as property setter argument
* Cython version: 0.29.12
* Compiler used: Visual Studio 2015 (MSVC)
* Python version: Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)]
 on win32

Following small code example, named crash.pyx:
```
cdef class Foo:
  property bar:
    def __set__(Foo self, (int, int) value):
      print(value[0], value[1])
```

Running with python -c "import pyximport;pyximport.install();import crash" cythonizes properly, but compilation crashes:
...\.pyxbld\temp.win32-3.6\Release\pyrex\crash.c(1286): error C2440: "Typumwandlung": "__pyx_ctuple_int__and_int" kann nicht in "__pyx_ctuple_int__and_int" konvertiert werden
...\.pyxbld\temp.win32-3.6\Release\pyrex\crash.c(1286): error C2198: "__pyx_pf_5crash_3Foo_3bar___set__": Nicht gengend Argumente fr Aufruf.

Cythonized crash.c file attached.
Problem is not pyximport-related and also crashes when used "normally".
[crash.zip](https://github.com/cython/cython/files/3376458/crash.zip)



Discussion:

Resolving patch:
diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py
--- a/Cython/Compiler/PyrexTypes.py
+++ b/Cython/Compiler/PyrexTypes.py
@@ -4207,6 +4207,9 @@ def create_from_py_utility_code(self, env):
         env.use_utility_code(self._convert_from_py_code)
         return True
 
+    def cast_code(self, expr_code):
+        return expr_code
+
 
 def c_tuple_type(components):
     components = tuple(components)


Test patch:
diff --git a/tests/windows_bugs.txt b/tests/windows_bugs.txt
--- a/tests/windows_bugs.txt
+++ b/tests/windows_bugs.txt
@@ -6,7 +6,6 @@ initial_file_path
 package_compilation
 
 carray_coercion
-ctuple
 int_float_builtins_as_casts_T400
 int_float_builtins_as_casts_T400_long_double
 list_pop
Repository: cython/cython

Issue:
Referencing local variable before assignment is safe inside sizeof
Referencing a variable before it is assigned to anything is usually a bad idea.
It is, however, perfectly valid to do so inside the `sizeof` operator. It's even a common pattern in C when using `malloc` / `calloc`.

This program produce a warning, while it should probably not.
```cython
def main():
    cdef int x
    print(sizeof(x))

main()
```



Discussion:
True. Can't say how difficult it is to fix, though. Maybe we could special-case `sizeof()`, and probably also `typeid()`, `varargs()` and maybe others(?) in the control flow analysis somehow, so that they won't consider the variable an actual usage.

Resolving patch:
diff --git a/Cython/Compiler/FlowControl.py b/Cython/Compiler/FlowControl.py
--- a/Cython/Compiler/FlowControl.py
+++ b/Cython/Compiler/FlowControl.py
@@ -885,6 +885,12 @@ def visit_Node(self, node):
         self.mark_position(node)
         return node
 
+    def visit_SizeofVarNode(self, node):
+        return node
+
+    def visit_TypeidNode(self, node):
+        return node
+
     def visit_IfStatNode(self, node):
         next_block = self.flow.newblock()
         parent = self.flow.block


Test patch:
diff --git a/tests/errors/w_uninitialized.pyx b/tests/errors/w_uninitialized.pyx
--- a/tests/errors/w_uninitialized.pyx
+++ b/tests/errors/w_uninitialized.pyx
@@ -112,6 +112,10 @@ def class_py3k_args():
     args = []
     kwargs = {}
 
+def uninitialized_in_sizeof():
+    cdef int i
+    print sizeof(i)
+
 _ERRORS = """
 6:10: local variable 'a' referenced before assignment
 12:11: local variable 'a' might be referenced before assignment
diff --git a/tests/errors/w_uninitialized_cpp.pyx b/tests/errors/w_uninitialized_cpp.pyx
new file mode 100644
--- /dev/null
+++ b/tests/errors/w_uninitialized_cpp.pyx
@@ -0,0 +1,12 @@
+# cython: warn.maybe_uninitialized=True
+# mode: error
+# tag: cpp, werror
+
+from cython.operator import typeid
+
+def uninitialized_in_typeid():
+    cdef int i
+    print typeid(i) == typeid(i)
+
+_ERRORS = """
+"""
Repository: cython/cython

Issue:
Compiler crash: `AttributeError: 'set' object has no attribute 'cf_is_null'`
I am getting a compiler crash trying to install a python project:
```
Compiler crash traceback from this point on:
  File "Cython/Compiler/Visitor.py", line 180, in Cython.Compiler.Visitor.TreeVisitor._visit
  File "/home/ellie/.local/lib/python3.8/site-packages/Cython/Compiler/Optimize.py", line 2012, in visit_SimpleCallNode
    function = self.get_constant_value_node(function_name)
  File "/home/ellie/.local/lib/python3.8/site-packages/Cython/Compiler/Optimize.py", line 1996, in get_constant_value_node
    if name_node.cf_state.cf_is_null:
AttributeError: 'set' object has no attribute 'cf_is_null'
```
This is the crashing line:
\<link outdated\>
This is the version of Cython I'm using:
```
$ pip3 show Cython
Name: Cython
Version: 0.29.20
Summary: The Cython compiler for writing C extensions for the Python language.
Home-page: http://cython.org/
Author: Robert Bradshaw, Stefan Behnel, Dag Seljebotn, Greg Ewing, et al.
Author-email: cython-devel@python.org
License: Apache
Location: /home/user/.local/lib/python3.8/site-packages
Requires: 
Required-by:
```

Pretty sure it worked with a previous Cython version many months ago, so possibly a regression...? Not sure


Discussion:
It definitely looks like a bug. Here's a simplified version of your code that reproduces it:

```
def run(done_callback):
    try:
        [] # anything
    finally:
       done_callback()
```

As far as I can tell being in the `finally` block is needed for the bug to trigger. If it's in try/except/else/not-in-a-try-block then you don't see it.

`cf_state` looks to be initially made a `set`, then replaced with a `ControlFlowState` object in `FlowControl.check_definitions`. It seems like in this case it isn't be replaced correctly.

Unfortunately this is where I'm outsmarted, so I don't think I can fix it.
If it works for older versions, then `git bisect` could help to find how this was introduced.
bbef4d74841b7e979a45d9bbb59c5a1c733a55d7 - which makes sense because it was changing flow-control and finally

Resolving patch:
diff --git a/Cython/Compiler/FlowControl.py b/Cython/Compiler/FlowControl.py
--- a/Cython/Compiler/FlowControl.py
+++ b/Cython/Compiler/FlowControl.py
@@ -1220,6 +1220,7 @@ def visit_TryFinallyStatNode(self, node):
         if self.flow.loops:
             self.flow.loops[-1].exceptions.append(descr)
         self.flow.block = body_block
+        body_block.add_child(entry_point)
         self.flow.nextblock()
         self._visit(node.body)
         self.flow.exceptions.pop()


Test patch:
diff --git a/tests/compile/tryfinally.pyx b/tests/compile/tryfinally.pyx
--- a/tests/compile/tryfinally.pyx
+++ b/tests/compile/tryfinally.pyx
@@ -18,4 +18,11 @@ def f(a, b, c, x):
         finally:
             i = 42
 
+def use_name_in_finally(name):
+    # GH3712
+    try:
+        []
+    finally:
+        name()
+