From 94b192b1340658d92df8e5dcf6a48d9f32f5f96e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Sep 2012 18:04:56 +0530 Subject: [PATCH 1/3] ... --- src/calibre/utils/podofo/output.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/calibre/utils/podofo/output.cpp b/src/calibre/utils/podofo/output.cpp index b0620f7f82..015949502a 100644 --- a/src/calibre/utils/podofo/output.cpp +++ b/src/calibre/utils/podofo/output.cpp @@ -37,14 +37,16 @@ class OutputDevice : public PdfOutputDevice { #ifdef _MSC_VER return _vscprintf(pszFormat, args); #else - char buf[10]; - int res; - res = vsnprintf(buf, 1, pszFormat, args); - if (res < 0) { - PyErr_SetString(PyExc_Exception, "Something bad happened while calling vsnprintf to get buffer length"); - throw pyerr(); + char *buf; + int res, len=1024; + while(true) { + buf = new (std::nothrow) char[len]; + if (buf == NULL) { PyErr_NoMemory(); throw pyerr(); } + res = vsnprintf(buf, len, pszFormat, args); + delete[] buf; + if (res >= 0) return res + 1; + len *= 2; } - return static_cast(res+1); #endif } From ae73428839849ba5495754104d738597f9006e4e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Sep 2012 18:06:19 +0530 Subject: [PATCH 2/3] ... --- src/calibre/utils/podofo/output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/utils/podofo/output.cpp b/src/calibre/utils/podofo/output.cpp index 015949502a..d72fd316fe 100644 --- a/src/calibre/utils/podofo/output.cpp +++ b/src/calibre/utils/podofo/output.cpp @@ -40,7 +40,7 @@ class OutputDevice : public PdfOutputDevice { char *buf; int res, len=1024; while(true) { - buf = new (std::nothrow) char[len]; + buf = new (std::nothrow) char[len+1]; if (buf == NULL) { PyErr_NoMemory(); throw pyerr(); } res = vsnprintf(buf, len, pszFormat, args); delete[] buf; From e6af33d5e911a386046226a6c724224fdcfddc6e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Sep 2012 19:38:46 +0530 Subject: [PATCH 3/3] Disable libusb/libmtp on OS X --- src/calibre/devices/mtp/unix/driver.py | 3 ++- src/calibre/devices/scanner.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/mtp/unix/driver.py b/src/calibre/devices/mtp/unix/driver.py index 338913114f..2f215f6353 100644 --- a/src/calibre/devices/mtp/unix/driver.py +++ b/src/calibre/devices/mtp/unix/driver.py @@ -27,7 +27,8 @@ def fingerprint(d): class MTP_DEVICE(MTPDeviceBase): - supported_platforms = ['linux', 'osx'] + # libusb(x) does not work on OS X. So no MTP support for OS X + supported_platforms = ['linux'] def __init__(self, *args, **kwargs): MTPDeviceBase.__init__(self, *args, **kwargs) diff --git a/src/calibre/devices/scanner.py b/src/calibre/devices/scanner.py index 6865546a54..e0bb74fa2a 100644 --- a/src/calibre/devices/scanner.py +++ b/src/calibre/devices/scanner.py @@ -292,7 +292,15 @@ if islinux: libusb_scanner = LibUSBScanner() if isosx: - osx_scanner = libusb_scanner + # Apparently libusb causes mem leaks on some Macs and hangs on others and + # works on a few. OS X users will just have to live without MTP support. + # See https://bugs.launchpad.net/calibre/+bug/1044706 + # See https://bugs.launchpad.net/calibre/+bug/1044758 + # osx_scanner = libusb_scanner + usbobserver, usbobserver_err = plugins['usbobserver'] + if usbobserver is None: + raise RuntimeError('Failed to load usbobserver: %s'%usbobserver_err) + osx_scanner = usbobserver.get_usb_devices if isfreebsd: freebsd_scanner = FreeBSDScanner()