Skip to content

Commit

Permalink
fixed db error
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdu committed Aug 27, 2023
1 parent 77fa52a commit d39bc5c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/fakeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Py_ssize_t pyfastx_fasta_keys_length(pyfastx_FastaKeys *self) {
}

PyObject *pyfastx_fasta_keys_repr(pyfastx_FastaKeys *self) {
return PyUnicode_FromFormat("<FastaKeys> contains %ld keys", self->seq_counts);
return PyUnicode_FromFormat("<FastaKeys> contains %zd keys", self->seq_counts);
}

PyObject *pyfastx_fasta_keys_subscript(pyfastx_FastaKeys *self, PyObject *item) {
Expand Down
9 changes: 4 additions & 5 deletions src/fasta.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PyObject *pyfastx_fasta_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
PyObject *index_obj = NULL;

//key function for seperating name
PyObject *key_func = Py_None;
PyObject *key_func = NULL;

pyfastx_Fasta *obj;

Expand All @@ -68,7 +68,7 @@ PyObject *pyfastx_fasta_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
return NULL;
}

if ((key_func != Py_None) && !PyCallable_Check(key_func)) {
if ((key_func) && !PyCallable_Check(key_func)) {
PyErr_SetString(PyExc_TypeError, "key_func must be a callable function");
return NULL;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ PyObject *pyfastx_fasta_new(PyTypeObject *type, PyObject *args, PyObject *kwargs

//create index

obj->index = pyfastx_init_index((PyObject *)obj, obj->file_obj, index_obj, uppercase, full_name, memory_index, key_func);
obj->index = pyfastx_init_index((PyObject *)obj, file_obj, index_obj, uppercase, full_name, memory_index, key_func);

//iter function
obj->func = pyfastx_index_next_null;
Expand Down Expand Up @@ -132,9 +132,8 @@ PyObject *pyfastx_fasta_new(PyTypeObject *type, PyObject *args, PyObject *kwargs

void pyfastx_fasta_dealloc(pyfastx_Fasta *self){
//free(self->file_name);
Py_DECREF(self->file_obj);

pyfastx_index_free(self->index);
Py_DECREF(self->file_obj);
Py_TYPE(self)->tp_free((PyObject *)self);
}

Expand Down
2 changes: 2 additions & 0 deletions src/fastq.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ void pyfastx_fastq_dealloc(pyfastx_Fastq *self) {
fclose(self->middle->fd);
gzclose(self->middle->gzfd);

Py_DECREF(self->file_obj);

Py_TYPE(self)->tp_free((PyObject *)self);
}

Expand Down
3 changes: 1 addition & 2 deletions src/fastx.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ PyObject *pyfastx_fastx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
int uppercase = 0;
int comment = 0;

char *file_name;
char *format = "auto";

PyObject *file_obj;
Expand Down Expand Up @@ -108,9 +107,9 @@ PyObject *pyfastx_fastx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
}

void pyfastx_fastx_dealloc(pyfastx_Fastx *self) {
Py_DECREF(self->file_obj);
kseq_destroy(self->kseqs);
gzclose(self->gzfd);
Py_DECREF(self->file_obj);
Py_TYPE(self)->tp_free((PyObject *)self);
}

Expand Down
7 changes: 5 additions & 2 deletions src/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pyfastx_Index* pyfastx_init_index(PyObject *obj, PyObject* file_obj, PyObject* i
index->uppercase = uppercase;

//key function
if (key_func) {
Py_INCREF(key_func);
}
index->key_func = key_func;

//full name
Expand Down Expand Up @@ -161,7 +164,7 @@ void pyfastx_create_index(pyfastx_Index *self){
PYFASTX_SQLITE_CALL(ret = sqlite3_open(self->index_file, &self->index_db));

if (ret != SQLITE_OK) {
PyErr_Format(PyExc_ConnectionError, "Can not open index file %s", self->index_file);
PyErr_Format(PyExc_ConnectionError, "Could not open index file %s", self->index_file);
return;
}

Expand Down Expand Up @@ -269,7 +272,7 @@ void pyfastx_create_index(pyfastx_Index *self){
//remove > sign at the start position
header_pos = line.s + 1;

if (self->key_func == Py_None) {
if (self->key_func == NULL) {
if (self->full_name) {
chrom.l = desc_len;
memcpy(chrom.s, header_pos, chrom.l);
Expand Down

0 comments on commit d39bc5c

Please sign in to comment.