Skip to content

Commit 483b29a

Browse files
committed
MAINT: (mpfdtype) fix some compiler warnings and hopefully error
On CI gcc, remove the static assert for the alignment, since the alignment of the `mpf_field` is correct in the current storage scheme. Hopefully the static_assert was the problem on gcc?
1 parent 30e1fda commit 483b29a

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
working-directory: mpfdtype
3434
run: |
3535
sudo apt install libmpfr-dev -y
36-
python -m pip install . --no-build-isolation
36+
CFLAGS="-Werror" python -m pip install . --no-build-isolation
3737
- name: Run mpfdtype tests
3838
working-directory: mpfdtype
3939
run: |

mpfdtype/mpfdtype/src/casts.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ numpy_to_mpf_strided_loop(PyArrayMethod_Context *context,
182182
T *in = (T *)in_ptr;
183183
mpf_load(out, out_ptr, prec_out);
184184

185-
int res = C_to_mpfr<conv_T, T>(*in, out);
186-
// TODO: At least for ints, could flag out of bounds...
185+
C_to_mpfr<conv_T, T>(*in, out);
186+
// TODO: At least for ints, could flag out of bounds, the return value
187+
// of C_to_mpfr may help with that (it flags imprecisions).
187188
mpf_store(out_ptr, out);
188189

189190
in_ptr += strides[0];

mpfdtype/mpfdtype/src/dtype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ new_MPFDType_instance(mpfr_prec_t precision)
4646
"storage of single float would be too large for precision.");
4747
}
4848
new->base.elsize = sizeof(mpf_storage) + size;
49-
new->base.alignment = _Alignof(mpf_storage);
49+
new->base.alignment = _Alignof(mpf_field);
5050
new->base.flags |= NPY_NEEDS_INIT;
5151

5252
return new;
@@ -242,7 +242,7 @@ PyArray_DTypeMeta MPFDType = {{{
242242
.tp_new = MPFDType_new,
243243
.tp_repr = (reprfunc)MPFDType_repr,
244244
.tp_str = (reprfunc)MPFDType_repr,
245-
.tp_getset = &mpfdtype_getsetlist,
245+
.tp_getset = mpfdtype_getsetlist,
246246
}},
247247
/* rest, filled in during DTypeMeta initialization */
248248
};

mpfdtype/mpfdtype/src/dtype.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ typedef struct {
2323
* So not storeing only those (saving 16 bytes of 48 for a 128 bit number)
2424
* removes the need to worry about this.
2525
*/
26-
static_assert(_Alignof(mpfr_t) >= _Alignof(mp_limb_t),
27-
"mpfr_t storage not aligned as much as limb_t?!");
2826
typedef mpfr_t mpf_storage;
2927

3028
extern PyArray_DTypeMeta MPFDType;

mpfdtype/mpfdtype/src/scalar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ PyTypeObject MPFloat_Type = {
209209
.tp_repr = (reprfunc)MPFloat_repr,
210210
.tp_str = (reprfunc)MPFloat_str,
211211
.tp_as_number = &mpf_as_number,
212-
.tp_richcompare = &mpf_richcompare,
213-
.tp_getset = &mpfloat_getsetlist,
212+
.tp_richcompare = (richcmpfunc)mpf_richcompare,
213+
.tp_getset = mpfloat_getsetlist,
214214
};
215215

216216

mpfdtype/mpfdtype/src/terrible_hacks.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
* (for larger itemsizes at least).
2323
*/
2424
static void
25-
copyswap_mpf(char *dst, char *src, int swap, PyArrayObject *arr)
25+
copyswap_mpf(char *dst, char *src, int swap, PyArrayObject *ap)
2626
{
27-
PyArray_Descr *descr = PyArray_DESCR(arr);
27+
/* Note that it is probably better to only get the descr from `ap` */
28+
PyArray_Descr *descr = PyArray_DESCR(ap);
2829

2930
memcpy(dst, src, descr->elsize);
3031
}
@@ -33,9 +34,10 @@ copyswap_mpf(char *dst, char *src, int swap, PyArrayObject *arr)
3334
/* Should only be used for sorting, so more complex than necessary, probably */
3435
int compare_mpf(char *in1_ptr, char *in2_ptr, int swap, PyArrayObject *ap)
3536
{
37+
/* Note that it is probably better to only get the descr from `ap` */
3638
mpfr_prec_t precision = ((MPFDTypeObject *)PyArray_DESCR(ap))->precision;
3739

38-
mpfr_t in1, in2;
40+
mpfr_ptr in1, in2;
3941

4042
mpf_load(in1, in1_ptr, precision);
4143
mpf_load(in2, in2_ptr, precision);
@@ -63,8 +65,8 @@ init_terrible_hacks(void) {
6365
return -1;
6466
}
6567
/* ->f slots are the same for all instances (currently). */
66-
descr->base.f->copyswap = &copyswap_mpf;
67-
descr->base.f->compare = &compare_mpf;
68+
descr->base.f->copyswap = (PyArray_CopySwapFunc *)&copyswap_mpf;
69+
descr->base.f->compare = (PyArray_CompareFunc *)&compare_mpf;
6870
Py_DECREF(descr);
6971

7072
return 0;

0 commit comments

Comments
 (0)