@@ -26,7 +26,7 @@ struct arraydescr {
2626 int itemsize ;
2727 PyObject * (* getitem )(struct arrayobject * , Py_ssize_t );
2828 int (* setitem )(struct arrayobject * , Py_ssize_t , PyObject * );
29- const char * formats ;
29+ char * formats ;
3030};
3131
3232typedef struct arrayobject {
@@ -42,8 +42,10 @@ static PyTypeObject Arraytype;
4242
4343#ifdef Py_UNICODE_WIDE
4444#define PyArr_UNI 'w'
45+ #define PyArr_UNISTR "w"
4546#else
4647#define PyArr_UNI 'u'
48+ #define PyArr_UNISTR "u"
4749#endif
4850
4951#define array_Check (op ) PyObject_TypeCheck(op, &Arraytype)
@@ -387,18 +389,18 @@ d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
387389
388390/* Description of types */
389391static struct arraydescr descriptors [] = {
390- {'b' , sizeof (char ), b_getitem , b_setitem },
391- {'B' , sizeof (char ), BB_getitem , BB_setitem },
392- {PyArr_UNI , sizeof (Py_UNICODE ), u_getitem , u_setitem },
393- {'h' , sizeof (short ), h_getitem , h_setitem },
394- {'H' , sizeof (short ), HH_getitem , HH_setitem },
395- {'i' , sizeof (int ), i_getitem , i_setitem },
396- {'I' , sizeof (int ), II_getitem , II_setitem },
397- {'l' , sizeof (long ), l_getitem , l_setitem },
398- {'L' , sizeof (long ), LL_getitem , LL_setitem },
399- {'f' , sizeof (float ), f_getitem , f_setitem },
400- {'d' , sizeof (double ), d_getitem , d_setitem },
401- {'\0' , 0 , 0 , 0 } /* Sentinel */
392+ {'b' , sizeof (char ), b_getitem , b_setitem , "b" },
393+ {'B' , sizeof (char ), BB_getitem , BB_setitem , "B" },
394+ {PyArr_UNI , sizeof (Py_UNICODE ), u_getitem , u_setitem , PyArr_UNISTR },
395+ {'h' , sizeof (short ), h_getitem , h_setitem , "h" },
396+ {'H' , sizeof (short ), HH_getitem , HH_setitem , "H" },
397+ {'i' , sizeof (int ), i_getitem , i_setitem , "i" },
398+ {'I' , sizeof (int ), II_getitem , II_setitem , "I" },
399+ {'l' , sizeof (long ), l_getitem , l_setitem , "l" },
400+ {'L' , sizeof (long ), LL_getitem , LL_setitem , "L" },
401+ {'f' , sizeof (float ), f_getitem , f_setitem , "f" },
402+ {'d' , sizeof (double ), d_getitem , d_setitem , "d" },
403+ {'\0' , 0 , 0 , 0 , 0 } /* Sentinel */
402404};
403405
404406/****************************************************************************
@@ -1770,12 +1772,7 @@ array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
17701772 view -> format = NULL ;
17711773 view -> internal = NULL ;
17721774 if ((flags & PyBUF_FORMAT ) == PyBUF_FORMAT ) {
1773- view -> internal = malloc (3 );
1774- /* XXX(nnorwitz): need to check for malloc failure.
1775- Should probably use PyObject_Malloc. */
1776- view -> format = view -> internal ;
1777- view -> format [0 ] = (char )(self -> ob_descr -> typecode );
1778- view -> format [1 ] = '\0' ;
1775+ view -> format = self -> ob_descr -> formats ;
17791776 }
17801777
17811778 finish :
@@ -1786,7 +1783,6 @@ array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
17861783static void
17871784array_buffer_relbuf (arrayobject * self , PyBuffer * view )
17881785{
1789- free (view -> internal );
17901786 self -> ob_exports -- ;
17911787}
17921788
0 commit comments