@@ -119,14 +119,7 @@ PyCStgDict_clone(StgDictObject *dst, StgDictObject *src)
119
119
120
120
if (src -> ffi_type_pointer .elements == NULL )
121
121
return 0 ;
122
- /* src->ffi_type_pointer.elements is an */
123
- /* array of pointers to ffi_type that */
124
- /* contains a trailing NULL pointer. */
125
- /* src->size is the size of the array */
126
- /* in bytes excluding the trailing NULL */
127
- /* pointer, so we have to add it in to */
128
- /* to compute how many bytes to copy. */
129
- size = src -> size + max (sizeof (ffi_type * ), src -> align );
122
+ size = sizeof (ffi_type * ) * (src -> length + 1 );
130
123
dst -> ffi_type_pointer .elements = PyMem_Malloc (size );
131
124
if (dst -> ffi_type_pointer .elements == NULL ) {
132
125
PyErr_NoMemory ();
380
373
PyCStructUnionType_update_stgdict (PyObject * type , PyObject * fields , int isStruct )
381
374
{
382
375
StgDictObject * stgdict , * basedict ;
383
- Py_ssize_t len , offset , size , align , i , base_len ;
376
+ Py_ssize_t len , offset , size , align , i ;
384
377
Py_ssize_t union_size , total_align , aligned_size ;
385
378
Py_ssize_t field_size = 0 ;
386
379
int bitofs ;
@@ -472,22 +465,19 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
472
465
union_size = 0 ;
473
466
total_align = align ? align : 1 ;
474
467
stgdict -> ffi_type_pointer .type = FFI_TYPE_STRUCT ;
475
- /* calculate the cumulative number of elements in the base class */
476
- /* so that all elements get copied to the child class */
477
- base_len = size / max (sizeof (ffi_type * ), align );
478
- stgdict -> ffi_type_pointer .elements = PyMem_New (ffi_type * , base_len + len + 1 );
468
+ stgdict -> ffi_type_pointer .elements = PyMem_New (ffi_type * , basedict -> length + len + 1 );
479
469
if (stgdict -> ffi_type_pointer .elements == NULL ) {
480
470
PyErr_NoMemory ();
481
471
return -1 ;
482
472
}
483
473
memset (stgdict -> ffi_type_pointer .elements , 0 ,
484
- sizeof (ffi_type * ) * (base_len + len + 1 ));
485
- if (size > 0 ) {
474
+ sizeof (ffi_type * ) * (basedict -> length + len + 1 ));
475
+ if (basedict -> length > 0 ) {
486
476
memcpy (stgdict -> ffi_type_pointer .elements ,
487
477
basedict -> ffi_type_pointer .elements ,
488
- size );
478
+ sizeof ( ffi_type * ) * ( basedict -> length ) );
489
479
}
490
- ffi_ofs = base_len ; /* index of the child class's first element */
480
+ ffi_ofs = basedict -> length ;
491
481
} else {
492
482
offset = 0 ;
493
483
size = 0 ;
@@ -705,7 +695,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
705
695
706
696
stgdict -> size = aligned_size ;
707
697
stgdict -> align = total_align ;
708
- stgdict -> length = len ; /* the number of elements in the child class */
698
+ stgdict -> length = ffi_ofs + len ;
709
699
710
700
/*
711
701
* The value of MAX_STRUCT_SIZE depends on the platform Python is running on.
0 commit comments