Python C-API segmentation fault -


i have code:

static pyobject* py_write(pyobject *self, pyobject* args){      pyobject *tx_list;     pyobject *item = 0;     uint8_t tx_len = 0;      /* parse arguments */     if(!pyarg_parsetuple(args, "o!", &pylist_type, &tx_list)){         return null;     }      /* length of list */     tx_len = pylist_size(tx_list);      /* allocate memory output buffer */     uint8_t *tx_buffer = (uint8_t *)malloc(tx_len * sizeof(uint8_t));     memset(tx_buffer, 0, sizeof(uint8_t));      /* populate output buffer */     int i;     for(i = 0; < tx_len; i++){         item = pylist_getitem(tx_list, i);         tx_buffer[i] = (uint8_t)pyint_aslong(item);     }      /* send data */     if(spi_write(fd, tx_buffer, tx_len) < 0){         return pyerr_setfromerrno(pyexc_ioerror);     }      /* cleanup */     free(tx_buffer);     py_decref(item);     py_decref(tx_list);      py_return_none; } 

when call once method there no problem. on ~2000 segmentation fault. guess there wrong reference count. can give me hand or tell method debugging?

pylist_getitem returns borrowed reference, don't need py_decref item. also, when calling python c-api calls, null returned if there's exception. check null pylist_getitem.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -