@@ -107,7 +107,20 @@ string_cmp(int len1, character *str1, int len2, character *str2)
107
107
}
108
108
109
109
110
- template <bool rstrip, int comp, typename character>
110
+ /*
111
+ * Helper for templating, avoids warnings about uncovered switch paths.
112
+ */
113
+ enum class COMP {
114
+ EQ = Py_EQ,
115
+ NE = Py_NE,
116
+ LT = Py_LT,
117
+ LE = Py_LE,
118
+ GT = Py_GT,
119
+ GE = Py_GE,
120
+ };
121
+
122
+
123
+ template <bool rstrip, COMP comp, typename character>
111
124
static int
112
125
string_comparison_loop (PyArrayMethod_Context *context,
113
126
char *const data[], npy_intp const dimensions[],
@@ -132,26 +145,24 @@ string_comparison_loop(PyArrayMethod_Context *context,
132
145
len1, (character *)in1, len2, (character *)in2);
133
146
npy_bool res;
134
147
switch (comp) {
135
- case Py_EQ :
148
+ case COMP::EQ :
136
149
res = cmp == 0 ;
137
150
break ;
138
- case Py_NE :
151
+ case COMP::NE :
139
152
res = cmp != 0 ;
140
153
break ;
141
- case Py_LT :
154
+ case COMP::LT :
142
155
res = cmp < 0 ;
143
156
break ;
144
- case Py_LE :
157
+ case COMP::LE :
145
158
res = cmp <= 0 ;
146
159
break ;
147
- case Py_GT :
160
+ case COMP::GT :
148
161
res = cmp > 0 ;
149
162
break ;
150
- case Py_GE :
163
+ case COMP::GE :
151
164
res = cmp >= 0 ;
152
165
break ;
153
- default :
154
- assert (false );
155
166
}
156
167
*(npy_bool *)out = res;
157
168
@@ -225,27 +236,27 @@ init_string_ufuncs(PyObject *umath)
225
236
226
237
/* TODO: It would be nice to condense the below */
227
238
/* All String loops */
228
- loop = string_comparison_loop<false , Py_EQ , npy_byte>;
239
+ loop = string_comparison_loop<false , COMP::EQ , npy_byte>;
229
240
if (add_loop (umath, " equal" , &spec, loop) < 0 ) {
230
241
goto finish;
231
242
}
232
- loop = string_comparison_loop<false , Py_NE , npy_byte>;
243
+ loop = string_comparison_loop<false , COMP::NE , npy_byte>;
233
244
if (add_loop (umath, " not_equal" , &spec, loop) < 0 ) {
234
245
goto finish;
235
246
}
236
- loop = string_comparison_loop<false , Py_LT , npy_byte>;
247
+ loop = string_comparison_loop<false , COMP::LT , npy_byte>;
237
248
if (add_loop (umath, " less" , &spec, loop) < 0 ) {
238
249
goto finish;
239
250
}
240
- loop = string_comparison_loop<false , Py_LE , npy_byte>;
251
+ loop = string_comparison_loop<false , COMP::LE , npy_byte>;
241
252
if (add_loop (umath, " less_equal" , &spec, loop) < 0 ) {
242
253
goto finish;
243
254
}
244
- loop = string_comparison_loop<false , Py_GT , npy_byte>;
255
+ loop = string_comparison_loop<false , COMP::GT , npy_byte>;
245
256
if (add_loop (umath, " greater" , &spec, loop) < 0 ) {
246
257
goto finish;
247
258
}
248
- loop = string_comparison_loop<false , Py_GE , npy_byte>;
259
+ loop = string_comparison_loop<false , COMP::GE , npy_byte>;
249
260
if (add_loop (umath, " greater_equal" , &spec, loop) < 0 ) {
250
261
goto finish;
251
262
}
@@ -254,27 +265,27 @@ init_string_ufuncs(PyObject *umath)
254
265
dtypes[0 ] = Unicode;
255
266
dtypes[1 ] = Unicode;
256
267
257
- loop = string_comparison_loop<false , Py_EQ , npy_ucs4>;
268
+ loop = string_comparison_loop<false , COMP::EQ , npy_ucs4>;
258
269
if (add_loop (umath, " equal" , &spec, loop) < 0 ) {
259
270
goto finish;
260
271
}
261
- loop = string_comparison_loop<false , Py_NE , npy_ucs4>;
272
+ loop = string_comparison_loop<false , COMP::NE , npy_ucs4>;
262
273
if (add_loop (umath, " not_equal" , &spec, loop) < 0 ) {
263
274
goto finish;
264
275
}
265
- loop = string_comparison_loop<false , Py_LT , npy_ucs4>;
276
+ loop = string_comparison_loop<false , COMP::LT , npy_ucs4>;
266
277
if (add_loop (umath, " less" , &spec, loop) < 0 ) {
267
278
goto finish;
268
279
}
269
- loop = string_comparison_loop<false , Py_LE , npy_ucs4>;
280
+ loop = string_comparison_loop<false , COMP::LE , npy_ucs4>;
270
281
if (add_loop (umath, " less_equal" , &spec, loop) < 0 ) {
271
282
goto finish;
272
283
}
273
- loop = string_comparison_loop<false , Py_GT , npy_ucs4>;
284
+ loop = string_comparison_loop<false , COMP::GT , npy_ucs4>;
274
285
if (add_loop (umath, " greater" , &spec, loop) < 0 ) {
275
286
goto finish;
276
287
}
277
- loop = string_comparison_loop<false , Py_GE , npy_ucs4>;
288
+ loop = string_comparison_loop<false , COMP::GE , npy_ucs4>;
278
289
if (add_loop (umath, " greater_equal" , &spec, loop) < 0 ) {
279
290
goto finish;
280
291
}
@@ -294,19 +305,19 @@ get_strided_loop(int comp)
294
305
{
295
306
switch (comp) {
296
307
case Py_EQ:
297
- return string_comparison_loop<rstrip, Py_EQ , character>;
308
+ return string_comparison_loop<rstrip, COMP::EQ , character>;
298
309
case Py_NE:
299
- return string_comparison_loop<rstrip, Py_NE , character>;
310
+ return string_comparison_loop<rstrip, COMP::NE , character>;
300
311
case Py_LT:
301
- return string_comparison_loop<rstrip, Py_LT , character>;
312
+ return string_comparison_loop<rstrip, COMP::LT , character>;
302
313
case Py_LE:
303
- return string_comparison_loop<rstrip, Py_LE , character>;
314
+ return string_comparison_loop<rstrip, COMP::LE , character>;
304
315
case Py_GT:
305
- return string_comparison_loop<rstrip, Py_GT , character>;
316
+ return string_comparison_loop<rstrip, COMP::GT , character>;
306
317
case Py_GE:
307
- return string_comparison_loop<rstrip, Py_GE , character>;
318
+ return string_comparison_loop<rstrip, COMP::GE , character>;
308
319
default :
309
- assert (false );
320
+ assert (false ); /* caller ensures this */
310
321
}
311
322
return nullptr ;
312
323
}
0 commit comments