14
14
15
15
16
16
// Converts a list of points tuples to a flat list of ints for speedier internal use.
17
- // Also validates the points.
17
+ // Also validates the points. If this fails due to invalid types or values, the
18
+ // content of the points is undefined.
18
19
static void _clobber_points_list (vectorio_polygon_t * self , mp_obj_t points_tuple_list ) {
19
20
size_t len = 0 ;
20
21
mp_obj_t * items ;
@@ -26,12 +27,8 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
26
27
}
27
28
28
29
if (self -> len < 2 * len ) {
29
- if (self -> points_list != NULL ) {
30
- VECTORIO_POLYGON_DEBUG ("free(%d), " , sizeof (self -> points_list ));
31
- gc_free (self -> points_list );
32
- }
33
- self -> points_list = gc_alloc (2 * len * sizeof (uint16_t ), false, false);
34
- VECTORIO_POLYGON_DEBUG ("alloc(%p, %d)" , self -> points_list , 2 * len * sizeof (uint16_t ));
30
+ self -> points_list = gc_realloc (self -> points_list , 2 * len * sizeof (uint16_t ), true);
31
+ VECTORIO_POLYGON_DEBUG ("realloc(%d) -> %p" , self -> points_list , 2 * len * sizeof (uint16_t ));
35
32
}
36
33
self -> len = 2 * len ;
37
34
@@ -42,17 +39,10 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
42
39
43
40
mp_arg_validate_length (tuple_len , 2 , MP_QSTR_point );
44
41
45
- mp_int_t x ;
46
- mp_int_t y ;
47
- if (!mp_obj_get_int_maybe (tuple_items [ 0 ], & x )
48
- || !mp_obj_get_int_maybe (tuple_items [ 1 ], & y )
49
- || x < SHRT_MIN || x > SHRT_MAX || y < SHRT_MIN || y > SHRT_MAX
50
- ) {
51
- gc_free (self -> points_list );
52
- self -> points_list = NULL ;
53
- mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
54
- self -> len = 0 ;
55
- }
42
+ mp_int_t x = mp_arg_validate_type_int (tuple_items [0 ], MP_QSTR_x );
43
+ mp_arg_validate_int_range (x , SHRT_MIN , SHRT_MAX , MP_QSTR_x );
44
+ mp_int_t y = mp_arg_validate_type_int (tuple_items [1 ], MP_QSTR_y );
45
+ mp_arg_validate_int_range (y , SHRT_MIN , SHRT_MAX , MP_QSTR_y );
56
46
self -> points_list [2 * i ] = (int16_t )x ;
57
47
self -> points_list [2 * i + 1 ] = (int16_t )y ;
58
48
}
0 commit comments