@@ -10,6 +10,9 @@ use std::os::raw::*;
1010use super :: types:: * ;
1111use crate :: npyffi:: * ;
1212
13+ pub const NPY_NTYPES_ABI_COMPATIBLE : usize = 21 ;
14+ pub const NPY_MAXDIMS_LEGACY_ITERS : usize = 32 ;
15+
1316#[ repr( C ) ]
1417pub struct PyArrayObject {
1518 pub ob_base : PyObject ,
@@ -192,7 +195,7 @@ pub struct PyArray_ArrayDescr {
192195#[ repr( C ) ]
193196#[ derive( Copy , Clone ) ]
194197pub struct PyArray_ArrFuncs {
195- pub cast : [ PyArray_VectorUnaryFunc ; 21usize ] ,
198+ pub cast : [ PyArray_VectorUnaryFunc ; NPY_NTYPES_ABI_COMPATIBLE ] ,
196199 pub getitem : PyArray_GetItemFunc ,
197200 pub setitem : PyArray_SetItemFunc ,
198201 pub copyswapn : PyArray_CopySwapNFunc ,
@@ -205,15 +208,15 @@ pub struct PyArray_ArrFuncs {
205208 pub nonzero : PyArray_NonzeroFunc ,
206209 pub fill : PyArray_FillFunc ,
207210 pub fillwithscalar : PyArray_FillWithScalarFunc ,
208- pub sort : [ PyArray_SortFunc ; 3usize ] ,
209- pub argsort : [ PyArray_ArgSortFunc ; 3usize ] ,
211+ pub sort : [ PyArray_SortFunc ; NPY_NSORTS ] ,
212+ pub argsort : [ PyArray_ArgSortFunc ; NPY_NSORTS ] ,
210213 pub castdict : * mut PyObject ,
211214 pub scalarkind : PyArray_ScalarKindFunc ,
212215 pub cancastscalarkindto : * mut * mut c_int ,
213216 pub cancastto : * mut c_int ,
214- pub fastclip : PyArray_FastClipFunc ,
215- pub fastputmask : PyArray_FastPutmaskFunc ,
216- pub fasttake : PyArray_FastTakeFunc ,
217+ pub _unused1 : * mut c_void ,
218+ pub _unused2 : * mut c_void ,
219+ pub _unused3 : * mut c_void ,
217220 pub argmin : PyArray_ArgFunc ,
218221}
219222
@@ -263,53 +266,9 @@ pub type PyArray_SortFunc =
263266 Option < unsafe extern "C" fn ( * mut c_void , npy_intp , * mut c_void ) -> c_int > ;
264267pub type PyArray_ArgSortFunc =
265268 Option < unsafe extern "C" fn ( * mut c_void , * mut npy_intp , npy_intp , * mut c_void ) -> c_int > ;
266- pub type PyArray_PartitionFunc = Option <
267- unsafe extern "C" fn (
268- * mut c_void ,
269- npy_intp ,
270- npy_intp ,
271- * mut npy_intp ,
272- * mut npy_intp ,
273- * mut c_void ,
274- ) -> c_int ,
275- > ;
276- pub type PyArray_ArgPartitionFunc = Option <
277- unsafe extern "C" fn (
278- * mut c_void ,
279- * mut npy_intp ,
280- npy_intp ,
281- npy_intp ,
282- * mut npy_intp ,
283- * mut npy_intp ,
284- * mut c_void ,
285- ) -> c_int ,
286- > ;
287269pub type PyArray_FillWithScalarFunc =
288270 Option < unsafe extern "C" fn ( * mut c_void , npy_intp , * mut c_void , * mut c_void ) -> c_int > ;
289271pub type PyArray_ScalarKindFunc = Option < unsafe extern "C" fn ( * mut c_void ) -> c_int > ;
290- pub type PyArray_FastClipFunc =
291- Option < unsafe extern "C" fn ( * mut c_void , npy_intp , * mut c_void , * mut c_void , * mut c_void ) > ;
292- pub type PyArray_FastPutmaskFunc =
293- Option < unsafe extern "C" fn ( * mut c_void , * mut c_void , npy_intp , * mut c_void , npy_intp ) > ;
294- pub type PyArray_FastTakeFunc = Option <
295- unsafe extern "C" fn (
296- * mut c_void ,
297- * mut c_void ,
298- * mut npy_intp ,
299- npy_intp ,
300- npy_intp ,
301- npy_intp ,
302- npy_intp ,
303- NPY_CLIPMODE ,
304- ) -> c_int ,
305- > ;
306-
307- #[ repr( C ) ]
308- pub struct PyArrayFlagsObject {
309- pub ob_base : PyObject ,
310- pub arr : * mut PyObject ,
311- pub flags : c_int ,
312- }
313272
314273#[ repr( C ) ]
315274#[ derive( Clone , Copy ) ]
@@ -365,9 +324,12 @@ pub struct PyUFuncObject {
365324 pub core_offsets : * mut c_int ,
366325 pub core_signature : * mut c_char ,
367326 pub type_resolver : PyUFunc_TypeResolutionFunc ,
368- pub legacy_inner_loop_selector : PyUFunc_LegacyInnerLoopSelectionFunc ,
369- pub reserved2 : * mut c_void ,
370- pub masked_inner_loop_selector : PyUFunc_MaskedInnerLoopSelectionFunc ,
327+ pub reserved2 : * mut c_void , // Was the legacy loop resolver
328+ #[ cfg( all( Py_3_8 , not( Py_LIMITED_API ) ) ) ]
329+ pub vectorcall : Option < vectorcallfunc > ,
330+ #[ cfg( not( all( Py_3_8 , not( Py_LIMITED_API ) ) ) ) ]
331+ pub vectorcall : * mut c_void ,
332+ pub reserved3 : * mut c_void , // Was previously the `PyUFunc_MaskedInnerLoopSelectionFunc`
371333 pub op_flags : * mut npy_uint32 ,
372334 pub iter_flags : npy_uint32 ,
373335}
@@ -393,27 +355,6 @@ pub type PyUFunc_TypeResolutionFunc = Option<
393355 * mut * mut PyArray_Descr ,
394356 ) -> c_int ,
395357> ;
396- pub type PyUFunc_LegacyInnerLoopSelectionFunc = Option <
397- unsafe extern "C" fn (
398- * mut PyUFuncObject ,
399- * mut * mut PyArray_Descr ,
400- * mut PyUFuncGenericFunction ,
401- * mut * mut c_void ,
402- * mut c_int ,
403- ) -> c_int ,
404- > ;
405- pub type PyUFunc_MaskedInnerLoopSelectionFunc = Option <
406- unsafe extern "C" fn (
407- * mut PyUFuncObject ,
408- * mut * mut PyArray_Descr ,
409- * mut PyArray_Descr ,
410- * mut npy_intp ,
411- npy_intp ,
412- * mut PyUFunc_MaskedStridedInnerLoopFunc ,
413- * mut * mut NpyAuxData ,
414- * mut c_int ,
415- ) -> c_int ,
416- > ;
417358
418359#[ repr( C ) ]
419360#[ derive( Debug , Copy , Clone ) ]
@@ -425,17 +366,17 @@ pub struct PyArrayIterObject {
425366 pub nd_m1 : c_int ,
426367 pub index : npy_intp ,
427368 pub size : npy_intp ,
428- pub coordinates : [ npy_intp ; 32usize ] ,
429- pub dims_m1 : [ npy_intp ; 32usize ] ,
430- pub strides : [ npy_intp ; 32usize ] ,
431- pub backstrides : [ npy_intp ; 32usize ] ,
432- pub factors : [ npy_intp ; 32usize ] ,
369+ pub coordinates : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
370+ pub dims_m1 : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
371+ pub strides : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
372+ pub backstrides : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
373+ pub factors : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
433374 pub ao : * mut PyArrayObject ,
434375 pub dataptr : * mut c_char ,
435376 pub contiguous : npy_bool ,
436- pub bounds : [ [ npy_intp ; 2usize ] ; 32usize ] ,
437- pub limits : [ [ npy_intp ; 2usize ] ; 32usize ] ,
438- pub limits_sizes : [ npy_intp ; 32usize ] ,
377+ pub bounds : [ [ npy_intp ; 2usize ] ; NPY_MAXDIMS_LEGACY_ITERS ] ,
378+ pub limits : [ [ npy_intp ; 2usize ] ; NPY_MAXDIMS_LEGACY_ITERS ] ,
379+ pub limits_sizes : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
439380 pub translate : npy_iter_get_dataptr_t ,
440381}
441382
@@ -446,7 +387,7 @@ pub struct PyArrayMultiIterObject {
446387 pub size : npy_intp ,
447388 pub index : npy_intp ,
448389 pub nd : c_int ,
449- pub dimensions : [ npy_intp ; 32usize ] ,
390+ pub dimensions : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
450391 pub iters : [ * mut PyArrayIterObject ; 32usize ] ,
451392}
452393
@@ -456,62 +397,25 @@ pub struct PyArrayNeighborhoodIterObject {
456397 pub nd_m1 : c_int ,
457398 pub index : npy_intp ,
458399 pub size : npy_intp ,
459- pub coordinates : [ npy_intp ; 32usize ] ,
460- pub dims_m1 : [ npy_intp ; 32usize ] ,
461- pub strides : [ npy_intp ; 32usize ] ,
462- pub backstrides : [ npy_intp ; 32usize ] ,
463- pub factors : [ npy_intp ; 32usize ] ,
400+ pub coordinates : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
401+ pub dims_m1 : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
402+ pub strides : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
403+ pub backstrides : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
404+ pub factors : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
464405 pub ao : * mut PyArrayObject ,
465406 pub dataptr : * mut c_char ,
466407 pub contiguous : npy_bool ,
467- pub bounds : [ [ npy_intp ; 2usize ] ; 32usize ] ,
468- pub limits : [ [ npy_intp ; 2usize ] ; 32usize ] ,
469- pub limits_sizes : [ npy_intp ; 32usize ] ,
408+ pub bounds : [ [ npy_intp ; 2usize ] ; NPY_MAXDIMS_LEGACY_ITERS ] ,
409+ pub limits : [ [ npy_intp ; 2usize ] ; NPY_MAXDIMS_LEGACY_ITERS ] ,
410+ pub limits_sizes : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
470411 pub translate : npy_iter_get_dataptr_t ,
471412 pub nd : npy_intp ,
472- pub dimensions : [ npy_intp ; 32usize ] ,
413+ pub dimensions : [ npy_intp ; NPY_MAXDIMS_LEGACY_ITERS ] ,
473414 pub _internal_iter : * mut PyArrayIterObject ,
474415 pub constant : * mut c_char ,
475416 pub mode : c_int ,
476417}
477418
478- #[ repr( C ) ]
479- pub struct PyArrayMapIterObject {
480- pub ob_base : PyObject ,
481- pub numiter : c_int ,
482- pub size : npy_intp ,
483- pub index : npy_intp ,
484- pub nd : c_int ,
485- pub dimensions : [ npy_intp ; 32usize ] ,
486- pub outer : * mut NpyIter ,
487- pub unused : [ * mut c_void ; 30usize ] ,
488- pub array : * mut PyArrayObject ,
489- pub ait : * mut PyArrayIterObject ,
490- pub subspace : * mut PyArrayObject ,
491- pub iteraxes : [ c_int ; 32usize ] ,
492- pub fancy_strides : [ npy_intp ; 32usize ] ,
493- pub baseoffset : * mut c_char ,
494- pub consec : c_int ,
495- pub dataptr : * mut c_char ,
496- pub nd_fancy : c_int ,
497- pub fancy_dims : [ npy_intp ; 32usize ] ,
498- pub needs_api : c_int ,
499- pub extra_op : * mut PyArrayObject ,
500- pub extra_op_dtype : * mut PyArray_Descr ,
501- pub extra_op_flags : * mut npy_uint32 ,
502- pub extra_op_iter : * mut NpyIter ,
503- pub extra_op_next : NpyIter_IterNextFunc ,
504- pub extra_op_ptrs : * mut * mut c_char ,
505- pub outer_next : NpyIter_IterNextFunc ,
506- pub outer_ptrs : * mut * mut c_char ,
507- pub outer_strides : * mut npy_intp ,
508- pub subspace_iter : * mut NpyIter ,
509- pub subspace_next : NpyIter_IterNextFunc ,
510- pub subspace_ptrs : * mut * mut c_char ,
511- pub subspace_strides : * mut npy_intp ,
512- pub iter_count : npy_intp ,
513- }
514-
515419pub type NpyIter_IterNextFunc = Option < unsafe extern "C" fn ( * mut NpyIter ) -> c_int > ;
516420pub type NpyIter_GetMultiIndexFunc = Option < unsafe extern "C" fn ( * mut NpyIter , * mut npy_intp ) > ;
517421pub type PyDataMem_EventHookFunc =
@@ -547,8 +451,11 @@ pub struct PyArray_DatetimeDTypeMetaData {
547451// npy_packed_static_string and npy_string_allocator are opaque pointers.
548452// FIXME(adamreichold): Consider extern types when they are stabilized.
549453// https://github.com/rust-lang/rust/issues/43467
550- pub type npy_packed_static_string = c_void ;
551- pub type npy_string_allocator = c_void ;
454+ #[ repr( C ) ]
455+ pub struct npy_packed_static_string ( [ u8 ; 0 ] ) ;
456+
457+ #[ repr( C ) ]
458+ pub struct npy_string_allocator ( [ u8 ; 0 ] ) ;
552459
553460#[ cfg( not( Py_LIMITED_API ) ) ]
554461#[ repr( C ) ]
0 commit comments