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.
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>
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.
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>
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.
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.
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.
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.
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.
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:
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.
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>
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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().
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.