1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Commit Graph

461 Commits

Author SHA1 Message Date
Bartosz Golaszewski
e915ea6f53 bindings: python: gpiod v2.4.3
- don't decref objects on PyList_SetItem() failure
- check for errors after PyIter_Next() in request_get_values() and
  set_output_values()
- release the GIL in chip_get_info()

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-15 14:37:00 +02:00
Bartosz Golaszewski
da2d2ae66a bindings: python: release the GIL in chip_get_info()
Other methods that call into the C library (chip_get_line_info,
chip_watch_line_info, etc.) properly release the GIL with
Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS, but chip_get_info() was
missed. Add the missing GIL release for consistency and to avoid
blocking other Python threads during the ioctl.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-14-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:20:00 +02:00
Bartosz Golaszewski
81b732d9b5 bindings: python: check for errors after PyIter_Next() in set_output_values
PyIter_Next() returns NULL both at end-of-iteration and when an exception
is raised. The code breaks out of the loop without checking
PyErr_Occurred(), potentially swallowing Python exceptions and continuing
with a partially filled buffer.

Add the missing error check.

Fixes: 27a69b0bfd ("bindings: python: add the output_values argument to Chip.request_lines()")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-13-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:20:00 +02:00
Bartosz Golaszewski
c88f678e36 bindings: python: check for errors after PyIter_Next() in request_get_values
PyIter_Next() returns NULL both at end-of-iteration and when an exception
is raised. The code breaks out of the loop without checking
PyErr_Occurred(), potentially swallowing Python exceptions and continuing
with a partially filled buffer.

Add the missing error check.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-12-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:20:00 +02:00
Bartosz Golaszewski
3124d90db2 bindings: python: don't decref objects on PyList_SetItem() failure
PyList_SetItem() steals the reference to the object we want to add
regardless of whether it succeeds or fails. Don't decrease the reference
count of the object we failed to add in error path.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Closes: https://github.com/brgl/libgpiod/issues/187
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260511111538.60844-1-bartosz.golaszewski@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-12 09:30:16 +02:00
Bartosz Golaszewski
268286995d bindings: python: gpiod v2.4.2
- fix heap-buffer overflow bugs on setting/getting values
- remove duplicated edge detection setting

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-09 10:49:49 +02:00
Bartosz Golaszewski
057aab6517 bindings: python: remove duplicated edge detection setting
In line_settings_init() we call gpiod_line_settings_set_edge_detection()
twice unnecessarily. Remove the second call.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Reported-by: 4fqr <4fqr@proton.me>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260407-treewide-fixes-v1-2-66c9744a56a3@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-09 09:33:29 +02:00
Bartosz Golaszewski
c3655b5f64 bindings: python: fix heap-buffer overflow bugs on setting/getting values
The C extension methods request_set_values() and request_get_values()
iterate over a caller-supplied sequence and write offsets/values into
pre-allocated buffers self->offsets and self->values, without checking
the write index.

If the user tries to read values for more lines than they previously
requested, we overflow the buffers.

Add appropriate bounds checks and implement test cases for this issue.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Reported-by: 4fqr <4fqr@proton.me>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260407-treewide-fixes-v1-1-66c9744a56a3@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-09 09:33:29 +02:00
Bartosz Golaszewski
d9d3ef9042 bindings: python: gpiod v2.4.1
- fix a Py_None reference leak
- fix setuptools dependency
- ship the license file with dist artifacts
- remove egg-info during clean

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-03-10 13:35:23 +01:00
Vincent Fazio
c921c813db bindings: python: remove egg-info during clean
The egg-info directory gets generated when a distribution is built so
should be removed when `make clean` is run.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260228185213.31442-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-03-02 12:19:53 +01:00
Vincent Fazio
51ee19fe1e bindings: python: copy the license into distributions
Previously, the bindings called out the SPDX license identifier in the
pyproject.toml but did not include a copy of the license in either the
source or binary distributions.

This can be problematic for tools that rely on extracting license
information, such as Buildroot or other license auditing mechanisms.

Now, when distributions are built, the license is copied out of the
libgpiod source tarball and into the target distribution.

Closes: https://github.com/brgl/libgpiod/issues/162
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260228184158.25003-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-03-02 12:19:52 +01:00
Vincent Fazio
f26d5c9f2b bindings: python: require newer setuptools
When commit d9b156ecc2 updated pyproject.toml to conform to PEP 639
we failed to make sure the build dependencies were updated to support
the new structure.

