Skip to content

Commit 1923b3a

Browse files
committed
Add finalization cleanup and don't Py_INCREF excessively
1 parent 11f2989 commit 1923b3a

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,5 @@ Wiggle and BigWig files use 0-based half-open coordinates, which are also used b
109109

110110
# To do
111111

112-
- [ ] Use numpy arrays instead of lists? This requires having numpy installed, which seems rather over the top but Fidel might want this for deeptools.
113112
- [ ] Writer functions? It's unclear how much these would even be used.
114-
- [ ] The global curl cleanup stuff isn't being done at all currently.
113+
- [X] The global curl cleanup stuff isn't being done at all currently.

pyBigWig.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ static PyObject *pyBwGetHeader(pyBigWigFile_t *self, PyObject *args) {
7171
if(PyDict_SetItemString(ret, "sumSquared", val) == -1) goto error;
7272
Py_DECREF(val);
7373

74-
Py_INCREF(ret);
7574
return ret;
7675

7776
error :
@@ -104,7 +103,6 @@ static PyObject *pyBwGetChroms(pyBigWigFile_t *self, PyObject *args) {
104103
}
105104
}
106105

107-
Py_INCREF(ret);
108106
return ret;
109107

110108
error :
@@ -174,7 +172,6 @@ static PyObject *pyBwGetStats(pyBigWigFile_t *self, PyObject *args, PyObject *kw
174172
for(i=0; i<nBins; i++) PyList_SetItem(ret, i, (isnan(val[i]))?Py_None:PyFloat_FromDouble(val[i]));
175173
free(val);
176174

177-
Py_INCREF(ret);
178175
return ret;
179176
}
180177

@@ -217,7 +214,6 @@ static PyObject *pyBwGetValues(pyBigWigFile_t *self, PyObject *args) {
217214
for(i=0; i<o->l; i++) PyList_SetItem(ret, i, PyFloat_FromDouble(o->value[i]));
218215
bwDestroyOverlappingIntervals(o);
219216

220-
Py_INCREF(ret);
221217
return ret;
222218
}
223219

@@ -267,7 +263,6 @@ static PyObject *pyBwGetIntervals(pyBigWigFile_t *self, PyObject *args, PyObject
267263
}
268264

269265
bwDestroyOverlappingIntervals(intervals);
270-
Py_INCREF(ret);
271266
return ret;
272267
}
273268

@@ -277,6 +272,7 @@ PyMODINIT_FUNC PyInit_pyBigWig(void) {
277272
errno = 0; //just in case
278273

279274
if(PyType_Ready(&bigWigFile) < 0) return NULL;
275+
if(Py_AtExit(bwCleanup)) return NULL;
280276
if(bwInit(128000)) return NULL;
281277
res = PyModule_Create(&pyBigWigmodule);
282278
if(!res) return NULL;
@@ -290,6 +286,7 @@ PyMODINIT_FUNC PyInit_pyBigWig(void) {
290286
//Python2 initialization
291287
PyMODINIT_FUNC initpyBigWig(void) {
292288
errno=0; //Sometimes libpython2.7.so is missing some links...
289+
if(Py_AtExit(bwCleanup)) return NULL;
293290
if(PyType_Ready(&bigWigFile) < 0) return;
294291
if(bwInit(128000)) return; //This is temporary
295292
Py_InitModule3("pyBigWig", bwMethods, "A module for handling bigWig files");

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
include_dirs = ['libBigWig'])
3232

3333
setup(name = 'pyBigWig',
34-
version = '0.1.9',
34+
version = '0.1.10',
3535
description = 'A package for accessing bigWig files using libBigWig',
3636
author = "Devon P. Ryan",
3737
author_email = "[email protected]",

0 commit comments

Comments
 (0)