1 #ifndef _NPY_ARRAYSCALARS_H_ 2 #define _NPY_ARRAYSCALARS_H_ 3 4 #ifndef _MULTIARRAYMODULE 5 typedef struct { 6 PyObject_HEAD 7 npy_bool obval; 8 } PyBoolScalarObject; 9 #endif 10 11 12 typedef struct { 13 PyObject_HEAD 14 signed char obval; 15 } PyByteScalarObject; 16 17 18 typedef struct { 19 PyObject_HEAD 20 short obval; 21 } PyShortScalarObject; 22 23 24 typedef struct { 25 PyObject_HEAD 26 int obval; 27 } PyIntScalarObject; 28 29 30 typedef struct { 31 PyObject_HEAD 32 long obval; 33 } PyLongScalarObject; 34 35 36 typedef struct { 37 PyObject_HEAD 38 npy_longlong obval; 39 } PyLongLongScalarObject; 40 41 42 typedef struct { 43 PyObject_HEAD 44 unsigned char obval; 45 } PyUByteScalarObject; 46 47 48 typedef struct { 49 PyObject_HEAD 50 unsigned short obval; 51 } PyUShortScalarObject; 52 53 54 typedef struct { 55 PyObject_HEAD 56 unsigned int obval; 57 } PyUIntScalarObject; 58 59 60 typedef struct { 61 PyObject_HEAD 62 unsigned long obval; 63 } PyULongScalarObject; 64 65 66 typedef struct { 67 PyObject_HEAD 68 npy_ulonglong obval; 69 } PyULongLongScalarObject; 70 71 72 typedef struct { 73 PyObject_HEAD 74 npy_half obval; 75 } PyHalfScalarObject; 76 77 78 typedef struct { 79 PyObject_HEAD 80 float obval; 81 } PyFloatScalarObject; 82 83 84 typedef struct { 85 PyObject_HEAD 86 double obval; 87 } PyDoubleScalarObject; 88 89 90 typedef struct { 91 PyObject_HEAD 92 npy_longdouble obval; 93 } PyLongDoubleScalarObject; 94 95 96 typedef struct { 97 PyObject_HEAD 98 npy_cfloat obval; 99 } PyCFloatScalarObject; 100 101 102 typedef struct { 103 PyObject_HEAD 104 npy_cdouble obval; 105 } PyCDoubleScalarObject; 106 107 108 typedef struct { 109 PyObject_HEAD 110 npy_clongdouble obval; 111 } PyCLongDoubleScalarObject; 112 113 114 typedef struct { 115 PyObject_HEAD 116 PyObject * obval; 117 } PyObjectScalarObject; 118 119 typedef struct { 120 PyObject_HEAD 121 npy_datetime obval; 122 PyArray_DatetimeMetaData obmeta; 123 } PyDatetimeScalarObject; 124 125 typedef struct { 126 PyObject_HEAD 127 npy_timedelta obval; 128 PyArray_DatetimeMetaData obmeta; 129 } PyTimedeltaScalarObject; 130 131 132 typedef struct { 133 PyObject_HEAD 134 char obval; 135 } PyScalarObject; 136 137 #define PyStringScalarObject PyBytesObject 138 typedef struct { 139 /* note that the PyObject_HEAD macro lives right here */ 140 PyUnicodeObject base; 141 Py_UCS4 *obval; 142 char *buffer_fmt; 143 } PyUnicodeScalarObject; 144 145 146 typedef struct { 147 PyObject_VAR_HEAD 148 char *obval; 149 PyArray_Descr *descr; 150 int flags; 151 PyObject *base; 152 void *_buffer_info; /* private buffer info, tagged to allow warning */ 153 } PyVoidScalarObject; 154 155 /* Macros 156 Py<Cls><bitsize>ScalarObject 157 Py<Cls><bitsize>ArrType_Type 158 are defined in ndarrayobject.h 159 */ 160 161 #define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0]))) 162 #define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1]))) 163 #define PyArrayScalar_FromLong(i) \ 164 ((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)]))) 165 #define PyArrayScalar_RETURN_BOOL_FROM_LONG(i) \ 166 return Py_INCREF(PyArrayScalar_FromLong(i)), \ 167 PyArrayScalar_FromLong(i) 168 #define PyArrayScalar_RETURN_FALSE \ 169 return Py_INCREF(PyArrayScalar_False), \ 170 PyArrayScalar_False 171 #define PyArrayScalar_RETURN_TRUE \ 172 return Py_INCREF(PyArrayScalar_True), \ 173 PyArrayScalar_True 174 175 #define PyArrayScalar_New(cls) \ 176 Py##cls##ArrType_Type.tp_alloc(&Py##cls##ArrType_Type, 0) 177 #define PyArrayScalar_VAL(obj, cls) \ 178 ((Py##cls##ScalarObject *)obj)->obval 179 #define PyArrayScalar_ASSIGN(obj, cls, val) \ 180 PyArrayScalar_VAL(obj, cls) = val 181 182 #endif 183