Support for PEP 639 was added to setuptools in v77.0.0 [0] so minimally
require that version in `build-system.requires` to avoid failures.

Link: https://setuptools.pypa.io/en/latest/history.html#v77-0-0 # [0]
Fixes: d9b156ecc2 ("bindings: python: make licensing information conform with PEP 639")
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260217005314.31016-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-02-18 09:26:22 +01:00
Bartosz Golaszewski
8a3058296d bindings: python: add missing Py_None reference increment
For lines with no name, chip_get_line_name() returns Py_None but does
not increment its reference count. Do it enough times and the following
error will occur with cpython before v3.12:

  Fatal Python error: none_dealloc: deallocating None: bug likely caused by a refcount error in a C extension

Add the missing Py_INCREF(). It's safe to do even on python >= v3.12 as
Py_INCREF() has no effect on immortal objects in more recent versions.

Fixes: 0c0993569c ("bindings: python: ext: add ability to query line name")
Reported-by: Pierre Gramme <pgramme@gmail.com>
Closes: https://github.com/brgl/libgpiod/issues/166
Link: https://lore.kernel.org/r/20260113092852.42573-1-bartosz.golaszewski@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-01-13 16:12:16 +01:00
Bartosz Golaszewski
e1d5096c6d bindings: python: gpiod v2.4.0
Changelog:
- make request and reconfigure behavior for lines requested by names
  consistent with that of lines requested by offsets
- fix parsing non-tuple keys when requesting a line
- disable UP045 linter check
- use quoted types when casting
- generate wheels for CPython 3.14
- issue a warning when reconfiguring a line not in the original request
- update dependencies for wheel generation
- update licensing information
- coding style fixes
- minor performance improvements

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-24 16:34:39 +02:00
Vincent Fazio
d62f3be0c4 bindings: python: bump cibuildwheel to 3.2.1
Version 3.2.1 uses images CPython 3.14.0 final instead of 3.14.0-rc3.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251022160406.1810450-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-23 10:01:47 +02:00
Vincent Fazio
962a1924e1 bindings: python: line_request: warn on unknown lines when reconfiguring
Previously, attempting to reconfigure a line that was not included in
the original request provided no feedback to the caller that there was
invalid data in the request.

Now, emit a warning when an unknown offset or line name is encountered.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-10-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
6a7d3306e4 bindings: python: chip: map names for lines requested by offset
Previously, lines requested by name could also be referred to by offset
when calling LineRequest.reconfigure_lines. However, lines requested by
offset could not be reconfigured by name if they had one.

Now, the name map is populated if the line has a name regardless of if
it's requested by name or offset.

To make behavior as consistent with earlier versions as possible, a line
requested by name always returns the first line on the chip with that
name. If there are duplicate line names and lines are requested by
offset, the first line in the request is mapped to the name. A line
requested by name always overrides a name mapped via an offset request.

If lines 0-3 all have the same name and a config object looks like:
  {("foo", 1, 2): None}
or
  {(1, "foo", 2): None}

Then lines 0-2 are requested and line 0 can be reconfigured by name.

If the config object looks like:
  {(1, 2): None}

Then lines 1 and 2 are requested and line 1 can be reconfigured by name.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-9-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
0c0993569c bindings: python: ext: add ability to query line name
Investigation has shown that the construction of the Enum values to
create the LineInfo object is expensive [0].

Add a method to retrieve the line name from a given offset without the
overhead of generating a full LineInfo object.

[0]: https://github.com/brgl/libgpiod/issues/149#issuecomment-3319448712

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-8-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
e2d7b6abaf bindings: python: line_request: ignore invalid line names in reconfigure_lines
Previously, calling `reconfigure_lines` with line identifiers that were
not included in the original request produced different behaviors
depending on the identifier type.

If the identifier was an integer, it would be silently ignored.

If the identifier was a string, it would raise a `ValueError`.

To be consistent, invalid line names are now silently ignored.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-7-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
0110c11626 bindings: python: chip: check mapped_output_values membership once
Simplify looking up mapped output values by providing a default value to
dict.get instead of checking for membership in the dict and then
fetching the value subsequently.

