@@ -215,8 +215,13 @@ SequenceLongObject_sq_item(PyObject *self, Py_ssize_t index) {
215
215
}
216
216
return PyLong_FromLong (((SequenceLongObject * ) self )-> array_long [my_index ]);
217
217
}
218
+
218
219
static int
219
220
SequenceLongObject_sq_ass_item (PyObject * self , Py_ssize_t index , PyObject * value ) {
221
+ fprintf (
222
+ stdout , "%s()#%d: self=%p index=%zd value=%p\n" ,
223
+ __FUNCTION__ , __LINE__ , (void * ) self , index , (void * ) value
224
+ );
220
225
Py_ssize_t my_index = index ;
221
226
if (my_index < 0 ) {
222
227
my_index += SequenceLongObject_sq_length (self );
@@ -235,9 +240,9 @@ SequenceLongObject_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value
235
240
/* Just set the value. */
236
241
if (!PyLong_Check (value )) {
237
242
PyErr_Format (
238
- PyExc_TypeError ,
239
- "sq_ass_item value needs to be an int, not type %s" ,
240
- Py_TYPE (value )-> tp_name
243
+ PyExc_TypeError ,
244
+ "sq_ass_item value needs to be an int, not type %s" ,
245
+ Py_TYPE (value )-> tp_name
241
246
);
242
247
return -1 ;
243
248
}
@@ -248,46 +253,51 @@ SequenceLongObject_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value
248
253
SequenceLongObject * self_as_slo = (SequenceLongObject * ) self ;
249
254
/* Special case: deleting the only item in the array. */
250
255
if (self_as_slo -> size == 1 ) {
256
+ fprintf (stdout , "%s()#%d: deleting empty index\n" , __FUNCTION__ , __LINE__ );
251
257
free (self_as_slo -> array_long );
252
258
self_as_slo -> array_long = NULL ;
253
259
self_as_slo -> size = 0 ;
254
260
} else {
255
261
/* Delete the value and re-compose the array. */
262
+ fprintf (stdout , "%s()#%d: deleting index=%zd\n" , __FUNCTION__ , __LINE__ , index );
256
263
long * new_array = malloc ((self_as_slo -> size - 1 ) * sizeof (long ));
257
264
if (!new_array ) {
258
265
PyErr_Format (
259
- PyExc_MemoryError ,
260
- "sq_ass_item can not allocate new array. %s#%d" ,
261
- __FILE__ , __LINE__
266
+ PyExc_MemoryError ,
267
+ "sq_ass_item can not allocate new array. %s#%d" ,
268
+ __FILE__ , __LINE__
262
269
);
263
270
return -1 ;
264
271
}
265
- /* memcpy across to the new array, firstly up to the index . */
272
+ /* memcpy parameters . */
266
273
void * dest = NULL ;
267
274
void * src = NULL ;
268
275
size_t count = 0 ;
269
276
277
+ /* memcpy across to the new array, firstly up to the index. */
270
278
dest = new_array ;
271
279
src = self_as_slo -> array_long ;
272
280
count = my_index * sizeof (long );
281
+ fprintf (stdout , "%s()#%d: First: dest=%p src=%p count=%zu\n" , __FUNCTION__ , __LINE__ , dest , src , count );
273
282
if (memcpy (dest , src , count ) != dest ) {
274
283
PyErr_Format (
275
- PyExc_MemoryError ,
276
- "sq_ass_item can not memcpy into new array. %s#%d" ,
277
- __FILE__ , __LINE__
284
+ PyExc_MemoryError ,
285
+ "sq_ass_item can not memcpy into new array. %s#%d" ,
286
+ __FILE__ , __LINE__
278
287
);
279
288
return -1 ;
280
289
}
281
- /* memcpy across to the new array, from the index to the end. */
290
+ /* memcpy from the index to the end. */
282
291
dest = new_array + count ;
283
- src = self_as_slo -> array_long + ( count - sizeof ( long )) ;
292
+ src = self_as_slo -> array_long + count ;
284
293
/* Example size=4, index=2 copy one value */
285
294
count = (self_as_slo -> size - my_index - 1 ) * sizeof (long );
295
+ fprintf (stdout , "%s()#%d: Next: dest=%p src=%p count=%zu\n" , __FUNCTION__ , __LINE__ , dest , src , count );
286
296
if (memcpy (dest , src , count ) != dest ) {
287
297
PyErr_Format (
288
- PyExc_MemoryError ,
289
- "sq_ass_item can not memcpy into new array. %s#%d" ,
290
- __FILE__ , __LINE__
298
+ PyExc_MemoryError ,
299
+ "sq_ass_item can not memcpy into new array. %s#%d" ,
300
+ __FILE__ , __LINE__
291
301
);
292
302
return -1 ;
293
303
}
0 commit comments