Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libBigWig/bigWigIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef struct {
#endif
FILE *fp; /**<The FILE * file pointer for local files.**/
} x; /**<A union holding curl and fp.*/
void *memBuf; /**<A void * pointing to memory of size bufSize.*/
char *memBuf; /**<A char * pointing to memory of size bufSize.*/
size_t filePos; /**<Current position inside the file.*/
size_t bufPos; /**<Curent position inside the buffer.*/
size_t bufSize; /**<The size of the buffer.*/
Expand All @@ -65,11 +65,11 @@ typedef struct {
*
* @warning Note that on error, URL for remote files is left in an unusable state. You can get around this by running urlSeek() to a position outside of the range held by the internal buffer.
*/
size_t urlRead(URL_t *URL, void *buf, size_t bufSize);
size_t urlRead(URL_t *URL, char *buf, size_t bufSize);

/*!
* @brief Seeks to a given position in a local or remote file.
*
*
* For local files, this will set the file position indicator for the file pointer to the desired position. For remote files, it sets the position to start downloading data for the next urlRead(). Note that for remote files that running urlSeek() with a pos within the current buffer will simply modify the internal offset.
*
* @param URL A URL_t * pointing to a valid opened file or remote URL.
Expand Down
2 changes: 1 addition & 1 deletion libBigWig/bwRead.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int bwSetPos(bigWigFile_t *fp, size_t pos) {
}

//returns the number of full members read (nmemb on success, something less on error)
size_t bwRead(void *data, size_t sz, size_t nmemb, bigWigFile_t *fp) {
size_t bwRead(char *data, size_t sz, size_t nmemb, bigWigFile_t *fp) {
size_t i, rv;
for(i=0; i<nmemb; i++) {
rv = urlRead(fp->URL, data+i*sz, sz);
Expand Down
14 changes: 7 additions & 7 deletions libBigWig/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ CURLcode urlFetchData(URL_t *URL, unsigned long bufSize) {

//Read data into a buffer, ideally from a buffer already in memory
//The loop is likely no longer needed.
size_t url_fread(void *obuf, size_t obufSize, URL_t *URL) {
size_t url_fread(char *obuf, size_t obufSize, URL_t *URL) {
size_t remaining = obufSize, fetchSize;
void *p = obuf;
char *p = obuf;
CURLcode rv;

while(remaining) {
Expand All @@ -55,7 +55,7 @@ size_t url_fread(void *obuf, size_t obufSize, URL_t *URL) {
if(rv != CURLE_OK) {
fprintf(stderr, "[url_fread] urlFetchData (A) returned %s\n", curl_easy_strerror(rv));
return 0;
}
}
} else if(URL->bufLen < URL->bufPos + remaining) { //Copy the remaining buffer and reload the buffer as needed
p = memcpy(p, URL->memBuf+URL->bufPos, URL->bufLen - URL->bufPos);
if(!p) return 0;
Expand Down Expand Up @@ -86,7 +86,7 @@ size_t url_fread(void *obuf, size_t obufSize, URL_t *URL) {

//Returns the number of bytes requested or a smaller number on error
//Note that in the case of remote files, the actual amount read may be less than the return value!
size_t urlRead(URL_t *URL, void *buf, size_t bufSize) {
size_t urlRead(URL_t *URL, char *buf, size_t bufSize) {
#ifndef NOCURL
if(URL->type==0) {
return fread(buf, bufSize, 1, URL->x.fp)*bufSize;
Expand All @@ -98,9 +98,9 @@ size_t urlRead(URL_t *URL, void *buf, size_t bufSize) {
#endif
}

size_t bwFillBuffer(const void *inBuf, size_t l, size_t nmemb, void *pURL) {
size_t bwFillBuffer(const char *inBuf, size_t l, size_t nmemb, char *pURL) {
URL_t *URL = (URL_t*) pURL;
void *p = URL->memBuf;
char *p = URL->memBuf;
size_t copied = l*nmemb;
if(!p) return 0;

Expand Down Expand Up @@ -230,7 +230,7 @@ URL_t *urlOpen(const char *fname, CURLcode (*callBack)(CURL*), const char *mode)
fprintf(stderr, "[urlOpen] Couldn't set CURLOPT_WRITEFUNCTION!\n");
goto error;
}
if(curl_easy_setopt(URL->x.curl, CURLOPT_WRITEDATA, (void*)URL) != CURLE_OK) {
if(curl_easy_setopt(URL->x.curl, CURLOPT_WRITEDATA, (char*)URL) != CURLE_OK) {
fprintf(stderr, "[urlOpen] Couldn't set CURLOPT_WRITEDATA!\n");
goto error;
}
Expand Down
44 changes: 34 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
#!/usr/bin/env python
import os
from setuptools import setup, Extension
from distutils import sysconfig
import sysconfig
from pathlib import Path
import subprocess
import glob
import sys

srcs = [x for x in
srcs = [x for x in
glob.glob("libBigWig/*.c")]
srcs.append("pyBigWig.c")

libs=["m", "z"]
if sys.platform == "win32":
libs = ["zlib"]
else:
libs=["m", "z"]

# do not link to python on mac, see https://github.com/deeptools/pyBigWig/issues/58
if 'dynamic_lookup' not in (sysconfig.get_config_var('LDSHARED') or ''):
if sysconfig.get_config_vars('BLDLIBRARY') is not None:
if sysconfig.get_config_vars('BLDLIBRARY') is not None and sysconfig.get_config_vars('BLDLIBRARY') != [None]:
#Note the "-l" prefix!
for e in sysconfig.get_config_vars('BLDLIBRARY')[0].split():
if e[0:2] == "-l":
libs.append(e[2:])
elif sys.platform == "win32":
libs.append(f"python{sys.version_info[0]}{sys.version_info[1]}")
elif sys.version_info[0] >= 3 and sys.version_info[1] >= 3:
libs.append("python%i.%im" % (sys.version_info[0], sys.version_info[1]))
else:
libs.append("python%i.%i" % (sys.version_info[0], sys.version_info[1]))

additional_libs = [sysconfig.get_config_var("LIBDIR"), sysconfig.get_config_var("LIBPL")]
if sys.platform == "win32":
additional_libs = [sysconfig.get_config_var("installed_platbase")]
else:
additional_libs = [sysconfig.get_config_var("LIBDIR"), sysconfig.get_config_var("LIBPL")]

defines = []
try:
foo, _ = subprocess.Popen(['curl-config', '--libs'], stdout=subprocess.PIPE).communicate()
libs.append("curl")
foo, _ = subprocess.Popen(['sh', '-c', 'curl-config', '--libs'], stdout=subprocess.PIPE).communicate()
if sys.platform == "win32":
libs.append("libcurl")
else:
libs.append("curl")
foo = foo.decode().strip().split()
except:
foo = []
Expand Down Expand Up @@ -58,10 +69,23 @@
except ImportError:
pass

module1 = Extension('pyBigWig',
if sys.platform == "win32":
defines.append(("_CRT_SECURE_NO_WARNINGS", None))
include_dirs.extend([os.environ.get("ZLIB_ROOT") + "/include", "win32", "libBigWig"])
additional_libs.append(os.environ.get("ZLIB_ROOT") + "/lib")
module1 = Extension(
"pyBigWig",
sources=srcs,
libraries=libs,
library_dirs=additional_libs,
define_macros=defines,
include_dirs=include_dirs
)
else:
module1 = Extension('pyBigWig',
sources = srcs,
libraries = libs,
library_dirs = additional_libs,
library_dirs = additional_libs,
define_macros = defines,
include_dirs = include_dirs)

Expand Down
Loading