While hashing and lookup is fast, it's unnecessary overhead.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-6-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
ea21b447d7 bindings: python: chip: simplify duplicate checking
Previously, a check was performed to prevent requests that included
duplicative lines.

While this provided quick feedback on erroneous requests, it penalized
callers that had a good config due to the over head of iterating the
config multiple times.

Now, duplicate check is performed as the config object is iterated.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-5-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
728a2f9b22 bindings: python: chip: track requested lines when enumerating
Previously, an offset map was maintained to lookup the name used to
request a line so that a list could be generated that reflected the
identifier used to request a given line.

For example, if a config looked like {0: None, ("foo", "bar"): None}, the
LineRequest.lines property would contain [0, "foo", "bar"].

Now, the line identifier is tracked in request order as the config
object is iterated to avoid maintaining an offset map.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-4-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
11aa4254b2 bindings: python: remove unused attribute from LineRequest
The _offset_map attribute was a map of offset -> line name. Values were
only inserted when a line was requested via name. As this map is never
utilized, remove it.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-3-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
8c9d5b4fdf bindings: python: make config iteration consistent
Previously, Chip.request_lines and LineRequest.reconfigure_lines
iterated over a config object but did so in subtly different ways.

Create a generator that iterates over a config object and returns line +
settings pairs. Update the aforementioned functions to use the generator
to consolidate and condense code.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20251009130516.3729433-2-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Bartosz Golaszewski
2838c7604a bindings: python: fix coding style in setup.py
Add a missing newline and make black happy.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Bartosz Golaszewski
63a264079f bindings: glib: don't install examples
Example programs using the libgpiod GLib bindings are erroneously
installed under $(prefix)/bin/. Change the bin_PROGRAMS make variable
to noinst_PROGRAMS to fix it.

Fixes: e090088c21 ("bindings: add GLib bindings")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-01 09:50:48 +02:00
Bartosz Golaszewski
2eab5e896f bindings: rust: add examples to the README.md in the libgpiod crate
Add some code examples to the README.md with the aim of showing how to
use the bindings on the crates.io landing page for the libgpiod crate.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250926-rust-release-tweaks-v1-3-beae932eb691@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-30 09:53:22 +02:00
Bartosz Golaszewski
d0f1291f41 bindings: rust: update formatting to --edition 2024
Update the formatting of all rust source files to be up to date with the
2024 rust edition.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250926-rust-release-tweaks-v1-2-beae932eb691@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-30 09:53:22 +02:00
Bartosz Golaszewski
e549494229 bindings: rust: complete the unification of imports in examples
Commit cd32f27dd5 ("bindings: rust: unify imports in examples") failed
to consistently unify the code across all examples so finish the
process.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250926-rust-release-tweaks-v1-1-beae932eb691@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-30 09:52:58 +02:00
Vincent Fazio
97ee308728 bindings: python: generate wheels for CPython 3.14
Update cibuildwheel to add support for generating 3.14 wheels.

Configuration options for cibuildwheel have been moved to pyproject.toml
to keep it in line with other tools used by the bindings.

The configuration has been updated to skip generating free-threaded
wheels since the bindings do not support free-threaded builds [0] and
cibuildwheel generates them by default starting with CPython3.14 [1].

[0]: https://github.com/brgl/libgpiod/issues/117
[1]: https://github.com/pypa/cibuildwheel/pull/2503

Closes: https://github.com/brgl/libgpiod/issues/138
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20250923200737.3177136-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-26 11:54:44 +02:00
Vincent Fazio
36f1e51b37 bindings: python: use quoted types when casting
Linter check T006 [0] recommends using quotes around types (making them
strings) when casting values to a type to avoid the overhead of runtime
type evaluation.

This provides a small performance benefit at runtime [1].

  >>> timeit(lambda: cast(gpiod._ext.Request, "a"), number=100000000)
  6.4817840601317585
  >>> timeit(lambda: cast("gpiod._ext.Request", "a"), number=100000000)
  4.369633618975058

This also allows moving some imports behind type checking guards as they
are not required at runtime.

[0]: https://docs.astral.sh/ruff/rules/runtime-cast-value/
[1]: https://github.com/snok/flake8-type-checking/issues/119#issuecomment-2511022212

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20250909125300.3507377-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-09 15:04:54 +02:00
Vincent Fazio
4db8707554 bindings: python: disable UP045 linter check
Linter check UP045 [0] was recently stabilized in ruff 0.12 [1].

