Stefan Brüns [Thu, 26 Nov 2015 02:07:47 +0000 (03:07 +0100)]
output/analog: track and free memory for float conversion buffer
==18779== 800,000 bytes in 196 blocks are definitely lost in loss record 29 of 29
==18779== at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==18779== by 0x4E635C3: receive (analog.c:319)
==18779== by 0x40870B: datafeed_in (session.c:316)
==18779== by 0x4E59D4E: sr_session_send (session.c:1201)
==18779== by 0x4E59F8B: sr_session_send (session.c:1159)
==18779== by 0x4E62595: send_chunk (wav.c:234)
==18779== by 0x4E62A06: process_buffer (wav.c:290)
==18779== by 0x40954A: load_input_file_module (input.c:123)
==18779== by 0x4097AB: load_input_file (input.c:157)
==18779== by 0x40531E: main (main.c:288)
Stefan Brüns [Thu, 26 Nov 2015 02:04:39 +0000 (03:04 +0100)]
session: free memory for datafeed callbacks, reported by valgrind
==17549== 32 (16 direct, 16 indirect) bytes in 1 blocks are definitely lost in loss record 22 of 39
==17549== at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==17549== by 0x5359200: g_malloc (in /usr/lib64/libglib-2.0.so.0.4200.2)
==17549== by 0x536EE2D: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.4200.2)
==17549== by 0x5370165: g_slist_append (in /usr/lib64/libglib-2.0.so.0.4200.2)
==17549== by 0x4E595C3: sr_session_datafeed_callback_add (session.c:512)
==17549== by 0x409527: load_input_file_module (input.c:111)
==17549== by 0x4097AB: load_input_file (input.c:157)
==17549== by 0x40531E: main (main.c:288)
Stefan Brüns [Thu, 26 Nov 2015 01:30:42 +0000 (02:30 +0100)]
session: fix use after free of session->devs as reported by valgrind
==7478== Invalid write of size 8
==7478== at 0x4E59182: sr_session_dev_remove_all (session.c:302)
==7478== by 0x4E591CD: sr_session_destroy (session.c:265)
==7478== by 0x4095D9: load_input_file_module (input.c:143)
==7478== by 0x4097AB: load_input_file (input.c:157)
==7478== by 0x40531E: main (main.c:288)
==7478== Address 0x7877eb8 is 88 bytes inside a block of size 96 free'd
==7478== at 0x4C2A37C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==7478== by 0x4E5F454: sr_input_free (input.c:573)
==7478== by 0x4095C3: load_input_file_module (input.c:140)
==7478== by 0x4097AB: load_input_file (input.c:157)
==7478== by 0x40531E: main (main.c:288)
Daniel Elstner [Fri, 27 Nov 2015 13:32:28 +0000 (14:32 +0100)]
sysclk-lwla: Cut down on size_t overuse
Do not use size_t for values whose width is defined by the device,
not the host. Also don't use size_t for simple indices with known
small range, unless type compatibility considerations apply.
Daniel Elstner [Sun, 22 Nov 2015 16:45:54 +0000 (17:45 +0100)]
sysclk-lwla: Implement support for LWLA1016
Refactor the sysclk-lwla driver to separate the generic logic from
the model-specific implementation. Based on this, implement support
for the SysClk LWLA1016 device.
Uwe Hermann [Sat, 21 Nov 2015 19:27:25 +0000 (20:27 +0100)]
sr_usb_find(): Increase the 'bus' limit to 255.
On some systems it can happen that the USB 'bus' number is a lot larger
than 64, but sr_usb_find() currently errors out if it is > 64.
Example:
Bus 250 Device 006: ID 1ab1:04ce 1ab1 DS1000Z Series[...]
Increase that limit so that the code will work everywhere. This bus number
is queried via libusb_get_bus_number() which returns an uint8_t, so we're
limiting to 255 here.
Daniel Elstner [Mon, 2 Nov 2015 13:30:24 +0000 (14:30 +0100)]
build: Set CXXFLAGS when building Python module
Set both CFLAGS and CXXFLAGS when executing setup.py to build
the Python bindings. Newer versions of distutils/setuptools have
apparently started to pick up the latter when compiling C++.
Daniel Elstner [Sun, 1 Nov 2015 20:40:28 +0000 (21:40 +0100)]
build: Match up Python headers with interpreter version
Check for either Python 2 or Python 3 header files depending on
the version of the Python interpreter. Also require the module
version to exactly match the interpreter version.
With the current driver API and the corresponding session event
handling, it is not possible to destroy and then re-create an
event source with the same key within the same main loop iteration.
The next generation driver API will fix this problem. But for now,
just change the driver to make do without that sort of thing. Also
increase the I/O timeout to 100 ms to be safer in the event of all
kind of delays the OS environment may induce.
Daniel Elstner [Sat, 31 Oct 2015 09:19:51 +0000 (10:19 +0100)]
sysclk-lwla: Read full 64 bit of capture duration field
Evaluate all 64 bit of the duration field in the capture status
record. Although unlikely in practical use, due to compression
it is possible for the duration in ms to exceed 32 bit.
Daniel Elstner [Fri, 30 Oct 2015 14:07:25 +0000 (15:07 +0100)]
zip: Provide fallback if zip_discard() is unavailable
zip_discard() was introduced in libzip 0.11, which some systems
do not have yet. Provide a fallback replacement for zip_discard(),
and reduce the requirement to libzip 0.10 again.
Daniel Elstner [Thu, 29 Oct 2015 21:53:25 +0000 (22:53 +0100)]
C++: Declare std::default_delete friend as struct
std::default_delete<> is originally defined as struct, not class.
This does not really make much of a difference, but some compilers
complain when the struct/class tag is not consistent across all
declarations of the type.
Daniel Elstner [Thu, 29 Oct 2015 21:39:44 +0000 (22:39 +0100)]
build: Use common SWIG defines for Python and Java
Make the Python and Java bindings use the same set of preprocessor
macros for the SWIG parsing stage, taken from a make variable. Add
G_GNUC_{BEGIN,END}_IGNORE_DEPRECATIONS to that set.
Daniel Elstner [Sun, 25 Oct 2015 02:44:55 +0000 (03:44 +0100)]
sysclk-lwla: Read test word twice during initialization
During initialization of the LWLA1034, read the 64-bit test word
twice and verify the result of the second read only. This better
matches what the original vendor software does.
Daniel Elstner [Sun, 25 Oct 2015 01:26:44 +0000 (02:26 +0100)]
sysclk-lwla: Clarify function of registers 10B0 to 10BC
Apparently, these four registers form an interface for indirect
access to another internal 64 bit wide memory. This is likely the
same memory as that accessed by the bulk transfer commands 7 and 8.
Hannu Vuolasaho [Wed, 21 Oct 2015 16:04:37 +0000 (19:04 +0300)]
Support for regulation status and fix for mysterious M
Added support for SR_CONF_REGULATION which returns value for CH1
Also VELLEMAN LABPS3005D (only device currently supported) sends single
'M' character in beginning of return value, which is specially discarded.
Daniel Elstner [Mon, 26 Oct 2015 06:29:50 +0000 (07:29 +0100)]
Java: Avoid dangerous writes via casted pointers
Writing to an object through a pointer of incompatible type is
really evil. Even when the data size matches, it is still a
violation of strict aliasing rules.
Replace all instances by direct casts of the value, without the
unnecessary and dangerous indirection.
Daniel Elstner [Mon, 26 Oct 2015 06:04:10 +0000 (07:04 +0100)]
C++: Avoid const ref args to appease Java bindings
The Java bindings currently have some weird problem with function
arguments passed by const reference. Not all types are affected,
but the collection types that involve custom typemaps are.
For now, revert back to pass-by-value for the problematic types.
Daniel Elstner [Mon, 26 Oct 2015 04:18:06 +0000 (05:18 +0100)]
C++: Use C++98 syntax for default arguments to appease SWIG
Looks like SWIG silently ignores default arguments specified via
aggregate initialization. This is rather unfortunate, especially
if the argument types are complex.
Daniel Elstner [Thu, 15 Oct 2015 17:21:28 +0000 (19:21 +0200)]
C++: Replace custom deleters with std::default_delete
Replace custom Deleter classes with std::default_delete<>, declared
as friend so it can invoke the private destructor. Inexplicably,
std::shared_ptr<> does not use default_delete<> by default, so it
is still necessary to explicitly specify the deleter when creating
shared_ptr instances.
With this, unique_ptr and shared_ptr instances now use the same
default delete mechanism.
Daniel Elstner [Thu, 15 Oct 2015 16:32:44 +0000 (18:32 +0200)]
C++: Use smart pointers instead of manual delete
Make use of std::unique_ptr<> to manage the lifetime of members
or container elements, so that manual invocations of delete can
be avoided. This also provides for exception safety.
Since std::unique_ptr<> is only movable but not copyable, adapt
the code to avoid copies and assignments of these pointers.
Daniel Elstner [Sun, 11 Oct 2015 15:57:30 +0000 (17:57 +0200)]
C++: Move C struct pointers out of ownership classes
Reduce needless over-generalization. There is no design need
for the ParentOwned and UserOwned classes to contain the C base
struct pointer. Instead, just make the _structure pointer a
private member of each class that needs one.
Daniel Elstner [Sun, 11 Oct 2015 12:31:18 +0000 (14:31 +0200)]
SWIG: Hack around SWIG segfault on private destructors
Apparently this problem has been fixed in SWIG 3.0.6. However,
until we can require that version, define "private" as "protected"
when running the SWIG parser.
Daniel Elstner [Sun, 11 Oct 2015 11:57:42 +0000 (13:57 +0200)]
C++: Make value get accessors const
Declare accessor methods that return value members const. For now,
skip all cases where constness would have to be applied transitively
to shared objects.
Daniel Elstner [Sun, 11 Oct 2015 10:35:01 +0000 (12:35 +0200)]
C++: Make some methods static to match the C API
Context::package_version() and Context::lib_version() do not access
context state and should be static. However, leave the logging
related methods alone for now, as making them static would entail
making the callback data a global static, since the C API lacks
destroy notification callbacks.
Daniel Elstner [Wed, 14 Oct 2015 18:56:51 +0000 (20:56 +0200)]
C++: Declare all callbacks invoked from C noexcept
If one of these functions does throw an exception, std::terminate()
will be called. Without this, the behavior is undefined since the C
stack is not prepared to deal with exceptions.
Daniel Elstner [Sun, 11 Oct 2015 10:12:28 +0000 (12:12 +0200)]
SWIG: Define "noexcept" empty to work around SWIG bug
The SWIG 2.0.12 on my system bails out with a syntax error on the
"noexcept" keyword in C++11 code. Define "noexcept" to nothing (for
the SWIG parser only) to work around this problem.
Daniel Elstner [Sun, 11 Oct 2015 01:12:02 +0000 (03:12 +0200)]
C++: Use move() and avoid passing containers by value
Make use of std::move() to transfer arguments passed in by value.
Take complex container arguments by const reference, as passing
those by value is rather unorthodox even for C++11 style code.
Martin Ling [Tue, 20 Oct 2015 23:29:50 +0000 (00:29 +0100)]
java: Don't use SWIG attribute mechanism.
Using the attribute mechanism results in badly named wrappers like
getLog_level(), as well as incompletely applied typemaps for templated
container types. If we just avoid this mechanism entirely, we get the
same foo() and set_foo() accessors as we have in the C++ API.