From b106213bd43af9ee1fadd527927d41f1bcc28d6f Mon Sep 17 00:00:00 2001
From: dalcinl <none@none>
Date: Sat, 10 Apr 2010 02:51:42 -0300
Subject: [PATCH] fix some testcases failing on Windows

---
 Cython/Compiler/Optimize.py         |  2 +-
 tests/compile/callingconvention.h   | 33 ++++++++++++++++++
 tests/compile/callingconvention.pyx |  4 +++
 tests/compile/declarations.h        | 53 +++++++++++++++++++++++++++++
 tests/compile/declarations.pyx      |  3 ++
 tests/compile/excvalcheck.h         | 13 +++++++
 tests/compile/excvalcheck.pyx       |  3 ++
 tests/compile/nogil.h               | 27 +++++++++++++--
 8 files changed, 135 insertions(+), 3 deletions(-)
 create mode 100644 tests/compile/callingconvention.h
 create mode 100644 tests/compile/declarations.h
 create mode 100644 tests/compile/excvalcheck.h

diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py
index 1917c9cf3..96ba5dfd4 100644
--- a/Cython/Compiler/Optimize.py
+++ b/Cython/Compiler/Optimize.py
@@ -2116,6 +2116,7 @@ impl = ""
 pop_utility_code = UtilityCode(
 proto = """
 static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
+    PyObject *r, *m;
 #if PY_VERSION_HEX >= 0x02040000
     if (likely(PyList_CheckExact(L))
             /* Check that both the size is positive and no reallocation shrinking needs to be done. */
@@ -2124,7 +2125,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
         return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
     }
 #endif
-    PyObject *r, *m;
     m = __Pyx_GetAttrString(L, "pop");
     if (!m) return NULL;
     r = PyObject_CallObject(m, NULL);
diff --git a/tests/compile/callingconvention.h b/tests/compile/callingconvention.h
new file mode 100644
index 000000000..43b93bab0
--- /dev/null
+++ b/tests/compile/callingconvention.h
@@ -0,0 +1,33 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern DL_EXPORT(int) f1(void);
+extern DL_EXPORT(int) __cdecl f2(void);
+extern DL_EXPORT(int) __stdcall f3(void);
+extern DL_EXPORT(int) __fastcall f4(void);
+#ifdef __cplusplus
+}
+#endif
+
+int f1(void) {return 0;}
+int __cdecl f2(void) {return 0;}
+int __stdcall f3(void) {return 0;}
+int __fastcall f4(void) {return 0;}
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int (*p1)(void);
+extern int (__cdecl *p2)(void);
+extern int (__stdcall *p3)(void);
+extern int (__fastcall *p4)(void);
+#ifdef __cplusplus
+}
+#endif
+
+int (*p1)(void);
+int (__cdecl *p2)(void);
+int (__stdcall *p3)(void);
+int (__fastcall *p4)(void);
diff --git a/tests/compile/callingconvention.pyx b/tests/compile/callingconvention.pyx
index cfca68228..0e3fa9dbe 100644
--- a/tests/compile/callingconvention.pyx
+++ b/tests/compile/callingconvention.pyx
@@ -1,3 +1,7 @@
+cdef extern from "callingconvention.h":
+    pass
+
+
 cdef extern int f1()
 
 cdef extern int __cdecl f2()
diff --git a/tests/compile/declarations.h b/tests/compile/declarations.h
new file mode 100644
index 000000000..d803e9759
--- /dev/null
+++ b/tests/compile/declarations.h
@@ -0,0 +1,53 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern char *cp;
+extern char *cpa[5];
+extern int (*ifnpa[5])(void);
+extern char *(*cpfnpa[5])(void);
+extern int (*ifnp)(void);
+extern int (*iap)[5];
+#ifdef __cplusplus
+}
+#endif
+
+char *cp;
+char *cpa[5];
+int (*ifnpa[5])(void);
+char *(*cpfnpa[5])(void);
+int (*ifnp)(void);
+int (*iap)[5];
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern DL_EXPORT(int) ifn(void);
+extern DL_EXPORT(char *) cpfn(void);
+extern DL_EXPORT(int) fnargfn(int (void));
+extern DL_EXPORT(int) (*iapfn(void))[5];
+extern DL_EXPORT(char *)(*cpapfn(void))[5];
+#ifdef __cplusplus
+}
+#endif
+
+int ifn(void) {return 0;}
+char *cpfn(void) {return 0;}
+int fnargfn(int f(void)) {return 0;}
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int ia[];
+extern int iaa[][3];
+extern DL_EXPORT(int) a(int[][3], int[][3][5]);
+#ifdef __cplusplus
+}
+#endif
+
+int ia[1];
+int iaa[][3];
+int a(int a[][3], int b[][3][5]) {return 0;}
diff --git a/tests/compile/declarations.pyx b/tests/compile/declarations.pyx
index cf6b5668e..b8705770e 100644
--- a/tests/compile/declarations.pyx
+++ b/tests/compile/declarations.pyx
@@ -1,3 +1,6 @@
+cdef extern from "declarations.h":
+    pass
+
 cdef extern char *cp
 cdef extern char *cpa[5]
 cdef extern int (*ifnpa[5])()
diff --git a/tests/compile/excvalcheck.h b/tests/compile/excvalcheck.h
new file mode 100644
index 000000000..4c92acd2b
--- /dev/null
+++ b/tests/compile/excvalcheck.h
@@ -0,0 +1,13 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern DL_EXPORT(int) spam(void);
+extern DL_EXPORT(void) grail(void);
+extern DL_EXPORT(char *)tomato(void);
+#ifdef __cplusplus
+}
+#endif
+
+int spam(void) {return 0;}
+void grail(void) {return;}
+char *tomato(void) {return 0;}
diff --git a/tests/compile/excvalcheck.pyx b/tests/compile/excvalcheck.pyx
index 4dbce95c9..9c84eb624 100644
--- a/tests/compile/excvalcheck.pyx
+++ b/tests/compile/excvalcheck.pyx
@@ -1,3 +1,6 @@
+cdef extern from "excvalcheck.h":
+    pass
+
 cdef extern int spam() except -1
 cdef extern void grail() except *
 cdef extern char *tomato() except? NULL
diff --git a/tests/compile/nogil.h b/tests/compile/nogil.h
index fb2e4d4e2..2c66be05d 100644
--- a/tests/compile/nogil.h
+++ b/tests/compile/nogil.h
@@ -1,2 +1,25 @@
-void e1(void);
-void *e2(void);
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern DL_EXPORT(void) e1(void);
+extern DL_EXPORT(void *) e2(void);
+#ifdef __cplusplus
+}
+#endif
+
+void e1(void) {return;}
+void *e2(void) {return 0;}
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern DL_EXPORT(PyObject *) g(PyObject*);
+extern DL_EXPORT(void) g2(PyObject*);
+#ifdef __cplusplus
+}
+#endif
+
+PyObject *g(PyObject* o) {return 0;}
+void g2(PyObject* o) {return;}
-- 
2.30.9