UP045 suggests using the `X | Y` syntax for files that perform:

  from __future__ import annotations

This import drives the Python interpreter to store type annotations as
strings and defers their evaluation [2] making the new syntax "safe".

See also [3] for a brief history.

For now, disable the UP045 linter warnings like we do UP007 [4] for the
sake of consistency within the bindings so there is no mixed usage of
`Union[X, Y]` and `Optional[X]` vs `X | Y` until the bindings minimally
target Python 3.10 and can move to the latter syntax.

[0]: https://docs.astral.sh/ruff/rules/non-pep604-annotation-optional/
[1]: de4fc5b171
[2]: https://peps.python.org/pep-0563/#implementation
[3]: https://peps.python.org/pep-0649/#a-history-of-annotations
[4]: https://docs.astral.sh/ruff/rules/non-pep604-annotation-union/

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20250907142919.1382670-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-09 11:24:36 +02:00
Bartosz Golaszewski
d30bcd7b2e tests: update library API version string tests
The version string returned by gpiod_api_version() is now stricter and
will always be of the form: x.y.z where x, y and z are unsigned integer
numbers. We no longer have to parse various suffixes so update the test
cases tree-wide.

Acked-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250903-api-version-detach-v1-4-027ca5928518@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-09 10:24:00 +02:00
Bartosz Golaszewski
aeb74d629b bindings: cxx: move misc.hpp inclusion to the correct place
The symbols from gpiodcxx/misc.hpp are correctly exported to users of
gpiod.hpp because it's implicitly pulled in by line-request.hpp but
that's incorrect: line-request.hpp has no need for any of the symbols
from misc.hpp and it should be part of the set of headers included by
the top-level gpiod.hpp. Move it to the correct place.

Acked-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250903-api-version-detach-v1-1-027ca5928518@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-09 10:24:00 +02:00
Vincent Fazio
1f2ba0deab bindings: python: parse non-tuple Iterable keys
When `chip.request_lines` was modified to allow `Iterable`s instead of
only `tuple`s, the code that checked for duplicate line entries in the
`config` argument was not updated to account for the expanded types.

If the `config` argument had a key that was not a `tuple`, `str`, or
`int`, a `TypeError` would be raised when resolving the line offset.

Refactor the code the resolves IDs to offsets into a separate function
to make the logic a bit clearer and to account for the widened types.

Fixes: 8f62e6c453 ("bindings: python: loosen type requirements in public API")
Closes: https://github.com/brgl/libgpiod/issues/148
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20250902123905.6491-1-vfazio@gmail.com
[Bartosz: don't pass the only argument by name in the call to
_resolve_config_keys_to_offsets()]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-08 09:29:13 +02:00
Bartosz Golaszewski
d0006cc3d5 bindings: rust: update crate versions to v1.0.0
Ahead of the first stable release, update versions for all libgpiod
crates to v1.0.0.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-10-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
efc39de44a bindings: rust: update intmap dependency
Bump the intmap dependency for libgpiod to the most recent major version.
The IntMap type now takes two explicit type arguments for the key and
value so adjust the code accordingly. No longer require a specific minor
version.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-9-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
751a37fa37 bindings: rust: update thiserror dependency
Bump the thiserror dependency for libgpiod to the most recent major
version. No code changes required. No longer require a specific minor
version.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-8-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
4b9924ff31 bindings: rust: update system-deps dependency
Bump the system-deps dependency for libgpiod-sys to the most recent major
version. The way we iterate over libs has changed, we now need to convert
it explicitly to an iterable. No longer require a specific minor
version.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-7-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
00c224897d bindings: rust: update cc dependency
Bump the cc dependency for gpiosim-sys to the most recent version which
happens to be a minor upgrade from the one we have currently. However:
let cargo select it automatically by no longer specifying the minor
number. No code changes required.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-6-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
1430eb1e91 bindings: rust: update errno dependency
Bump the errno dependency for gpiosim-sys and libgpiod crates to the
most recent version which is a minor update from the one we have now.
However: let cargo select it automatically by not specifying the bugfix
version. We need to be stricter than just selecting the major version
alone because crates with major versions starting with 0 can introduce
breaking changes in minor releases. No code changes required.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-5-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
e40018f9cc bindings: rust: update bindgen dependency
Bump bindgen dependency in both gpiosim-sys and libgpiod-sys to the most
recent version. We now need to call CargoCallbacks::new() when boxing
the ParseCallbacks trait.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-4-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
ec4486fde1 bindings: rust: bump the minimum required rustc version
In order to satisfy the requirements of more recent versions of bindgen
and system-deps, bump the minimum required rustc version to v1.78.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-3-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
07b65bb307 bindings: rust: add missing unsafe block ahead of rust version bump
Rust edition 2024 changed the semantics of the unsafe keyword used as
function modifier[1]. Unsafe operations inside unsafe functions must
still be wrapped in an unsafe {} block. Update the code in case we want
to bump the rust version or check it with clippy --edition 2024.

