|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | + |
| 4 | +namespace Python.Runtime |
| 5 | +{ |
| 6 | + /* buffer interface */ |
| 7 | + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] |
| 8 | + internal struct Py_buffer { |
| 9 | + public IntPtr buf; |
| 10 | + public IntPtr obj; /* owned reference */ |
| 11 | + [MarshalAs(UnmanagedType.SysInt)] |
| 12 | + public IntPtr len; |
| 13 | + [MarshalAs(UnmanagedType.SysInt)] |
| 14 | + public IntPtr itemsize; /* This is Py_ssize_t so it can be |
| 15 | + pointed to by strides in simple case.*/ |
| 16 | + [MarshalAs(UnmanagedType.Bool)] |
| 17 | + public bool _readonly; |
| 18 | + public int ndim; |
| 19 | + [MarshalAs(UnmanagedType.LPStr)] |
| 20 | + public string format; |
| 21 | + public IntPtr shape; |
| 22 | + public IntPtr strides; |
| 23 | + public IntPtr suboffsets; |
| 24 | + public IntPtr _internal; |
| 25 | + } |
| 26 | + |
| 27 | + public enum BufferOrderStyle |
| 28 | + { |
| 29 | + C, |
| 30 | + Fortran, |
| 31 | + EitherOne, |
| 32 | + } |
| 33 | + |
| 34 | + /* Flags for getting buffers */ |
| 35 | + public enum PyBUF |
| 36 | + { |
| 37 | + /// <summary> |
| 38 | + /// Simple buffer without shape strides and suboffsets |
| 39 | + /// </summary> |
| 40 | + SIMPLE = 0, |
| 41 | + /// <summary> |
| 42 | + /// Controls the <see cref="PyBuffer.ReadOnly"/> field. If set, the exporter MUST provide a writable buffer or else report failure. Otherwise, the exporter MAY provide either a read-only or writable buffer, but the choice MUST be consistent for all consumers. |
| 43 | + /// </summary> |
| 44 | + WRITABLE = 0x0001, |
| 45 | + /// <summary> |
| 46 | + /// Controls the <see cref="PyBuffer.Format"/> field. If set, this field MUST be filled in correctly. Otherwise, this field MUST be NULL. |
| 47 | + /// </summary> |
| 48 | + FORMATS = 0x0004, |
| 49 | + /// <summary> |
| 50 | + /// N-Dimensional buffer with shape |
| 51 | + /// </summary> |
| 52 | + ND = 0x0008, |
| 53 | + /// <summary> |
| 54 | + /// Buffer with strides and shape |
| 55 | + /// </summary> |
| 56 | + STRIDES = (0x0010 | ND), |
| 57 | + /// <summary> |
| 58 | + /// C-Contigous buffer with strides and shape |
| 59 | + /// </summary> |
| 60 | + C_CONTIGUOUS = (0x0020 | STRIDES), |
| 61 | + /// <summary> |
| 62 | + /// F-Contigous buffer with strides and shape |
| 63 | + /// </summary> |
| 64 | + F_CONTIGUOUS = (0x0040 | STRIDES), |
| 65 | + /// <summary> |
| 66 | + /// C or Fortran contigous buffer with strides and shape |
| 67 | + /// </summary> |
| 68 | + ANY_CONTIGUOUS = (0x0080 | STRIDES), |
| 69 | + /// <summary> |
| 70 | + /// Buffer with suboffsets (if needed) |
| 71 | + /// </summary> |
| 72 | + INDIRECT = (0x0100 | STRIDES), |
| 73 | + /// <summary> |
| 74 | + /// Writable C-Contigous buffer with shape |
| 75 | + /// </summary> |
| 76 | + CONTIG = (ND | WRITABLE), |
| 77 | + /// <summary> |
| 78 | + /// Readonly C-Contigous buffer with shape |
| 79 | + /// </summary> |
| 80 | + CONTIG_RO = (ND), |
| 81 | + /// <summary> |
| 82 | + /// Writable buffer with shape and strides |
| 83 | + /// </summary> |
| 84 | + STRIDED = (STRIDES | WRITABLE), |
| 85 | + /// <summary> |
| 86 | + /// Readonly buffer with shape and strides |
| 87 | + /// </summary> |
| 88 | + STRIDED_RO = (STRIDES), |
| 89 | + /// <summary> |
| 90 | + /// Writable buffer with shape, strides and format |
| 91 | + /// </summary> |
| 92 | + RECORDS = (STRIDES | WRITABLE | FORMATS), |
| 93 | + /// <summary> |
| 94 | + /// Readonly buffer with shape, strides and format |
| 95 | + /// </summary> |
| 96 | + RECORDS_RO = (STRIDES | FORMATS), |
| 97 | + /// <summary> |
| 98 | + /// Writable indirect buffer with shape, strides, format and suboffsets (if needed) |
| 99 | + /// </summary> |
| 100 | + FULL = (INDIRECT | WRITABLE | FORMATS), |
| 101 | + /// <summary> |
| 102 | + /// Readonly indirect buffer with shape, strides, format and suboffsets (if needed) |
| 103 | + /// </summary> |
| 104 | + FULL_RO = (INDIRECT | FORMATS), |
| 105 | + } |
| 106 | +} |
0 commit comments