Package: python-biopython / 1.64+dfsg-5

fix_test_problem_on_powerpc.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Author: Michiel de Hoon <mjldehoon@yahoo.com>
Last-Update: Fri, 29 Aug 2014 20:37:24 -0700
Bug-Debian: http://bugs.debian.org/751277
Forwarded-Upstream: yes
Description: Fix issue in test suite on PowerPC (and hopefully mips, s390x)

--- a/Bio/Cluster/clustermodule.c
+++ b/Bio/Cluster/clustermodule.c
@@ -27,31 +27,79 @@
 /* -- Helper routines ------------------------------------------------------- */
 /* ========================================================================== */
 
+#if PY_MAJOR_VERSION < 3
+static char
+extract_single_character(PyObject* object, const char variable[],
+                         const char allowed[])
+{   char c = '\0';
+    const char* data;
+    Py_ssize_t n;
+    if (PyString_Check(object))
+    {   n = PyString_GET_SIZE(object);
+        if (n==1) {
+            data = PyString_AS_STRING(object);
+            c = data[0];
+        }
+    }
+    else if (PyUnicode_Check(object))
+    {   n = PyUnicode_GET_SIZE(object);
+        if (n==1) {
+            Py_UNICODE* u = PyUnicode_AS_UNICODE(object);
+            Py_UNICODE ch = u[0];
+            if (ch < 128) c = ch;
+        }
+    }
+    else
+    {   PyErr_Format(PyExc_ValueError, "%s should be a string", variable);
+        return 0;
+    }
+    if (!c)
+    {   PyErr_Format(PyExc_ValueError,
+                     "%s should be a single character", variable);
+        return 0;
+    }
+    else if (!strchr(allowed, c))
+    {   PyErr_Format(PyExc_ValueError,
+                     "unknown %s function specified (should be one of '%s')",
+                     variable, allowed);
+        return 0;
+    }
+    return c;
+}
+#else
+static char
+extract_single_character(PyObject* object, const char variable[],
+                         const char allowed[])
+{   Py_UCS4 ch;
+    Py_ssize_t n;
+    if (!PyUnicode_Check(object))
+    {   PyErr_Format(PyExc_ValueError, "%s should be a string", variable);
+        return 0;
+    }
+    if (PyUnicode_READY(object)==-1) return 0;
+    n = PyUnicode_GET_LENGTH(object);
+    if (n!=1)
+    {   PyErr_Format(PyExc_ValueError,
+                     "%s should be a single character", variable);
+        return 0;
+    }
+    ch = PyUnicode_READ_CHAR(object, 0);
+    if (ch < 128)
+    {   const char c = ch;
+        if (strchr(allowed, c)) return c;
+    }
+    PyErr_Format(PyExc_ValueError,
+                 "unknown %s function specified (should be one of '%s')",
+                 variable, allowed);
+    return 0;
+}
+#endif
+
 static int
 distance_converter(PyObject* object, void* pointer)
 { char c;
-  const char* data;
-  const char known_distances[] = "ebcauxsk";
-#if PY_MAJOR_VERSION < 3
-  if (PyString_Check(object))
-      data = PyString_AsString(object);
-  else
-#endif
-  if (PyUnicode_Check(object))
-      data = PyUnicode_AS_DATA(object);
-  else
-  { PyErr_SetString(PyExc_ValueError, "distance should be a string");
-    return 0;
-  }
-  if (strlen(data)!=1)
-  { PyErr_SetString(PyExc_ValueError, "distance should be a single character");
-    return 0;
-  }
-  c = data[0];
-  if (!strchr(known_distances, c))
-  { PyErr_Format(PyExc_ValueError, "unknown distance function specified (should be one of '%s')", known_distances);
-    return 0;
-  }
+  c = extract_single_character(object, "dist", "ebcauxsk");
+  if (c==0) return 0;
   *((char*)pointer) = c;
   return 1;
 }
@@ -59,28 +107,8 @@ distance_converter(PyObject* object, voi
 static int
 method_treecluster_converter(PyObject* object, void* pointer)
 { char c;
-  const char* data;
-  const char known_methods[] = "csma";
-#if PY_MAJOR_VERSION < 3
-  if (PyString_Check(object))
-      data = PyString_AsString(object);
-  else
-#endif
-  if (PyUnicode_Check(object))
-      data = PyUnicode_AS_DATA(object);
-  else
-  { PyErr_SetString(PyExc_ValueError, "method should be a string");
-    return 0;
-  }
-  if (strlen(data)!=1)
-  { PyErr_SetString(PyExc_ValueError, "method should be a single character");
-    return 0;
-  }
-  c = data[0];
-  if (!strchr(known_methods, c))
-  { PyErr_Format(PyExc_ValueError, "unknown method function specified (should be one of '%s')", known_methods);
-    return 0;
-  }
+  c = extract_single_character(object, "method", "csma");
+  if (c==0) return 0;
   *((char*)pointer) = c;
   return 1;
 }
@@ -88,28 +116,8 @@ method_treecluster_converter(PyObject* o
 static int
 method_kcluster_converter(PyObject* object, void* pointer)
 { char c;
-  const char* data;
-  const char known_methods[] = "am";
-#if PY_MAJOR_VERSION < 3
-  if (PyString_Check(object))
-      data = PyString_AsString(object);
-  else
-#endif
-  if (PyUnicode_Check(object))
-      data = PyUnicode_AS_DATA(object);
-  else
-  { PyErr_SetString(PyExc_ValueError, "method should be a string");
-    return 0;
-  }
-  if (strlen(data)!=1)
-  { PyErr_SetString(PyExc_ValueError, "method should be a single character");
-    return 0;
-  }
-  c = data[0];
-  if (!strchr(known_methods, c))
-  { PyErr_Format(PyExc_ValueError, "unknown method function specified (should be one of '%s')", known_methods);
-    return 0;
-  }
+  c = extract_single_character(object, "method", "am");
+  if (c==0) return 0;
   *((char*)pointer) = c;
   return 1;
 }
@@ -117,31 +125,12 @@ method_kcluster_converter(PyObject* obje
 static int
 method_clusterdistance_converter(PyObject* object, void* pointer)
 { char c;
-  const char* data;
-  const char known_methods[] = "amsxv";
-#if PY_MAJOR_VERSION < 3
-  if (PyString_Check(object))
-      data = PyString_AsString(object);
-  else
-#endif
-  if (PyUnicode_Check(object))
-      data = PyUnicode_AS_DATA(object);
-  else
-  { PyErr_SetString(PyExc_ValueError, "method should be a string");
-    return 0;
-  }
-  if (strlen(data)!=1)
-  { PyErr_SetString(PyExc_ValueError, "method should be a single character");
-    return 0;
-  }
-  c = data[0];
-  if (!strchr(known_methods, c))
-  { PyErr_Format(PyExc_ValueError, "unknown method function specified (should be one of '%s')", known_methods);
-    return 0;
-  }
+  c = extract_single_character(object, "method", "amsxv");
+  if (c==0) return 0;
   *((char*)pointer) = c;
   return 1;
 }
+
 /* -- data ------------------------------------------------------------------ */
 
 static double**