[1] https://rust-lang.github.io/rfcs/2585-unsafe-block-in-unsafe-fn.html

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-2-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
fafd5e6180 bindings: rust: make Buffer::read_edge_events() lifetimes more explicit
Fix an issue pointed out by newer rustc version in the Buffer struct.
struct Events stores a reference to the buffer so tie the lifetime of the
latter to it explicitly.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250828-rust-1-0-0-release-v3-1-0f9c6c1c4808@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-01 10:23:50 +02:00
Bartosz Golaszewski
cd32f27dd5 bindings: rust: unify imports in examples
Some example source files avoid imports at the top of the file in favor
of overusing the namespaces in the code itself. The ones that do import
modules either group the imports or have a separate "use" in each line.
Let's unify the imports in example and use the brief approach of
grouping the modules inside use statements.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250723-rust-examples-imports-v1-2-4c87e07a9b79@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-07-24 11:26:41 +02:00
Bartosz Golaszewski
8da049f2d7 bindings: rust: fix formatting in examples
Use rustfmt to fix formatting of println!() in two examples. The lines
here don't need to be broken as they don't reach the character limit.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250723-rust-examples-imports-v1-1-4c87e07a9b79@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-07-24 11:26:41 +02:00
Erik Wierich
6263abf3ab bindings: rust: simplify format statements
clippy suggested these:

    warning: variables can be used directly in the `format!` string
       --> libgpiod/src/lib.rs:113:9
        |
    113 |         write!(f, "{:?}", self)
        |         ^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
        = note: `#[warn(clippy::uninlined_format_args)]` on by default
    help: change this to
        |
    113 -         write!(f, "{:?}", self)
    113 +         write!(f, "{self:?}")
        |

Generated with `cargo clippy --fix`.

The suggestions look like an improvement to me.

Signed-off-by: Erik Wierich <erik@riscstar.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lore.kernel.org/r/20250721-rust-clippy-v1-2-2ac0198b2ea6@riscstar.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-07-21 14:01:19 +02:00
Erik Wierich
b20401360c bindings: rust: remove newline between attribute and attribute
These are block attributes, but the newline in between suggests that
they are for the whole module.

Fixes clippy warning:

    warning: empty line after outer attribute
     --> libgpiod-sys/src/lib.rs:6:1
      |
    6 | / #[cfg_attr(test, allow(deref_nullptr, non_snake_case))]
    7 | |
      | |_^
    8 |   mod bindings_raw {
      |   ---------------- the attribute applies to this module
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr
      = note: `#[warn(clippy::empty_line_after_outer_attr)]` on by default
      = help: if the empty line is unintentional, remove it
    help: if the attribute should apply to the crate use an inner attribute
      |
    5 ~ #![allow(non_camel_case_types, non_upper_case_globals)]
    6 ~ #![cfg_attr(test, allow(deref_nullptr, non_snake_case))]
      |

Signed-off-by: Erik Wierich <erik@riscstar.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lore.kernel.org/r/20250721-rust-clippy-v1-1-2ac0198b2ea6@riscstar.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-07-21 14:01:19 +02:00
Erik Wierich
f1a949f827 bindings: rust: rename constructors that wrap raw objects to from_raw
This matches the stdlib conventions[1] and seems easier to read to me.

[1] https://doc.rust-lang.org/stable/std/?search=from_raw

Signed-off-by: Erik Wierich <erik@riscstar.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lore.kernel.org/r/20250721-rust-unsafe-consistency-v1-2-aa1b42ed5983@riscstar.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-07-21 13:59:49 +02:00