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.
The most commonly used cleanup attribute is the one used for automatic
closing of GPIO chips. For brevity: hide the long TEST_CLEANUP(...)
invocation behind a shorter TEST_CLEANUP_CHIP macro.
Clemens Gruber [Tue, 20 Feb 2018 16:57:32 +0000 (17:57 +0100)]
tools: move function attributes to the header file
The attributes must be located next to function declarations in the
header file. Otherwise, the NORETURN attribute seems to have no effect
and GCC emits several Wimplicit-fallthrough warnings when compiling
libgpiod. This patch fixes those warnings.
Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com> Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
For enums describing direction & active state, event types etc. use 1
as the first value as it's easier to debug when all valid values are
different than in a zero-initialized data structure.
Also: the master branch doesn't contain the tags for bugfix releases so
documenting them in this branche's NEWS makes no sense.
Fold all the info about bugfix releases into the next minor release and
only keep major and minor releases in NEWS on the master branch. Bugfix
releases will only be documented in their respective minor branches
from now on.
doc: improve the doxygen description of default_val(s)
Users report being confused by the name 'default_val(s)' for function
parameters. Because it's in line with the kernel uAPI, we'll leave it
like this, but let's improve the documentation a bit by stating
explicitly that this parameter represents the initial values for
requested GPIO lines.
API: use gpiod_ctxless_ as prefix for the high-level API
As suggested by Linus Walleij: the word 'simple' is generally
subjective and the high-level routines provided by libgpiod are not
necessarily simple, but rather contextless, as they don't require any
resource managemend. Use 'gpiod_ctxless_' as prefix for all high-level
symbols.
Clemens Gruber [Mon, 22 Jan 2018 16:12:13 +0000 (17:12 +0100)]
gpiomon: initialize the active low variable
The variable active_low is not initialized, so the value is undefined
and if the -l argument is not passed, the undefined value remains. Fix
it by initializing it to false.
Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com> Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
This project contains both a library and executables so it's better to
use an umbrella term "This program ..." than "This library ..." in all
the source files.