Bartosz Golaszewski [Fri, 15 Feb 2019 12:16:57 +0000 (13:16 +0100)]
bindings: python: fix argument alignment in a function call
When breaking a line, the arguments should be aligned with the opening
bracket of the function call.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Bartosz Golaszewski [Thu, 14 Feb 2019 16:07:15 +0000 (17:07 +0100)]
tests: gpiomon: remove failing test case
Since commit
fa38869b0161 ("gpiolib: Don't support irq sharing for
userspace") in the kernel, the test case veryfing correct ignoring
of edge events is failing. It will take a while until it will be
fixed upstream so remove this test for now.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Michael Beach [Sat, 9 Feb 2019 15:06:18 +0000 (00:06 +0900)]
bindings: cxx: make bitset_cmp::operator() const
This fixes build problems with clang and libc++ and such constness is
now required by C++17 (see https://cplusplus.github.io/LWG/issue2542).
Signed-off-by: Michael Beach <michaelb@ieee.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Patrick Boettcher [Sun, 3 Feb 2019 12:29:14 +0000 (13:29 +0100)]
bindings: cxx: do not initialize a chip's shared_ptr with nullptr
A shared_ptr initialized with nullptr will still call the deleter which
causes a NULL-pointer dereference if we create a chip_iter when there
are no GPIO chips in the system.
Only initialize the current chip object in chip_iter if
gpiod_chip_iter_next_noclose() returned a valid pointer.
Signed-off-by: Patrick Boettcher <p@yai.se>
[Bartosz:
- tweaked the commit message
- use std::move when assigning the chip object]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Bartosz Golaszewski [Thu, 3 Jan 2019 10:46:25 +0000 (11:46 +0100)]
gpioset: extend help text
There's a common misconception about the way the character device
works. Some users expect line states to be driven as desired even
after gpioset exits. Add a note about that to the help text to avoid
further confusion.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 14 Nov 2018 10:15:30 +0000 (11:15 +0100)]
treewide: unify naming of local variables representing return values
For integers representing simple return values of various functions
use the name 'rv' everywhere.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Gasper Zejn [Fri, 23 Feb 2018 13:51:19 +0000 (14:51 +0100)]
doc: C API documentation fixes
Fix a couple problems in doxygen documentation of the C API.
(Unfortunately no Signed-off-by tag from the submitter...)
[Bartosz: added a proper commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 12 Nov 2018 15:43:03 +0000 (16:43 +0100)]
tests: ignore 'remove' events from udev
So far the tests have been executed on a Debian 9 machine with libudev
provided by systemd 232 - everything always worked fine. However
running them on a system with systemd 237 uncovered a bug in the
testing framework.
It turned out that on newer versions the ignored 'remove' events linger
somewhere in the pipeline and get read by subsequent test cases causing
erroneous chip naming and breaking tests.
Check the action string for udev device objects and only care about
those being added.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 9 Nov 2018 09:08:18 +0000 (10:08 +0100)]
libgpiod: start v1.3 development cycle
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 8 Nov 2018 18:36:02 +0000 (19:36 +0100)]
libgpiod v1.2
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 8 Nov 2018 18:26:31 +0000 (19:26 +0100)]
NEWS: updates for v1.2
Add release notes for libgpiod v1.2.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 7 Nov 2018 20:29:02 +0000 (21:29 +0100)]
build: check for sys/sysmacros.h in configure
We now need this header to build the core library.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 7 Nov 2018 15:55:52 +0000 (16:55 +0100)]
core: add missing include
Not including <sys/sysmacros.h> causes the following error on ARM:
core.c: In function ‘is_gpiochip_cdev’:
core.c:116:4: warning: implicit declaration of function ‘major’ [-Wimplicit-function-declaration]
major(statbuf.st_rdev), minor(statbuf.st_rdev));
^~~~~
core.c:116:28: warning: implicit declaration of function ‘minor’; did you mean ‘mknod’? [-Wimplicit-function-declaration]
major(statbuf.st_rdev), minor(statbuf.st_rdev));
^~~~~
mknod
It wasn't spotted earlier since it builds fine on x86-64. Add the
missing include.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 5 Nov 2018 02:57:17 +0000 (03:57 +0100)]
core: harden gpiod_chip_open()
Verify that the file we were asked to use is really a GPIO character
device.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 3 Nov 2018 11:56:48 +0000 (12:56 +0100)]
tools: tweak the formatting of help text strings
Add an additional newline between the summary and the options list
for better readability.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 7 Oct 2018 13:49:50 +0000 (15:49 +0200)]
Merge branch 'next'
This introduces the new context-less event monitor with specifiable
event types and a small tweak in configure.ac.
Bartosz Golaszewski [Tue, 2 Oct 2018 14:30:37 +0000 (16:30 +0200)]
API: mark context-less event loop functions as deprecated
Mark gpiod_ctxless_event_loop() and gpiod_ctxless_event_loop_multiple()
as deprecated. Those functions suffer from an issue where HW may not
allow setting up both rising and falling egde interrupts. All users
have been converted to using the new event monitor helpers.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 2 Oct 2018 12:49:17 +0000 (14:49 +0200)]
API: add a macro for marking deprecated functions
We want to deprecate the badly designed event loop functions. Introduce
a macro that allows marking API routines as deprecated.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 7 Oct 2018 08:56:38 +0000 (10:56 +0200)]
tests: ctxless: add a test case for the event monitor
Add a test case verifying that the event callback is not called for
events we're not monitoring.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 2 Oct 2018 15:23:30 +0000 (17:23 +0200)]
tests: ctxless: switch to using the event monitor routines
Use gpiod_ctxless_event_monitor() and
gpiod_ctxless_event_monitor_multiple() instead of
gpiod_ctxless_event_loop() and gpiod_ctxless_event_loop_multiple()
respectively.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 2 Oct 2018 15:05:38 +0000 (17:05 +0200)]
gpiomon: switch to using gpiod_ctxless_event_monitor_multiple()
Switch to using the new context-less routine for event monitoring. We
can now simplify the event callback as there's no need anymore to
check the event type in the handler.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 27 Sep 2018 08:47:14 +0000 (10:47 +0200)]
ctxless: provide new event monitor
Current implementation of gpiod_ctxless_event_loop() (and its variant
for multiple lines) always requests GPIO lines for listening for both
rising and falling edge events. This causes a problem when the
underlying hardware doesn't allow this.
It can e.g. result in the following error raised by the interrupt
controller:
genirq: Setting trigger mode 3 for irq 107 failed (kempld_irq_set_type+0x0/0x130 [gpio_kempld])
For the sake of backward compatibility we're leaving the old
implementation in place and provide two new routines that that take an
additional parameter allowing users to specify the events libgpiod
should listen for.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
SZ Lin (林上智) [Wed, 26 Sep 2018 09:47:10 +0000 (17:47 +0800)]
bindings: cxx: examples: add missing include
This patch adds proper include file to fix FTBFS issue in
gpiod_cxx_tests.cpp, please see below error.
gpiod_cxx_tests.cpp:29:19: note: 'std::function' is defined in header '<functional>'; did you forget to '#include <functional>'?
gpiod_cxx_tests.cpp:26:1:
+#include <functional>
Signed-off-by: SZ Lin (林上智) <sz.lin@moxa.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 2 Oct 2018 15:53:27 +0000 (17:53 +0200)]
build: don't use unicode characters in configure.ac
Replace unicode apostrophes with their ASCII counterparts.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 24 Aug 2018 15:25:10 +0000 (17:25 +0200)]
build: tools: remove unnecessary line breaks
There are only two source files in the list so don't break the line
too eagerly.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 26 Jul 2018 13:59:19 +0000 (15:59 +0200)]
bindings: python: pydoc improvements
Current documentation of python bindings is quite limited. Extend it
with more elaborate descriptions of types and methods.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 31 Jul 2018 12:33:40 +0000 (14:33 +0200)]
bindings: python: bail-out if the line was not found in gpiofind.py
Currently we're not checking if the object returned from
gpiod.fine_line() is None which results in an attribute error being
raised when we try to call line methods on a non-line object.
Add an if and bail-out with an error code if the line with given name
was not found.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 30 Jul 2018 13:05:53 +0000 (15:05 +0200)]
bindings: python: fix gpiod_Chip_find_lines() for nonexistent lines
Currently if we call gpiod_Chip_find_lines() with some names that
cannot be looked up, we end up getting an exception from the LineBulk
object's constructor (because None is not a Line and LineBulk can only
hold Line objects).
Fix the behavior of gpiod_Chip_find_lines() for nonexistent lines by
raising an explicit exception if the underlying gpiod_Chip_find_line()
call returns None. Also: add a relevant test case.
Fixes: 96c524c4951c ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 30 Jul 2018 12:49:17 +0000 (14:49 +0200)]
bindings: python: remove a redundant if
We don't need to check if bulk is NULL in gpiod_Chip_find_lines()
before returning it.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 27 Jul 2018 11:52:18 +0000 (13:52 +0200)]
bindings: python: examples: close chip objects where needed
Unlike the C++ bindings: we can't expect the python runtime to call
the Chip object's destructor when all references are dropped. We need
to close each chip explicitly. Either call the close() method directly
or use controlled execution in all examples.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 26 Jul 2018 11:09:34 +0000 (13:09 +0200)]
build: add a comment about libtool version to configure.ac
The libtool version only applies to the core C library, not to tools
or python bindings. C++ bindings have a separate libtool version.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Jul 2018 13:09:35 +0000 (15:09 +0200)]
tools: tweak the displayed version format
Prepend the version string with a 'v' to stay consistent with git
tags we're using.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 24 Jul 2018 12:12:18 +0000 (14:12 +0200)]
bindings: python: fix tp_dealloc callbacks in all objects
We have a significant memory leak in the current implementation as we
don't call PyObject_Del() as the last action in tp_dealloc callbacks.
From tp_dealloc's documentation:
---
The destructor function should free all references which the instance
owns, free all memory buffers owned by the instance (using the freeing
function corresponding to the allocation function used to allocate the
buffer), and finally (as its last action) call the type’s tp_free
function.
---
PyObject_Del() will internally call the tp_free callback of the type.
Add a call to it as the last action in every destructor.
Fixes: 96c524c4951c ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 22 Jul 2018 19:26:47 +0000 (21:26 +0200)]
bindings: python: don't force python to use the system allocator
When allocating raw memory let python decide which allocator to use.
Convert all calls to PyMem_Raw*() to PyMem_*().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 22 Jul 2018 18:12:40 +0000 (20:12 +0200)]
bindings: python: examples: new test case
Add a test case for incorrect number of default values in line
requests.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 22 Jul 2018 13:23:59 +0000 (15:23 +0200)]
bindings: python: don't call gpiod_LineBulk_init() directly
We can instantiate an object of a type by "calling" it's type structure
using PyObject_CallObject(). It will internally call the constructor so
use it to shrink the code.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 20 Jul 2018 08:27:53 +0000 (10:27 +0200)]
bindings: python: add test cases for default values in line requests
Add two new tests verifying the default_vals argument in line requests
for single and multiple lines.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 20 Jul 2018 08:13:59 +0000 (10:13 +0200)]
bindings: python: fix the default_vals argument in line requests
We're assigning the wrong local variable in PyArg_ParseTupleAndKeywords()
which results in not honoring the default_vals argument. Fix the
LineBulk.request() implementation.
Fixes: 96c524c4951c ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 13 Jul 2018 17:47:37 +0000 (19:47 +0200)]
bindings: python: examples: remove unnecessary import
We no longer need sys in gpiod_tests.py. Remove it.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 13 Jul 2018 16:34:50 +0000 (18:34 +0200)]
bindings: python: move gpiod_ChipIsClosed() to the top of gpiodmodule.c
Unlike the other two helpers that are still declared at the top of the
source file - this routine doesn't need to know any gpiod-specific type
so move it up and remove the prototype.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 13 Jul 2018 14:00:23 +0000 (16:00 +0200)]
bindings: python: examples: don't use sys.argv[0] as consumer string
Strings with slashes trigger a warning in the kernel in
fs/proc/generic.c. Use a hardcoded consumer string.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 13 Jul 2018 13:57:25 +0000 (15:57 +0200)]
bindings: python: call gpiod_LineBulk_init() directly
Using the .tp_init callback is more complicated and unnecessary. Call
gpiod_LineBulk_init() directly from gpiod_ListToLineBulk().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 13 Jul 2018 13:07:47 +0000 (15:07 +0200)]
bindings: python: provide a helper for calling methods with python args
Wrap the calls to PyObject_GetAttrString() and PyObject_Call() in
a single helper that allows to call a python method and pass it the
args and kwds tuples directly as received from the interpreter.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 13 Jul 2018 09:21:31 +0000 (11:21 +0200)]
bindings: python: fix a memory corruption
PyList_GetItem() returns a borrowed reference so we need to increase
the reference count on the returned object before DECREF'ing the list
object itself
This fixes random 'free(): invalid pointer' errors.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 13 Jul 2018 08:10:34 +0000 (10:10 +0200)]
bindings: python: fix a memory leak in error path
We need to decref the iter object in Line.set_values() if the
conversion from python to C unsigned integer fails.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 6 Jun 2018 15:01:44 +0000 (17:01 +0200)]
bindings: python: fix a warning
On some architectures we get a 'comparison between signed and unsigned
integer' warning when building python bindings. Fix it by changing the
type of the variable used for offset to unsigned int.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 6 Jun 2018 10:49:00 +0000 (12:49 +0200)]
bindings: python: add a test case for line_event's __repr__
Check if an event's representation string is generated correctly.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 6 Jun 2018 10:26:23 +0000 (12:26 +0200)]
bindings: python: avoid calling object method callbacks directly
Where it's impossible to use PyObject_CallMethod() (e.g. when we want
to pass args and kwargs unchanged to the method being called), use
a combination of PyObject_GetAttrString() and PyObject_Call().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 6 Jun 2018 10:15:54 +0000 (12:15 +0200)]
bindings: python: use PyObject_CallMethod() where possible
Avoid directly calling method callbacks. Use the routine provided by
Python API instead where possible.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 6 Jun 2018 09:25:06 +0000 (11:25 +0200)]
libgpiod: start v1.2 development cycle
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 16 May 2018 13:28:39 +0000 (15:28 +0200)]
libgpiod v1.1
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 16 May 2018 12:30:36 +0000 (14:30 +0200)]
NEWS: updates for v1.1
Add release notes for libgpiod v1.1.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 16 May 2018 12:14:12 +0000 (14:14 +0200)]
bindings: cxx: set the ABI version to 1.0.0
The C++ bindings ABI that will be released in v1.1 is considered
stable. Set it to 1.0.0 for the release.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 16 May 2018 10:18:40 +0000 (12:18 +0200)]
bindings: python: add support for controlled execution
Provide __enter__ and __exit__ callbacks for Chip so that it can be
used with the 'with' statement.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 16 May 2018 09:53:18 +0000 (11:53 +0200)]
bindings: python: provide better resource control
So far we rely on cpython's reference counting for closing the GPIO
chips and freeing the underlying resources. This is however wrong.
Python doesn't guarantee anything regarding the lifetime of an object.
Provide a method for closing the underlying chip handle and add
relevant checks to all methods using the resources associated with
a GPIO chip, so that we raise an error should the user use a chip
after closing it.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 16 May 2018 08:36:28 +0000 (10:36 +0200)]
bindings: python: provide gpiod.version_string()
Implement a python wrapper around gpiod_version_string().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 16 May 2018 08:11:57 +0000 (10:11 +0200)]
doc: tweak the comment for gpiod_version_string()
Make it clear that this function returns the API version as we now have
separate API and ABI versions.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 16:35:16 +0000 (18:35 +0200)]
bindings: python: test case for line flags
Add a new test case verifying that line flags work as expected.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 16:33:47 +0000 (18:33 +0200)]
bindings: python: provide Line.is_requested()
Add a python wrapper around gpiod_line_is_requested().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 16:12:20 +0000 (18:12 +0200)]
bindings: python: improve readability in test cases
Mostly just add new lines for improved readability.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 12:51:00 +0000 (14:51 +0200)]
bindings: python: new test cases/examples
Add more test cases/code examples for python bindings.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 10:04:25 +0000 (12:04 +0200)]
bindings: python: provide Chip.get_all_lines()
Add a method for retrieving all GPIO lines exposed by a chip.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 09:50:16 +0000 (11:50 +0200)]
bindings: python: improve readability
Order the arguments in a reverse christmas tree shape in
gpiod_Chip_find_lines();
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 09:49:16 +0000 (11:49 +0200)]
bindings: python: code shrink
Provide a helper for converting a list of lines into a LineBulk object
in a single call.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 15 May 2018 09:41:52 +0000 (11:41 +0200)]
bindings: python: implement Chip.find_lines()
Provide a method for looking up multiple lines by name at once.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 9 May 2018 20:01:47 +0000 (22:01 +0200)]
bindings: python: extend tests
Add more test cases/examples, implement some helper functions, tweak
the output messages, mention the need for a dummy chip in the system
in the module's pydoc string.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 14 May 2018 09:20:23 +0000 (11:20 +0200)]
bindings: python: change the return value of gpiod_LineBulk_event_wait()
gpiod_Line_event_wait() works differently than its LineBulk
counterpart. While the latter returns either a list of lines or False,
the former returns True if an event occurred on this line or False
otherwise.
False is not a good counterpart for an actual object, so instead return
None if no events occurred on any of the monitored lines.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 14 May 2018 09:18:18 +0000 (11:18 +0200)]
bindings: python: fix a memory leak in gpiod_Line_event_wait()
We don't return the object returned from gpiod_LineBulk_event_wait()
back to the interpreter. We need to collect it before returning True.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 13 May 2018 21:34:38 +0000 (23:34 +0200)]
bindings: cxx: fix the return value of line_bulk::find_lines()
We should return an invalid line_bulk object if we failed to look up at
least one line from the provided list of names.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 13 May 2018 21:25:06 +0000 (23:25 +0200)]
bindings: python: fix a memory leak in Line.set_value()
We're not collecting the bulk object we're creating in this method. Add
Py_DECREF() where needed.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 13 May 2018 11:56:49 +0000 (13:56 +0200)]
helpers: provide gpiod_chip_find_lines()
Implement a new helper that allows to look-up multiple GPIO lines by
their names. Include a set of test cases.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 12 May 2018 12:48:58 +0000 (14:48 +0200)]
bindings: python: return None if line can't be found by name
For both find_line() variants (Chip's method and global function)
return None if the internal call to the C find_line function fails
with ENOENT. This is not an error so don't raise an exception.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 12 May 2018 12:30:44 +0000 (14:30 +0200)]
bindings: python: decref the chip object in gpiod_Module_find_line()
When returning back to the interpreter from gpiod_Module_find_line(),
there's only one chip object reference holder, but we set the refcount
to 2 (as if the chip object existed separately in the interpreter).
Fix it by decreasing the chip's refcount by one before returning the
line object.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 9 May 2018 20:23:14 +0000 (22:23 +0200)]
bindings: cxx: add test cases for iterators
Add simple tests for chip and line iterators.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 2 May 2018 10:19:39 +0000 (12:19 +0200)]
bindings: cxx: new test cases
Implement more test cases for C++ bindings and extend the existing
ones.
While we're at it: use auto where applicable and log to stderr instead
of stdout.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 9 May 2018 12:05:20 +0000 (14:05 +0200)]
bindings: cxx: add a comment about the need for a dummy chip to run tests
In order to run the C++ tests/examples, we need at least one dummy chip
to be present in the system. It also needs to be the first GPIO chip.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 9 May 2018 11:19:30 +0000 (13:19 +0200)]
bindings: cxx: initialize the line_request flags before using them
We store the flag values in the request flags mapping before
initializing them so flags don't get translated correctly in
line_bulk::request(). Fix it by moving the flag definitions above the
mapping initialization.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 8 May 2018 20:55:02 +0000 (22:55 +0200)]
bindings: cxx: export static members of gpiod::line_request
The static flags definitions of gpiod::line_request are not exported.
Add the missing GPIOD_API attributes.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 7 May 2018 20:15:51 +0000 (22:15 +0200)]
bindings: cxx: fix SPDX license identifiers in examples
The source files in bindings/cxx/examples still use C-style comments
for SPDX license identifiers. Use C++-style comments for consistency
with all other source files in the repository.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 21 Apr 2018 13:37:19 +0000 (15:37 +0200)]
bindings: python: release the GIL during blocking I/O operations
We should release the python global interpreter lock when performing
blocking operations and reacquire it again when we're done. Use the
relevant APIs provided by libpython.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 21 Apr 2018 13:31:30 +0000 (15:31 +0200)]
README: add info about building from release tarballs
There's no need to use autogen.sh if building from release tarballs as
the configure script is already provided. Only git builds need
autoreconf.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 21 Apr 2018 13:29:33 +0000 (15:29 +0200)]
README: add info about high-level bindings
Briefly describe C++ and python bindings.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Fri, 20 Apr 2018 09:54:51 +0000 (11:54 +0200)]
build: fix cross-compilation of python bindings
AX_PYTHON_DEVEL macro from the autoconf-archive collection doesn't work
when we're trying to cross-compile python bindings in environments such
as buildroot or yocto. It can't properly detect the location of python
headers.
Let's use AM_PATH_PYTHON to detect the python3 interpreter and then
either take the PYTHON_CPPFLAGS and PYTHON_LIBS variables from the
environment (so that cross-compiling build systems can pass their
custom locations to autotools) or try to detect them ourselves using
the python3-config tool.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 18 Apr 2018 15:44:52 +0000 (17:44 +0200)]
build: check for unexpanded macros in configure.ac
We're now using m4 macros from the autoconf-archive collection. The
user may be missing this package so check for unexpanded AX_* macros
and bail-out if any are found.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Mon, 19 Feb 2018 11:52:38 +0000 (12:52 +0100)]
bindings: implement python bindings
Create a C extension module wrapping the functionality of libgpiod
in a set of Python classes.
Add code examples including simplified reimplementations of gpio-tools
in Python.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sat, 14 Apr 2018 20:20:53 +0000 (22:20 +0200)]
core: events: correctly handle POLLNVAL in gpiod_line_event_wait()
The only error that can be indicated by ppoll() in the revents field
of struct pollfd when polling a line events file descriptor is
POLLNVAL. It can happen if the user calls close() on said descriptor
after retrieving it with gpiod_line_event_get_fd().
Currently we would act as if there's a line event to read. Make
gpiod_line_event_wait() and its bulk variant return -1 and set errno
to EINVAL in this case.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 12 Apr 2018 15:15:44 +0000 (17:15 +0200)]
tools: fix the copyright notice
The copyright notice displayed together with the package version using
the --version argument got accidentally modified by commit
0704bcdbbf56
("all: update the copyright notice") and is now incorrect. Fix it.
Fixes: 0704bcdbbf56 ("all: update the copyright notice")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 12 Apr 2018 12:51:09 +0000 (14:51 +0200)]
build: tweak the message emitted after building tests
The kernel version displayed in the message has not been updated the
last time we bumped the kernel version required for running tests.
We don't need to print this version here - the test suite will bail-out
anyway if the kernel is too old. Drop it from the message.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Thu, 12 Apr 2018 10:28:18 +0000 (12:28 +0200)]
core: use reference counting for line file descriptors
In v0.x series we were using a separate, refcounted structure for
storing the file descriptor returned by the linehandle request ioctl().
We also had a separate mechanism for event file descriptors. This was
quite complicated and was replaced by a simpler structure in v1.x
series.
It turned out however that we're now calling close() on already closed
descriptors when releasing a set of simultaneously requested lines.
In order to fix that we need to go back to having a refcounted file
descriptor handle. This time we're using the same structure for storing
both values and events file descriptors (even though there can't be
more than one line per descriptor requested for events) for simplicity.
This patch also adds a test case that verifies the reference counting
works as expected.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Wed, 4 Apr 2018 11:19:05 +0000 (13:19 +0200)]
license: use C++-style comments for SPDX headers in source files
Follow the linux kernel licensing style and only use C-style comments
in C headers.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 3 Apr 2018 08:05:29 +0000 (10:05 +0200)]
tests: gpioinfo: expect default direction to be input
Starting with linux v4.16 the direction of gpio-mockup lines is input
by default as is the case for all real gpio drivers.
Modify the expected strings in test cases for gpioinfo and make v4.16
the minimum kernel version to run libgpiod tests.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 13 Mar 2018 17:14:48 +0000 (18:14 +0100)]
build: use separate versioning schemes for API & ABI
Commit
783ff2e3c707 ("API: start certain enums from 1") broke the ABI
compatibility (while keeping the source compatibility). We need to
indicate that to the users by changing the SONAME string. Up until now
the SONAME would correspond with the major release number. We now need
to have a separate versioning schemes for API and ABI.
Keep using the same MAJOR.MINOR.RELEASE scheme for the API, but switch
to using the libtool versioning - CURRENT.REVISION.AGE - for ABI. Start
the ABI version from 2.0.0 to indicate that it changed since 1.0.0.
Define a separate ABI version for the C++ bindings, but start with 0.0.0
since it was not a part of any release yet.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 4 Mar 2018 11:12:56 +0000 (12:12 +0100)]
build: user SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in the remaining
build and helper files.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 4 Mar 2018 11:09:27 +0000 (12:09 +0100)]
bindings: cxx: use SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in C++ bindings
directory.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 4 Mar 2018 09:50:11 +0000 (10:50 +0100)]
include: use SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in the public
API header and the corresponding Makefile.am.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 4 Mar 2018 09:37:34 +0000 (10:37 +0100)]
core: use SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in core source
files.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 4 Mar 2018 09:32:25 +0000 (10:32 +0100)]
tests: use SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in source files
of the testing framework.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 27 Feb 2018 12:48:08 +0000 (13:48 +0100)]
bindings: cxx: rename the C++ tests executable
Include the project's prefix in the executable name.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Tue, 27 Feb 2018 12:41:46 +0000 (13:41 +0100)]
bindings: cxx: rename line_bulk::add() to line_bulk::append()
This routine adds the line at the end of the internal list of lines.
Rename it to append() in case we ever want to introduce prepend().
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Bartosz Golaszewski [Sun, 25 Feb 2018 13:18:56 +0000 (14:18 +0100)]
bindings: cxx: don't check the chip's label and name for empty strings
The core library guarantees that a GPIO chip will have a name and
a label. No need to check if the returned strings are empty.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>