babeltrace.git
7 months agopython: run isort on everything
Simon Marchi [Tue, 19 Sep 2023 18:45:05 +0000 (14:45 -0400)] 
python: run isort on everything

Run isort on the whole repo, to nicely sort Python imports.

Add a mention in CONTRIBUTING.adoc, that all Python imports must be
sorted using the version of isort specified in dev-requirements.txt.

Add `isort ~= 5.12` to dev-requirements.txt.  5.12 is the latest stable
version available on PyPi as of writing.

Tell isort to use its `black` profile, in pyproject.toml, so that
black remains happy.  The details of that profile are here:

  https://pycqa.github.io/isort/docs/configuration/profiles.html

Tell isort to ignore `tests/utils/python/tap`, since it's code copied
from elsewhere.

Use the `length_sort` option, because Philippe prefers it like that.
See:

  https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html

Change-Id: I8778f908342d0feeb97d4442506113d9252559e7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10871
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agoDocument usage of Black in CONTRIBUTING.adoc
Simon Marchi [Fri, 15 Sep 2023 19:55:20 +0000 (15:55 -0400)] 
Document usage of Black in CONTRIBUTING.adoc

Mention that all Python code must be formatted using Black.

Change-Id: I420c4e5a75b34eae40da83ae09d5fd76d8eddb0f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10888
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agopython: remove internal `import bt2` imports
Simon Marchi [Mon, 28 Aug 2023 21:01:58 +0000 (17:01 -0400)] 
python: remove internal `import bt2` imports

Standardize the internal imports to import specific modules like this:

    from bt2 import foo as bt2_foo

... instead of importing the complete bt2 package.

Change-Id: I32eb223a8bcfe841020a2aafb976f121dadd8680
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10388
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agopython: move exception types out of __init__.py
Simon Marchi [Mon, 19 Jun 2023 18:47:15 +0000 (14:47 -0400)] 
python: move exception types out of __init__.py

Move exception types defined in __init__.py.

 - Move _MemoryError to error.py
 - Move _IncompleteUserClass to component.py
 - Move the others to utils.py

I initially moved them to a new exceptions.py file, but I think that
it's just fine to move them in the existing files.  But it's a
possibility too, if y'all prefer that.

The goal of this commit is to make it easier to use these types
internally, using the form:

    from bt2 import utils as bt2_utils

    ... use bt2_utils.TryAgain ...

... in order to get rid of the internal `import bt2` imports.

Note that it would be possible to keep the exception types in
__init__.py and do:

    from bt2 import TryAgain

... and then use `TryAgain` in the code, but I think we prefer using a
module qualifier for whatever is imported.

Change-Id: I7d8dbdc28a3a2e3e38093903d622487a45fe7637
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10387
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agopython: standardize intra-bt2 imports
Simon Marchi [Mon, 19 Jun 2023 18:11:04 +0000 (14:11 -0400)] 
python: standardize intra-bt2 imports

A subsequent patch wants to refer to `object` (the Python type), but it
is shadowed by our `from bt2 import object` import.  It seems like a
good time to standardize how we import intra-bt2 modules, to use the
pattern:

    from bt2 import potato as bt2_potato

Note that I didn't add the bt2_ prefix to the native_bt import, since it
would be a bit redundant.

Change-Id: Icdb4339075a1888463c4f84b292deb272ad49943
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10386
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agoBump black to version 23
Simon Marchi [Wed, 15 Mar 2023 19:45:28 +0000 (15:45 -0400)] 
Bump black to version 23

Bump to the latest available black version.

Change-Id: I62360ab9137ab2a5eb7fcc4dbbed913bfacee2e1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9650
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agoctf: fix formatting in ctf-meta-resolve.cpp
Simon Marchi [Tue, 12 Sep 2023 18:18:56 +0000 (14:18 -0400)] 
ctf: fix formatting in ctf-meta-resolve.cpp

Run tools/format-cpp.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Iea7165c5996b5ce62790ddb9df69e4e8e5014240
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10891
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agocpp-common/bt2/message.hpp: add missing `#include`
Philippe Proulx [Wed, 6 Sep 2023 15:48:38 +0000 (11:48 -0400)] 
cpp-common/bt2/message.hpp: add missing `#include`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I35fe9d7ed01e4272252fb0918371ef5251a90438
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10847
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
7 months agosrc.ctf.fs: add GMappedFileUP
Simon Marchi [Thu, 9 Jun 2022 19:49:39 +0000 (15:49 -0400)] 
src.ctf.fs: add GMappedFileUP

Add GMappedFileUP, a unique_ptr type used to manage the lifetime of a
GMappedFile object.

Change-Id: Ibc47d3c6e052499013cb34782b112ff1e72eab46
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8311
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10846
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add GDirUp
Simon Marchi [Thu, 9 Jun 2022 15:37:51 +0000 (11:37 -0400)] 
cpp-common: add GDirUp

Add GDirUP, a unique_ptr type to manage the lifetime of GDir objects.

Change-Id: I8814db0bec41918203af2f6d43a97a3e8d13c8c1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8294
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10845
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add GStringUP
Simon Marchi [Thu, 9 Jun 2022 15:23:33 +0000 (11:23 -0400)] 
cpp-common: add GStringUP

Add a type to automatically manage the lifetime of GString objects.

Change-Id: I60e08f7d62c290c0194ed0cd62b0d0491b9af2bd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8288
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10844
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add FileUP
Simon Marchi [Sat, 28 May 2022 18:18:17 +0000 (14:18 -0400)] 
cpp-common: add FileUP

Add a unique_ptr type to manage the lifetime of a `FILE *`, with a
custom deleter that calls fclose.

Change-Id: Idded4546d2a709cd0652975ef83c3ad6a0f511bc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8172
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10843
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add GCharUP
Simon Marchi [Sat, 28 May 2022 14:36:08 +0000 (10:36 -0400)] 
cpp-common: add GCharUP

Add GCharUP, a unique_ptr type that wraps a g_char pointer and has a
deleter that calls g_free.  It can be used to provide automatic memory
management of buffers returned by the GLib API.

Change-Id: I9d98be2f972cc008877b55a20eceeb3dce256cdb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8170
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10842
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add `readFixedLenInt()` function
Francis Deslauriers [Wed, 25 May 2022 15:20:53 +0000 (11:20 -0400)] 
cpp-common: add `readFixedLenInt()` function

This function template reads an integer from a buffer without assuming
its byte order.

For example, this is needed when reading the magic number from a data
buffer of unknown byte order. If needed, the user then has to manually
swap byte order of that integer to get its native byte order

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ia94ee3a3ffc7caaa46a46defead3e23da0a4c2b2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8111
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10841
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add fixed-length integer reading functions
Philippe Proulx [Mon, 25 Apr 2022 15:10:04 +0000 (11:10 -0400)] 
src/cpp-common: add fixed-length integer reading functions

This patch adds `src/cpp-common/read-fixed-len-int.hpp` which offers
function templates to read fixed-length integers from a buffer.

The bt2_common::readFixedLenIntLe() (little endian) and
bt2_common::readFixedLenIntBe() (big endian) function templates accept
one template parameter which is the integral type of the integer to read
(and the return type of the function). For example,
bt2_common::readFixedLenIntLe<std::int32_t>() reads a 32-bit signed
little-endian integer and returns it.

The function templates use bt2_common::littleEndianToNative() and
bt2_common::bigEndianToNative() as needed.

You may combine this with `bt2_common::StdIntT` to have the length in
bits and the signedness as independent template parameters, for
example:

    const auto val = readFixedLenIntBe<StdIntT<16, true>>(myBuf);

which is equivalent to:

    const auto val = readFixedLenIntBe<std::int16_t>(myBuf);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9c684bede60f7b6324a3140c5fd498c21ad513ab
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7939
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10840
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd `src/cpp-common/std-int.hpp`
Philippe Proulx [Thu, 19 May 2022 12:38:05 +0000 (08:38 -0400)] 
Add `src/cpp-common/std-int.hpp`

This new header contains the `StdIntT` trait structure to get the
standard integer type from a length (bits) and a signedness.

For example, `bt2_common::StdIntT<32, true>::Type` is `std::int32_t`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I69fc9ac7e01c2a82e4ad13afa553ef8e8720bd57
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8086
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10839
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add bt2_common::messageTypeStr()
Simon Marchi [Wed, 3 Aug 2022 15:56:15 +0000 (11:56 -0400)] 
cpp-common: add bt2_common::messageTypeStr()

Change-Id: I6967d232922c7b5ad6b35cc100becb9ff8a6b968
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8651
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10838
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add vectorFastRemove
Simon Marchi [Tue, 28 Jun 2022 18:26:53 +0000 (14:26 -0400)] 
cpp-common: add vectorFastRemove

Add the vectorFastRemove function, in src/cpp-common/vector.hpp, as a
drop-in replacement for g_ptr_array_remove_index_fast, when replacing a
GPtrArray with an std::vector.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ibee249fd9a8168d02ad99abf36984bf7edd53b5b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8493
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10837
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agotests: add `--port` option to lttng_live_server.py
Simon Marchi [Thu, 30 Jun 2022 17:15:46 +0000 (13:15 -0400)] 
tests: add `--port` option to lttng_live_server.py

This is useful when testing manually, to force using a specific port.
When not specified, we still use an OS-assigned port, so it doesn't
change the behavior when used by the testsuite.

Change-Id: Ic530bf13ddfa37fa1095c1e52a6c78f284e2c312
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8215
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10836
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: bt2::CommonOptionField::hasField(): use has_value()
Philippe Proulx [Wed, 10 Aug 2022 15:16:05 +0000 (11:16 -0400)] 
Fix: bt2::CommonOptionField::hasField(): use has_value()

Can't convert `nonstd::optional<ConstField>` to `bool` for some reason
in this context.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I539700da37eb0c27944e2f2842b09df8c2b1b023
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10835
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/bt2: field.hpp: Add assignment operator for Enum field
Francis Deslauriers [Wed, 1 Jun 2022 13:27:57 +0000 (09:27 -0400)] 
cpp-common/bt2: field.hpp: Add assignment operator for Enum field

Used to set the value of enumeration fields using integers.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Iaec161ca8e9e0d13770ac4f82a9c5556a1a20001
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8199
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10834
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: Add `bt2::CommonStringField::append()` method
Francis Deslauriers [Tue, 31 May 2022 14:52:15 +0000 (10:52 -0400)] 
cpp-common: Add `bt2::CommonStringField::append()` method

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I42217dd06cf53511718d97839bda4f9d0a0ed784
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8196
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10833
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: message.hpp: add `asDiscardedPackets()` function
Francis Deslauriers [Mon, 30 May 2022 20:00:28 +0000 (16:00 -0400)] 
cpp-common: message.hpp: add `asDiscardedPackets()` function

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I909290879d90806124119b00d91f5ad17d176abc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8189
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10832
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agotrace-ir.hpp: pass `UuidView` object to `CommonTrace::uuid()` method
Francis Deslauriers [Mon, 30 May 2022 19:58:31 +0000 (15:58 -0400)] 
trace-ir.hpp: pass `UuidView` object to `CommonTrace::uuid()` method

To simplify the code, the ctf::ir::TraceCls returns a Uuid, so accepting
a UuidView here makes it trivial to pass the return of one to the other.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I1f7a8fa51d932d764d77cd8dafe087cbf89f77b7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8188
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10831
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: trace-ir.hpp: spurious reference on object creation
Francis Deslauriers [Mon, 30 May 2022 19:55:14 +0000 (15:55 -0400)] 
Fix: trace-ir.hpp: spurious reference on object creation

We create a variant field class, which initially has refcount == 1.  We
then call `.shared()`, which creates another reference, bringing the
refcount to 2.

Fix that by using the `Shared::createWithoutRef()` method.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idfe8184497a00d3192e390017d7717c7ff9a3344
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8187
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10830
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: trace-ir.hpp: no need to provide a bt2::Trace to create a bt2::Trace
Francis Deslauriers [Mon, 30 May 2022 19:28:27 +0000 (15:28 -0400)] 
Fix: trace-ir.hpp: no need to provide a bt2::Trace to create a bt2::Trace

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I3d1af5c8c9057a7a252f2e2a72313cc71bf396f8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8186
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10829
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: field.hpp: various typos
Francis Deslauriers [Mon, 30 May 2022 17:53:46 +0000 (13:53 -0400)] 
Fix: field.hpp: various typos

 * `Common{Unsigned, Signed}IntegerField` is derived by the
   `Common{Unsigned,Signed}EnumerationField` class so can't be final.

 * `CommonSignedIntegerField::value` should be `int64_t`.

 * Calling single precision function instead of double.

 * `CommonStringField::operator=` methods can throw.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ib354f0bd4edc8f625494acedac1052c7f45ec67d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8185
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10828
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: integer-range-set.hpp: calling `_get_ref()` rather than `_put_ref()`
Francis Deslauriers [Mon, 30 May 2022 17:41:36 +0000 (13:41 -0400)] 
Fix: integer-range-set.hpp: calling `_get_ref()` rather than `_put_ref()`

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ic7c381d7dd7f2c5780f7678e48b76d23e8f3ca00
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8183
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10827
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/bt2: pass wrappers by value instead of by reference
Philippe Proulx [Mon, 30 May 2022 12:08:10 +0000 (08:08 -0400)] 
cpp-common/bt2: pass wrappers by value instead of by reference

This is the convention elsewhere when using those wrappers as they only
contain a single pointer.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I23d73f6447a90372df349cb75afe56db28afc9aa
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8177
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10826
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add SharedObj::release
Simon Marchi [Sat, 28 May 2022 14:01:44 +0000 (10:01 -0400)] 
cpp-common: add SharedObj::release

It will sometimes be needed to extract the ownership of a lib object
from a SharedObj, and get the underlying lib object pointer.  For
example:

 - The value returned by queries
 - Messages returned by iterators

Add a SharedObj::release method for that.  The return type is a borrowed
object (e.g. bt2::Value::Shared::release returns a bt2::Value), but
conceptually the caller then owns the reference and is responsible for
manually managing it.

After a release, a Shared object becomes invalid, same as when it is moved
from.

Change-Id: Id31855512b8dd3d5223f2e759ff48f81ceadbfbf
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8169
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10825
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/bt2: use classes from `cpp-common/exc.hpp`
Philippe Proulx [Mon, 30 May 2022 11:46:26 +0000 (07:46 -0400)] 
cpp-common/bt2: use classes from `cpp-common/exc.hpp`

This patch:

* Renames `lib-error.hpp` to `exc.hpp` as this could contain non-error
  exceptions in the future.

* Changes `bt2::Error`, `bt2::MemoryError`, and `bt2::OverflowError` to
  be aliases of `bt2_common::Error`, `bt2_common::MemoryError`, and
  `bt2_common::OverflowError`.

  This makes it possible for some code to catch only the common
  `bt2_common` errors to handle both library and user/internal
  exceptions.

  Note that those exceptions don't carry much information themselves;
  they're usually just a signal that an exception occurred, while the
  details are part of the libbabeltrace2 error of the current thread.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5bc1d39c8d978c21604614c68012509edc1776d5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8176
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10824
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd `bt2_common::OverflowError`
Philippe Proulx [Mon, 30 May 2022 11:41:01 +0000 (07:41 -0400)] 
Add `bt2_common::OverflowError`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9c524bed2374b7472e5603740c1c146f49371fe5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8175
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10823
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: improve C++ UUID utilities
Simon Marchi [Thu, 30 Mar 2023 16:14:09 +0000 (12:14 -0400)] 
src/cpp-common: improve C++ UUID utilities

Philippe Proulx writing below.

This patch improves the C++ common UUID utilities.

Francis wrote the initial version of `bt2_common::Uuid`, and then we
worked together to improve many little things at once, leading to this
patch.

His original message was:

> Add `bt2_common::Uuid`
>
> This patch adds the `bt2_common::Uuid` class which represent UUIDs.
>
> `Uuid` instances can be created from byte array, strings, or
> bt2_common::UuidView objects.
>
> The generate() static method returns a Uuid object with newly
> generated UUID.
>
> The operator UuidView() method returns a bt2_common::UuidView object
> representing the entire content of the UUID.
>
> The data() method returns a const pointer to the underlying
> std::array<>.
>
> The str() method returns a new `std::string` instance containing the
> canonical string representation of the UUID.

The final improvements are:

* Add said `bt2_common::Uuid` class.

  I also added the operator[](), operator=(), isNil(), begin(), and
  end() methods, the `Val` and `ConstIter` aliases, and the fact that
  most of the class relies on creating a `bt2_common::UuidView` to wrap
  itself when needed.

  data() just returns `const Val *`.

* In `bt2_common::UuidView`:

  * Make the class `final`.

  * Add the `Val` and `ConstIter` aliases.

  * Add operator<(): makes it possible to use a `bt2_common::UuidView`
    as an `std::set` value type or as an `std::map` key type, and to use
    it with STL algorithms.

  * Make size() `constexpr`.

  * Rename string() to str() for consistency with internal C++ naming.

  * Add begin() and end().

  * Add operator=() which accepts a UUID pointer.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id049953aecc51562e5939db546cb7d82bbaf88eb
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10822
Tested-by: jenkins <jenkins@lttng.org>
7 months agoMake `bt2_common::UuidView` final
Philippe Proulx [Mon, 2 May 2022 14:08:03 +0000 (10:08 -0400)] 
Make `bt2_common::UuidView` final

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I79ea919d497065256a445fc0faeb59e4267a466a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7972
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10821
Tested-by: jenkins <jenkins@lttng.org>
7 months agoRename bt2_common::UuidView::string() -> str()
Philippe Proulx [Mon, 2 May 2022 14:07:30 +0000 (10:07 -0400)] 
Rename bt2_common::UuidView::string() -> str()

More consistent with other internal C++ naming.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I552d4941b882215a302d8c02ea17bb018db79c5a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7971
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10820
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd bt2_common::UuidView::operator<()
Philippe Proulx [Mon, 2 May 2022 14:01:54 +0000 (10:01 -0400)] 
Add bt2_common::UuidView::operator<()

Makes it possible to use a `bt2_common::UuidView` as an `std::set` value
type or an `std::map` key type.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I297afa3c4ef00939ca3de659e1e72ced93a3310e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7970
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10819
Tested-by: jenkins <jenkins@lttng.org>
7 months agoMake bt2_common::UuidView::size() `constexpr`
Philippe Proulx [Mon, 2 May 2022 13:59:42 +0000 (09:59 -0400)] 
Make bt2_common::UuidView::size() `constexpr`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iffaae7d39ffa9fffb5c40988f82f5a5d78174115
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7969
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10818
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add bt2_common::align()
Philippe Proulx [Fri, 22 Apr 2022 12:11:22 +0000 (08:11 -0400)] 
src/cpp-common: add bt2_common::align()

This is a templated C++ version of the BT_ALIGN() macro found in
`src/common/align.h`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I0062778831d20cf19fe28bfa82c867473f7cf50b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7928
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10817

7 months agosrc/cpp-common: add bt2_common::safeTo*() and bt2_common::safe*()
Philippe Proulx [Fri, 15 Apr 2022 17:08:10 +0000 (13:08 -0400)] 
src/cpp-common: add bt2_common::safeTo*() and bt2_common::safe*()

This patch adds the following function templates, under the `bt2_common`
namespace, within the new `src/cpp-common/safe-ops.hpp` header:

safeToMul():
    Returns whether or not you can safely multiply two numbers without
    causing an overflow.

safeToAdd():
    Returns whether or not you can safely add two numbers without
    causing an overflow.

safeToSub():
    Returns whether or not you can safely subtract two numbers without
    causing an underflow.

safeMul():
    Multiplies some number by another, asserting that it's safe to do
    so, and returns the result.

safeAdd():
    Adds some number and another, asserting that it's safe to do so, and
    returns the result.

safeSub():
    Subtract some number from another, asserting that it's safe to do
    so, and returns the result.

Those are similar to the existing bt_safe_*() C functions, except that:

* They're function templates, so you can use any numeric type.

* The safeTo*() function templates are `constexpr`.

* They only work with unsigned types; signed types introduce some
  complexity (negative values) which I don't need to deal with right
  now.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I29ed4b51d50ae2507f5580db20452ec6c188ef66
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7916
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10816
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add bt2_common::makeUnique()
Philippe Proulx [Wed, 2 Mar 2022 18:47:25 +0000 (13:47 -0500)] 
src/cpp-common: add bt2_common::makeUnique()

This is our equivalent of std::make_unique() (introduced in C++14) for
C++11.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic58341f7419ac447f83401358ca0884151246dc8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7465
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10815
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add bt2_common::{little,big}ToNative()
Philippe Proulx [Fri, 22 Apr 2022 12:09:21 +0000 (08:09 -0400)] 
src/cpp-common: add bt2_common::{little,big}ToNative()

Those are C++ versions (using overloads) of the {le,be}{16,32,64}toh()
functions found in `src/compat/endian.h`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iab826bb633388d5ce506b4462b7a0417c2c05ad4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7927
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10814
Tested-by: jenkins <jenkins@lttng.org>
7 months agouuid-view.hpp: add missing #include's
Francis Deslauriers [Wed, 23 Feb 2022 15:42:49 +0000 (10:42 -0500)] 
uuid-view.hpp: add missing #include's

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I6299ef75acd765fde29f86046df877720ff8f54d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7376
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10813
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common/Makefile.am: add missing `uuid-view.hpp`
Simon Marchi [Wed, 27 Jul 2022 13:21:11 +0000 (09:21 -0400)] 
src/cpp-common/Makefile.am: add missing `uuid-view.hpp`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Idca1204fc2e53cf42633a3dd977f6883a6d55348
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7407
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10812
Tested-by: jenkins <jenkins@lttng.org>
7 months agologging: remove check for BT_LOG_OUTPUT_LEVEL
Simon Marchi [Wed, 3 Aug 2022 14:42:01 +0000 (10:42 -0400)] 
logging: remove check for BT_LOG_OUTPUT_LEVEL

This helps the case of TUs including headers that do logging, but don't
do logging themselves.

Change-Id: Ia1b51b4d30f120c68f96bcbd2db90adfc8ee98c9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10811
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add BT_APPEND_CAUSE*() and BT_CLOG_*() macros
Simon Marchi [Wed, 27 Jul 2022 13:20:50 +0000 (09:20 -0400)] 
src/cpp-common: add BT_APPEND_CAUSE*() and BT_CLOG_*() macros

This patch adds the following files:

`src/cpp-common/cfg-logging.hpp`:
    Offers the following macros:

    BT_CLOG*_EX():
        Logs using a given logging configuration reference.

    BT_CLOG*_STR_EX():
        Logs a literal string using a given logging configuration
        reference.

    BT_CLOG*_ERRNO_EX():
        Logs an errno message using a given logging configuration
        reference.

    BT_CLOG*_MEM_EX():
        Logs memory bytes using a given logging configuration reference.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

    Those macros decide, depending on what's available within the
    provided logging configuration object, how to prefix the complete
    log message.

`src/cpp-common/cfg-error-reporting.hpp`:
    Offers the following macros:

    BT_APPEND_CAUSE_EX():
    BT_APPEND_CAUSE_STR_EX():
    BT_APPEND_CAUSE_ERRNO_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

    Those macros decide, depending on what's available within the
    provided logging configuration object, which
    BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use.

`src/cpp-common/cfg-error-reporting-throw.hpp`:
    Offers the following macros:

    BT_APPEND_CAUSE_AND_THROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and throws an exception.

    BT_APPEND_CAUSE_AND_RETHROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and rethrows.

    BT_STR_APPEND_CAUSE_AND_THROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and throws an exception.

    BT_STR_APPEND_CAUSE_AND_RETHROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and rethrows.

    BT_ERRNO_APPEND_CAUSE_AND_THROW_EX():
        Appends a cause with an errno message to the error of the
        current thread using a given logging configuration reference,
        and throws an exception.

    BT_ERRNO_APPEND_CAUSE_AND_RETHROW_EX():
        Appends a cause with an errno message to the error of the
        current thread using a given logging configuration reference,
        and rethrows.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

`src/cpp-common/cfg-logging-error-reporting.hpp`:
    Offers the following macros:

    BT_CLOGE_APPEND_CAUSE_EX():
        Logs using a given logging configuration reference and appends
        a cause to the error of the current thread.

    BT_CLOGE_STR_APPEND_CAUSE_EX():
        Logs a literal string using a given logging configuration
        reference and appends a cause to the error of the current
        thread.

    BT_CLOGE_ERRNO_APPEND_CAUSE_EX():
        Logs an errno message using a given logging configuration
        reference and appends a cause to the error of the current
        thread.

    BT_CLOGE_MEM_APPEND_CAUSE_EX():
        Logs memory bytes using a given logging configuration reference
        and appends a cause to the error of the current thread.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

    Those macros decide, depending on what's available within the
    provided logging configuration object, which
    BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use.

`src/cpp-common/cfg-logging-error-reporting-throw.hpp`:
    Offers the following macros:

    BT_CLOGE_APPEND_CAUSE_AND_THROW_EX():
        Logs using a given logging configuration reference, appends a
        cause to the error of the current thread, and throws an
        exception.

    BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX():
        Logs using a given logging configuration reference, appends a
        cause to the error of the current thread, and rethrows.

    BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX():
        Logs a literal string using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and throws an exception.

    BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX():
        Logs a literal string using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and rethrows.

    BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX():
        Logs an errno message using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and throws an exception.

    BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX():
        Logs an errno message using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and rethrows.

    BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX():
        Logs memory bytes using a given logging configuration reference,
        appends a cause to the error of the current thread, and throws
        an exception.

    BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX():
        Logs memory bytes using a given logging configuration reference,
        appends a cause to the error of the current thread, and
        rethrows.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

The intended usage is as such:

1. In a header file defining a class, have a logging configuration
   member:

       bt2_common::LogCfg _mLogCfg;

   Make the constructor of the class accept a logging configuration
   reference and copy it to `_mLogCfg`.

2. In the source file which implements the methods of the class, at
   the top of the file, write:

       #define BT_LOG_TAG   "MY/TAG"
       #define BT_CLOG_CFG  _mLogCfg
       #include "cpp-common/cfg-logging-error-reporting-throw.hpp"

3. In any method of the class, when there's an error, call:

       BT_CLOGE_APPEND_CAUSE_AND_THROW(bt2_common::Error,
                                       "Cannot do this and that: code=%d",
                                       code);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3e689fe612b90be2f8f69288bc7947c727434d5a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10810
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: Add common exceptions
Francis Deslauriers [Tue, 19 Apr 2022 20:49:47 +0000 (16:49 -0400)] 
cpp-common: Add common exceptions

Add `bt2_common::{End, Error, MemoryError, TryAgain}` exception classes
to use in in-tree components and elsewhere. Each exception inherits a
C++ standard exception that I believe matches more closely in meaning.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I7335465f2377e032ae9706108708e35d78d38e6e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7918
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10809
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agosrc/cpp-common: add `LogCfg` class
Francis Deslauriers [Fri, 22 Apr 2022 20:47:55 +0000 (16:47 -0400)] 
src/cpp-common: add `LogCfg` class

`LogCfg` is a class to carry around the logging information used by
`BT_LOG*()` macros in the in-tree plugins.

Philippe added:

* Class comment.

* Setting other members when possible (for example, `_mSelfComp` when
  using the self message iterator constructor).

* Use references instead of pointers in constructors because they can't
  be `nullptr`, making it possible to remove some assertions.

* Component class member (because the libbabeltrace2 API has nothing
  to get a self component class from a self component) and
  compClsName() method.

  compClsName() is always available when using the self message
  iterator, component, or component class constructor.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic6980a2bcf74f8b270b0a108efc79f25f0e65d8d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7936
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10808
Tested-by: jenkins <jenkins@lttng.org>
7 months agolib: adjust son dev/non-dev precondition assertions in field-class.c
Simon Marchi [Thu, 17 Feb 2022 04:10:29 +0000 (23:10 -0500)] 
lib: adjust son dev/non-dev precondition assertions in field-class.c

I found some functions using BT_ASSERT_PRE_DEV_FC_NON_NULL followed by
either BT_ASSERT_PRE_FC_HAS_TYPE or BT_ASSERT_PRE_FC_IS_STRUCT (i.e. a
dev followed by a non-dev).  This seems illogical to me.  Either the
function is considered "fast path" and we use the dev versions, either
it's not "fast path" and we use the non-dev versions.

Change a few assertions to be dev.  If some of these functions aren't
actually considered fast path, then I think we should switch the
BT_ASSERT_PRE_DEV_FC_NON_NULLs to be non-dev.

Change-Id: I4f0c1cb0ef1006beddcc688d4e71f37fdb561e15
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7326
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10807
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agotests: only preload libasan for gcc compilers
Simon Marchi [Fri, 26 Aug 2022 17:50:53 +0000 (13:50 -0400)] 
tests: only preload libasan for gcc compilers

Clang appears to not use an external library for ASan, so we should not
try to preload it when building with clang.

Change-Id: I5cd88007fefcd7b8ad7caaee9155d3d9ea7f463e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10806
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/uuid-view: use string::operator[] instead of string::data to access intern...
Simon Marchi [Thu, 30 Mar 2023 16:11:19 +0000 (12:11 -0400)] 
cpp-common/uuid-view: use string::operator[] instead of string::data to access internal buffer

Using UuidView::string fails with:

      CXX      ctf-ir.lo
    In file included from /home/smarchi/src/babeltrace/src/cpp-common/bt2/clock-class.hpp:20,
                     from /home/smarchi/src/babeltrace/src/cpp-common/bt2/trace-ir.hpp:19,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.hpp:18,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.cpp:8:
    /home/smarchi/src/babeltrace/src/cpp-common/uuid-view.hpp: In member function 'std::string bt2_common::UuidView::str() const':
    /home/smarchi/src/babeltrace/src/cpp-common/uuid-view.hpp:57:38: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
       57 |         bt_uuid_to_str(_mUuid, s.data());
          |                                ~~~~~~^~
          |                                      |
          |                                      const char*
    In file included from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.hpp:15:
    /home/smarchi/src/babeltrace/src/common/uuid.h:40:62: note:   initializing argument 2 of 'void bt_uuid_to_str(const uint8_t*, char*)'
       40 | BT_HIDDEN void bt_uuid_to_str(const bt_uuid_t uuid_in, char *str_out);
          |                                                        ~~~~~~^~~~~~~

This is because the data method only has a const version in C++11:

  https://en.cppreference.com/w/cpp/string/basic_string/data

It therefore can't be used to modify the content of the string.  Use
operator[] instead.

Change-Id: I3bd9c9756c4e79856a5f0f0c7d8fa14e19c1eadd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10805
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agofield-class.hpp: add missing support for user attributes
Philippe Proulx [Fri, 20 May 2022 13:11:40 +0000 (09:11 -0400)] 
field-class.hpp: add missing support for user attributes

This patch adds the missing
bt2::CommonStructureFieldClassMember::userAttributes() and
bt2::CommonVariantFieldClassOption::userAttributes() methods to set and
borrow user attributes of structure field member classes and variant
field class options.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I023e835531753eb928ea5db41b5f429750139af7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8100
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10804
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd bt2::Common{Field,FieldClass,Value,Message}<>::as<>()
Philippe Proulx [Fri, 20 May 2022 01:50:36 +0000 (21:50 -0400)] 
Add bt2::Common{Field,FieldClass,Value,Message}<>::as<>()

Those new as() method templates conceptually cast their object to the
first template parameter. Those are shorthands to use specific types
within a template function, for example:

    template <typename FieldT, typename ValT>
    void g(bt2::Field field, const ValT val)
    {
        // ...
        field.as<FieldT>() = val;
        // ...
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ifc1f49487ac6ef9c143bf4c2faa3373f4eaccd9e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8099
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10803
Tested-by: jenkins <jenkins@lttng.org>
7 months agobt2::internal::BorrowedObj: add static assertions for generic copy ops.
Philippe Proulx [Thu, 19 May 2022 16:22:29 +0000 (12:22 -0400)] 
bt2::internal::BorrowedObj: add static assertions for generic copy ops.

This patch adds static assertions to `borrowed-obj.hpp` so as to make
compiler errors more readable when assigning a const wrapper to a
non-const wrapper, for example:

    bt2::Value v = bt2::ConstMapValue {somePtr};

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib23d91c6660a478e0ad663abbd141b0a90eaa92d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8091
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10802
Tested-by: jenkins <jenkins@lttng.org>
7 months agobt2::internal::BorrowedObj: use default copy operations explicitly
Philippe Proulx [Thu, 19 May 2022 16:11:40 +0000 (12:11 -0400)] 
bt2::internal::BorrowedObj: use default copy operations explicitly

What was called the generic copy constructor and assignment operator
are in fact constructor templates, not true copy operations.

This is because C++ requires that a copy constructor/assignment operator
be a "non-template non-static member function".

This patch is not a fix because the generated default copy operations
were fine (just copy the underlying libbabeltrace2 pointer). Just use
the default ones explicitly and fix the comments so that we know what's
going on.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4b4f19416a78ca05eaf3fa92f85f9637b2be2c0a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8090
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10801
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common/bt2/internal/*-obj.hpp: template param. names not needed
Philippe Proulx [Thu, 19 May 2022 16:06:59 +0000 (12:06 -0400)] 
src/cpp-common/bt2/internal/*-obj.hpp: template param. names not needed

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I40d093d773fc07f6972e7b86262c01dac4540575
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8088
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10800
Tested-by: jenkins <jenkins@lttng.org>
7 months agofield-class.hpp: support optional variant FC option name
Philippe Proulx [Tue, 17 May 2022 18:09:05 +0000 (14:09 -0400)] 
field-class.hpp: support optional variant FC option name

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4b2df4343a0f773b82e472b1138536440279e940
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8056
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10799
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: bt2::internal::SharedObj: add real copy/move ctor./operator=()
Philippe Proulx [Sat, 14 May 2022 16:28:52 +0000 (12:28 -0400)] 
Fix: bt2::internal::SharedObj: add real copy/move ctor./operator=()

Observed issue
==============
Given the type S, some `bt2::internal::SharedObj` class template
instantiation:

* Constructing an S object A from another S object doesn't increment the
  internal reference count of the libbabeltrace2 object which A wraps.

* Assigning an S object A from an S object B:

  * Doesn't increment the internal reference count of the libbabeltrace2
    object which B wraps.

  * Doesn't decrement the internal reference count of the libbabeltrace2
    object which A wraps.

* Constructing an S object from another moved S object B doesn't
  reset B.

* Assigning an S object A from a moved S object B:

  * Doesn't reset B.

  * Doesn't decrement the internal reference count of the libbabeltrace2
    object which A wraps.

Cause
=====
What I thought were copy/move constructor and assignment operators in
`bt2::internal::SharedObj` are in fact simple constructor and assignment
operator templates. In other words, they don't qualify as copy/move
constructor and assignment operators, so the compiler uses default ones.

From [1]:

> A copy constructor of class `T` is a non-template constructor whose
> first parameter is `T&‍`, `const T&‍`, `volatile T&‍`, or `const
> volatile T&‍`, and either there are no other parameters, or the rest
> of the parameters all have default values.

The same condition (non-template) holds for a move constructor, a copy
assignment operator, and a move assignment operator.

Solution
========
Add copy/move constructors and assignment operators to
`bt2::internal::SharedObj`.

Although you may call an operator=() method template like this:

    this->operator=<ObjT, LibObjT>(other)

you can't specify the template parameters when you call a constructor
template: the types of all its parameters need to be deduced.

This is why, to avoid redundant code, I added two common "copy" and
"move" (not real copy/move constructors) private constructor templates
to which the true copy/move constructors and the generic "copy"/"move"
constructors delegate. Those common ones accept a second, unused `int`
parameter to differentiate them from the public, generic "copy"/"move"
constructors.

Known drawbacks
===============
None.

References
==========
[1]: https://en.cppreference.com/w/cpp/language/copy_constructor

Change-Id: I6d8cb7c16da0a79296a482f8d130ab40468cc1a5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8041
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10798
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoAdd bt2::internal::SharedObj::create{With,Without}Ref() methods
Philippe Proulx [Fri, 13 May 2022 17:29:36 +0000 (13:29 -0400)] 
Add bt2::internal::SharedObj::create{With,Without}Ref() methods

It seems like there were some confusion regarding the reference
acquisition of the `bt2::internal::SharedObj` constructor vs. its
createWithInitialRef() static method.

Make it clear with a private constructor and two public static methods:

* createWithoutRef() creates a shared object without getting a
  reference.

* createWithRef() creates a shared object, immediately getting a new
  reference.

Both methods have two versions: one which accepts a wrapper and one
which accepts a raw libbabeltrace2 pointer.

Update all the `src/cpp-common/bt2` code to use those methods.

The pattern for a non-static shared() method is:

    Shared shared() const noexcept
    {
        return Shared::createWithRef(*this);
    }

This means if you have a borrowed wrapper `obj`, then `obj.shared()`
returns a shared object, incrementing the reference count.

The pattern for a creation method is:

    return Shared::createWithoutRef(libObjPtr);

where `libObjPtr` is a raw libbabeltrace2 pointer to an object of which
the reference count is one.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ifeef4af74a0078c1b7e9e5dfec8ebd5be381da8f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8039
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10797
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: bt2::CommonStreamClass: use correct memory error status
Philippe Proulx [Thu, 12 May 2022 17:23:48 +0000 (13:23 -0400)] 
Fix: bt2::CommonStreamClass: use correct memory error status

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I325d41eeaa4f81df5ad6177fc935bffe49416b34
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8025
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10796
Tested-by: jenkins <jenkins@lttng.org>
7 months agointeger-range-set.hpp: add `begin()` and `end()` to bt2::CommonIntegerRangeSet
Francis Deslauriers [Fri, 11 Mar 2022 17:30:06 +0000 (12:30 -0500)] 
integer-range-set.hpp: add `begin()` and `end()` to bt2::CommonIntegerRangeSet

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I85d92d27f90f25b2f86780180b248bde3c394b20
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7568
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10795
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add `begin()` and `end()` to VariantWithIntegerSelector FC
Francis Deslauriers [Thu, 17 Mar 2022 01:12:49 +0000 (21:12 -0400)] 
cpp-common: add `begin()` and `end()` to VariantWithIntegerSelector FC

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ice31d346102258a6af593bd38fc3f123179482f4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7619
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10794
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add `begin()` and `end()` to bt2::CommonEnumerationFieldClass
Francis Deslauriers [Wed, 16 Mar 2022 19:24:03 +0000 (15:24 -0400)] 
cpp-common: add `begin()` and `end()` to  bt2::CommonEnumerationFieldClass

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Id8b001611288121dd1adc1c3ae5bb698722b5bca
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7618
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10793
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add `begin()` and `end()` to bt2::ConstFieldPath
Francis Deslauriers [Wed, 9 Mar 2022 22:42:44 +0000 (17:42 -0500)] 
cpp-common: add `begin()` and `end()` to bt2::ConstFieldPath

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ie442f80bf1d5b055f6707ff516a8094417ff6c1d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7553
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10792
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agosrc/cpp-common/bt2: add `bt2::AddConst` and `bt2::RemoveConst`
Philippe Proulx [Mon, 9 May 2022 20:08:23 +0000 (16:08 -0400)] 
src/cpp-common/bt2: add `bt2::AddConst` and `bt2::RemoveConst`

This patch adds the `bt2::AddConst` and `bt2::RemoveConst` structure
templates in `src/cpp-common/bt2/type-traits.hpp` which both provide the
`Type` type alias to transform a const object type into a non-const
object type and vice versa.

For example, `bt2::AddConst<bt2::ClockClass>::Type` is
`bt2::ConstClockClass` and `bt2::RemoveConst<bt2::ConstMapValue>::Type`
is `bt2::MapValue`.

I needed this to call something like

    bt2::RemoveConst<typename LibFcT::Mapping::RangeSet>::Type::create()

where `LibFcT` is some non-const enumeration field class, but I decided
to implement it for all the types right now.

Internally, we add something like this for all type pairs:

    namespace internal {

    struct XyzTypeDescr
    {
        using Const = ConstXyz;
        using NonConst = Xyz;
    };

    template <>
    struct TypeDescr<Xyz> : public XyzTypeDescr
    {
    };

    template <>
    struct TypeDescr<ConstXyz> : public XyzTypeDescr
    {
    };

    } /* namespace internal */

The type trait structure templates in `type-traits.hpp` just use
`internal::TypeDescr`, for example:

    template <typename ObjT>
    struct RemoveConst
    {
        using Type = typename internal::TypeDescr<ObjT>::NonConst;
    };

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia4d44a286fd836dcdb2a0f37c5a08a43bad5508e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8008
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10791
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd bt2::CommonEnumerationFieldClass::addMapping() methods
Philippe Proulx [Mon, 9 May 2022 19:34:33 +0000 (15:34 -0400)] 
Add bt2::CommonEnumerationFieldClass::addMapping() methods

They make it possible to add mappings to an enumeration field class.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9683e14e57f3b3167693d18ff16316fec12d7611
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8007
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10790
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: bt2::CommonIntegerFieldClass::fieldValueRange(): use correct func.
Philippe Proulx [Mon, 9 May 2022 19:33:39 +0000 (15:33 -0400)] 
Fix: bt2::CommonIntegerFieldClass::fieldValueRange(): use correct func.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I38f60c9888e04b367806d54db9d7dc6f9bbb6579
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8006
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10789
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: src/cpp-common/bt2/trace-ir.hpp: use correct variable name
Philippe Proulx [Mon, 9 May 2022 18:12:28 +0000 (14:12 -0400)] 
Fix: src/cpp-common/bt2/trace-ir.hpp: use correct variable name

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic6fec0fbe90b5528a37ef34e67c4789c61fb7ad6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8004
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10788
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: Expose BorrowedObj::libObjPtr() as public method
Francis Deslauriers [Tue, 26 Apr 2022 15:39:11 +0000 (11:39 -0400)] 
cpp-common: Expose BorrowedObj::libObjPtr() as public method

This will be useful for component class queries that may use bt2::Value
C++ wrappers but must return a `bt_value` at the moment.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Iea93caa6b47ce1afeb7977fee26dffdd3f97013e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7948
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10787
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: field-path.hpp: add missing `shared-obj.hpp` include
Francis Deslauriers [Wed, 16 Mar 2022 15:30:54 +0000 (11:30 -0400)] 
Fix: field-path.hpp: add missing `shared-obj.hpp` include

gcc 9.3 emits the following warning when including the `field-path.hpp`
file by itself:
  ../../../../src/cpp-common/bt2/field-path.hpp:180:5: error: return type ‘using Shared = class bt2::internal::SharedObj<bt2::ConstFieldPath, const bt_field_path, bt2::internal::FieldPathRefFuncs>’ {aka ‘class bt2::internal::SharedObj<bt2::ConstFieldPath, const bt_field_path, bt2::internal::FieldPathRefFuncs>’} is incomplete
    180 |     {
        |     ^
  ../../../../src/cpp-common/bt2/field-path.hpp: In member function ‘void bt2::ConstFieldPath::shared() const’:
  ../../../../src/cpp-common/bt2/field-path.hpp:181:29: error: too many initializers for ‘bt2::ConstFieldPath::Shared’ {aka ‘bt2::internal::SharedObj<bt2::ConstFieldPath, const bt_field_path, bt2::internal::FieldPathRefFuncs>’}
    181 |         return Shared {*this};
        |                             ^

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: If18d48f16eb6ecb5b14e12a9c8314392c3f3698e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7604
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10786
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: cpp-common: add missing argument to bt_field_class_variant_create call
Simon Marchi [Thu, 17 Mar 2022 19:10:09 +0000 (15:10 -0400)] 
Fix: cpp-common: add missing argument to bt_field_class_variant_create call

Change-Id: I582fb40180e2d34b5890e13ae517566945ec3a15
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7641
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10765
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: cpp-common: remove unexpected parameter to createStructureFieldClass
Simon Marchi [Thu, 17 Mar 2022 18:54:03 +0000 (14:54 -0400)] 
Fix: cpp-common: remove unexpected parameter to createStructureFieldClass

Change-Id: Ib9e050b109df596f7c7198a80fed6c1cd9c20cea
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7640
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10764
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agoCleanup: cpp-common: typo: clkSnapshot -> fieldPath
Francis Deslauriers [Thu, 17 Mar 2022 02:09:34 +0000 (22:09 -0400)] 
Cleanup: cpp-common: typo: clkSnapshot -> fieldPath

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idf62a2a8d1eb52799c71dee37f08e44af277b15a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7621
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10763
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agofield-class.hpp: remove redundant template parameters
Francis Deslauriers [Tue, 8 Mar 2022 21:41:24 +0000 (16:41 -0500)] 
field-class.hpp: remove redundant template parameters

C++ Standard excerpt:
  14.6.1 Locally declared names [temp.local]
  Like normal (non-template) classes, class templates have an
  injected-class-name (Clause 9). The injected-class-name can be used
  with or without a template-argument-list. When it is used without a
  template-argument-list, it is equivalent to the injected-class-name
  followed by the template-parameters of the class template enclosed in
  <>. When it is used with a template-argument-list, it refers to the
  specified class template specialization, which could be the current
  specialization or another specialization.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I1c0c104431f7cf57806a66ed1bce964c007f2c47
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7527
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10762
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agofield-class.hpp: Add CommonVariantWithSelectorFieldClass
Francis Deslauriers [Mon, 7 Mar 2022 22:17:46 +0000 (17:17 -0500)] 
field-class.hpp: Add CommonVariantWithSelectorFieldClass

This is useful to call the `selectorFieldPath()` method without knowing
if the variant field class has a signed or unsigned selector.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ib54bfa31d8f818430ec378c7c0e0c9258e20e450
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7511
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10761
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agofield-class.hpp: Add CommonBaseEnumerationFieldClass
Francis Deslauriers [Mon, 7 Mar 2022 21:54:34 +0000 (16:54 -0500)] 
field-class.hpp: Add CommonBaseEnumerationFieldClass

This is useful to call the `size()` method without knowing if the
enumeration field class is of the signed or unsigned type.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I952fc54c015f8548489aab74e85cded23f9841f7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7510
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10760
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

7 months agocpp-common: add `begin()` and `end()` to Variant and Struct FC
Francis Deslauriers [Thu, 10 Feb 2022 22:06:27 +0000 (17:06 -0500)] 
cpp-common: add `begin()` and `end()` to Variant and Struct FC

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ic78e9a06ec86b3a1749c1763698408964f34ec27
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7323
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7290
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: template ArrayValueIterator for reuse with other containers
Francis Deslauriers [Tue, 8 Mar 2022 17:16:27 +0000 (12:16 -0500)] 
cpp-common: template ArrayValueIterator for reuse with other containers

This pattern will be reused for Structure and Variant field class.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I8b6521e41dcc2ebdb81b6348de916544176dbf20
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7518
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10759
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: field-class.cpp: calling _option_fc lib function on VariantFieldClass
Francis Deslauriers [Fri, 4 Mar 2022 19:52:08 +0000 (14:52 -0500)] 
Fix: field-class.cpp: calling _option_fc lib function on VariantFieldClass

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ie3bbc05a20368b8b1388b484ef02da4fb4b68a2d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7497
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10758
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agofield-class.hpp: add missing #include
Francis Deslauriers [Fri, 4 Mar 2022 15:08:18 +0000 (10:08 -0500)] 
field-class.hpp: add missing #include

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I5dedb44d393fe318253f5912c032ad313fd1c455
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7495
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10757
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: Add `CommonFieldClass::isReal()` method
Francis Deslauriers [Thu, 24 Feb 2022 19:37:29 +0000 (14:37 -0500)] 
cpp-common: Add `CommonFieldClass::isReal()` method

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I420462ccfd78c06d7b496f4650af77cd2d2e57b7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7385
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10756
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: Add hash() and isSame() methods to BorrowedObj
Francis Deslauriers [Tue, 22 Feb 2022 20:43:46 +0000 (15:43 -0500)] 
cpp-common: Add hash() and isSame() methods to BorrowedObj

This will allow us to use the C++ wrapper objects in
`std::unordered_map` by using these methods in custom hasher and isEqual
objects.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I4e018ece9ea4ca755f6612cd9adec408667b202d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7356
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10755
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: use C-style comments in C++ files
Philippe Proulx [Tue, 1 Mar 2022 16:25:05 +0000 (11:25 -0500)] 
src/cpp-common: use C-style comments in C++ files

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I63b73d110e59f39afc59e83fcf7b59e61db78dbc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7434
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10754
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd `bt2::CommonArrayValueIterator` to iterate on `bt2::CommonArrayValue` container
Francis Deslauriers [Tue, 1 Feb 2022 14:05:18 +0000 (09:05 -0500)] 
Add `bt2::CommonArrayValueIterator` to iterate on `bt2::CommonArrayValue` container

This commit implements an array value input iterator and adds `begin()` and
`end()` methods to the `CommonArrayValue` container class.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I2e3c502bd5b11a507fc4643cee27b48b06a6c4a8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7322
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7193
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoctf: fix -Wformat-overflow warning in ctf-meta-resolve.cpp
Simon Marchi [Mon, 11 Sep 2023 13:48:14 +0000 (09:48 -0400)] 
ctf: fix -Wformat-overflow warning in ctf-meta-resolve.cpp

Compiling with gcc 13.2.1 (Arch's gcc version as of today) and -O2, I
get:

    libtool: compile:  ccache g++ -std=c++11 -DHAVE_CONFIG_H -I/home/smarchi/src/babeltrace/include -I../../../../../src -I/home/smarchi/src/babeltrace/src -include common/config.h -I. -I/home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata -fvisibility=hidden -fvisibility-inlines-hidden -pthread -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -pthread -Wall -Wextra -Wmissing-prototypes -Wmissing-declarations -Wnull-dereference -Wundef -Wredundant-decls -Wshadow -Wjump-misses-init -Wsuggest-attribute=format -Wnested-externs -Wwrite-strings -Wformat=2 -Wstrict-aliasing -Wmissing-noreturn -Winit-self -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wsuggest-override -Wno-unused-parameter -Wno-sign-compare -Wno-cast-function-type -Wno-missing-field-initializers -Wno-maybe-uninitialized -Werror -g3 -O2 -fmax-errors=1 -fdiagnostics-color=always -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28 -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28 -D_GLIBCXX_DEBUG=1 -MT ctf-meta-resolve.lo -MD -MP -MF .deps/ctf-meta-resolve.Tpo -c /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp  -fPIC -DPIC -o .libs/ctf-meta-resolve.o
    In file included from /home/smarchi/src/babeltrace/src/logging/comp-logging.h:16,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp:12:
    /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp: In function 'int64_t get_field_paths_lca_index(ctf_field_path*, ctf_field_path*, resolve_context*)':
    /home/smarchi/src/babeltrace/src/logging/comp-logging.h:18:41: error: '%s' directive argument is null [-Werror=format-overflow=]
       18 | #define _BT_COMP_LOG_COMP_PREFIX        "[%s] "
    /home/smarchi/src/babeltrace/src/logging/log.h:807:67: note: in definition of macro 'BT_LOG_WRITE'
      807 |                                                         lvl, tag, __VA_ARGS__); \
          |                                                                   ^~~~~~~~~~~
    /home/smarchi/src/babeltrace/src/logging/comp-logging.h:23:42: note: in expansion of macro '_BT_COMP_LOG_COMP_PREFIX'
       23 |         BT_LOG_WRITE((_lvl), BT_LOG_TAG, _BT_COMP_LOG_COMP_PREFIX _fmt, \
          |                                          ^~~~~~~~~~~~~~~~~~~~~~~~
    /home/smarchi/src/babeltrace/src/logging/comp-logging.h:83:9: note: in expansion of macro 'BT_COMP_LOG'
       83 |         BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
          |         ^~~~~~~~~~~
    /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp:734:9: note: in expansion of macro 'BT_COMP_LOGD'
      734 |         BT_COMP_LOGD("Finding lowest common ancestor (LCA) between two field paths: "
          |         ^~~~~~~~~~~~

It is undefined what happens when %s receives NULL.  Use the literal
string "(null)" instead of NULL.

Change-Id: I4f53165ff9fc08fb373f7c1cdf87a63f2b792532
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10856
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
8 months agodoc/man: make default values of boolean init. params. clearer
Philippe Proulx [Fri, 1 Sep 2023 18:17:28 +0000 (14:17 -0400)] 
doc/man: make default values of boolean init. params. clearer

This patch answers to <https://bugs.lttng.org/issues/1387>, removing the
"=`yes`" and "=`no`" in the component class manual pages to replace them
with "='VAL'" and indicate the behaviour depending on "'VAL'", as well
as the default value.

Fixes: https://bugs.lttng.org/issues/1387
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie7439fa397e2a9a5818152a68073f7bf87385675
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10709

8 months agobuild: gen-version-i.sh: make it an error if git describe fails
Simon Marchi [Fri, 26 May 2023 16:17:19 +0000 (12:17 -0400)] 
build: gen-version-i.sh: make it an error if git describe fails

When doing `make` as a regular user, building from the git repo, the
src/common/version.i file may contain:

    #define BT_VERSION_GIT "v1.2.0-3717-ga7074326ba9a"

Then, doing `make` as root, when logged in with `su -`, generates a new
version.i with an empty version string:

    #define BT_VERSION_GIT ""

This is because the `git describe --tags --dirty --abbrev=12` command
fails with:

    make[1]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      GEN      version.i
    fatal: detected dubious ownership in repository at '/home/smarchi/src/babeltrace'
    To add an exception for this directory, call:

            git config --global --add safe.directory /home/smarchi/src/babeltrace

By default, git refuses to work on a git repository owned by a different
user.  Note that running a command under sudo doesn't hit this problem,
because git honors the SUDO_UID & co variables.

I think that the current state is buggy, because it results in the
installed library having an empty version string, and it happens almost
silently.  I suggest making it an error if that `git describe` command
fails, since the script can't work correctly in those conditions.  The
user would then need to adjust their setup: either add the directory to
git's safe.directory variable (as the git command suggested) or run the
command under sudo.

Doing "make install" as root not under sudo is one use case, but another
one would be to do the complete build as a regular user from a source
git repository that is owned by another reguar user.  In that case, the
script wouldn't be able to generate a version string in the first
place.  I think that the right thing to do is to error out.  And in that
case, the only solution I see if or the user to use the git
safe.directory variable.

Note that the second git describe command is expected to fail in normal
situations, when it doesn't find an exact tag match, so the `|| true`
there is fine.

Change-Id: I879ddc2184223266829afceca252fe971795f395
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Fixes: https://bugs.lttng.org/issues/1376
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10104
Tested-by: jenkins <jenkins@lttng.org>
8 months agobuild: gen-version-i.sh: use a fixed abbrev length
Simon Marchi [Fri, 26 May 2023 16:17:01 +0000 (12:17 -0400)] 
build: gen-version-i.sh: use a fixed abbrev length

When doing:

 - make
 - sudo make install

... it is possible for the `sudo make install` command to generate a new
src/common/version.i file, if the regular user has a custom value for
the `core.abbrev` git configuration variable.

The version.i file generated by `make` contains a version number with a
hash of a certain length.  Then `sudo make install` generates an
equivalent version number, but with a hash of a different length.  This
then causes some object files that depended on it to be rebuilt, which
is not expected for the install target.

To avoid this, add --abbrev=12 to the git describe command that
genenerates the version string, so that the same hash representation is
generated during both "make" and "sudo make install".

Change-Id: I979d6a9d627f133909dc026e0d2820b52f409d98
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Fixes: https://bugs.lttng.org/issues/1376
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10098
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 months agobuild: gen-version-i.sh: use errexit option
Simon Marchi [Tue, 20 Jun 2023 01:28:12 +0000 (21:28 -0400)] 
build: gen-version-i.sh: use errexit option

Use `set -o errexit` in gen-version-i.sh, so that any unexpected
command failures stops the script.

The first `git describe` command can unexpectedly fail when the script
is ran by a user other than the owner of the git repository (and sudo
wasn't used, so SUDO_UID & co are not set):

    # git describe --tags --dirty
    fatal: detected dubious ownership in repository at '/home/smarchi/src/babeltrace'
    To add an exception for this directory, call:

            git config --global --add safe.directory /home/smarchi/src/babeltrace

For instance, this happens if the git repository is owned by a regular
user, and `make install` is ran in a root shell started with `su`.  Add
`|| true` to that command, to keep the existing behavior (even if
it's not ideal).

Change-Id: Idfbcb3a86158bcddff11a34a18a5d004def37742
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10103
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: gen-version-i.sh: use `mv -f`
Simon Marchi [Fri, 26 May 2023 12:50:55 +0000 (08:50 -0400)] 
build: gen-version-i.sh: use `mv -f`

When file src/common/version.i happens to be owned by root (there are
known bugs that causes version.i to be rebuilt when doing `make install`
as root), doing `make` as a regular user gives an interactive prompt:

    make[3]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      GEN      version.i
    mv: replace 'version.i', overriding mode 0644 (rw-r--r--)?

Pass -f to mv to avoid this.

Change-Id: I3ac19cff615fd52db1c025b08c046d34814fb50a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10102
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: gen-version-i.sh: use `command` to check if git exists
Simon Marchi [Fri, 26 May 2023 16:14:04 +0000 (12:14 -0400)] 
build: gen-version-i.sh: use `command` to check if git exists

Use the shell builtin `command` to check if git is a valid command,
instead of `which`.

Change-Id: I2e3b4cc178383be1e34dfddbff0794e6fc7ddf86
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10105
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: gen-version-i.sh: make shellcheck-clean
Simon Marchi [Fri, 26 May 2023 12:35:37 +0000 (08:35 -0400)] 
build: gen-version-i.sh: make shellcheck-clean

Fix all the warnings below.

    In src/common/gen-version-i.sh line 27:
    if (test ! -f version.i && test -f "$TOP_SRCDIR/include/version.i"); then
       ^-- SC2233 (style): Remove superfluous (..) around condition to avoid subshell overhead.

    In src/common/gen-version-i.sh line 39:
    if (test -r "$TOP_SRCDIR/bootstrap" && test -r "$TOP_SRCDIR/.git") &&
       ^-- SC2235 (style): Use { ..; } instead of (..) to avoid subshell overhead.

    In src/common/gen-version-i.sh line 40:
     test -x "`which git 2>&1;true`"; then
                             ^-------------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
     test -x "$(which git 2>&1;true)"; then

    In src/common/gen-version-i.sh line 41:
     GIT_VERSION_STR="`cd "$TOP_SRCDIR" && git describe --tags --dirty`"
                             ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
     GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && git describe --tags --dirty)"

    In src/common/gen-version-i.sh line 42:
     GIT_CURRENT_TAG="`cd "$TOP_SRCDIR" && git describe --tags --exact-match --match="v[0-9]*" HEAD || true 2> /dev/null`"
                             ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
                                               ^-- SC2015 (info): Note that A && B || C is not if-then-else. C may run when A is true.

    Did you mean:
     GIT_CURRENT_TAG="$(cd "$TOP_SRCDIR" && git describe --tags --exact-match --match="v[0-9]*" HEAD || true 2> /dev/null)"

    In src/common/gen-version-i.sh line 64:
    echo "#define BT_VERSION_EXTRA_NAME \"`$SED -n '1p' "$TOP_SRCDIR/version/extra_version_name" 2> /dev/null`\"" >> version.i.tmp
    ^-- SC2129 (style): Consider using { cmd1; cmd2; } >> file instead of individual redirects.
                                          ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
    echo "#define BT_VERSION_EXTRA_NAME \"$($SED -n '1p' "$TOP_SRCDIR/version/extra_version_name" 2> /dev/null)\"" >> version.i.tmp

    In src/common/gen-version-i.sh line 70:
    echo "#define BT_VERSION_EXTRA_DESCRIPTION \"`$SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.,]/-/g ; s/\r{0,1}\n/\\\n/g' "$TOP_SRCDIR/version/extra_version_description" 2> /dev/null`\"" >> version.i.tmp
                                                 ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
    echo "#define BT_VERSION_EXTRA_DESCRIPTION \"$($SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.,]/-/g ; s/\r{0,1}\n/\\\n/g' "$TOP_SRCDIR/version/extra_version_description" 2> /dev/null)\"" >> version.i.tmp

    In src/common/gen-version-i.sh line 80:
    echo "#define BT_VERSION_EXTRA_PATCHES \"`ls -1 "$TOP_SRCDIR/version/extra_patches" | $GREP -v '^README.adoc' | $SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.]/-/g ; s/\r{0,1}\n/\\\n/g' 2> /dev/null`\"" >> version.i.tmp
                                             ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
                                              ^-- SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames.

    Did you mean:
    echo "#define BT_VERSION_EXTRA_PATCHES \"$(ls -1 "$TOP_SRCDIR/version/extra_patches" | $GREP -v '^README.adoc' | $SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.]/-/g ; s/\r{0,1}\n/\\\n/g' 2> /dev/null)\"" >> version.i.tmp

    In src/common/gen-version-i.sh line 87:
     test x"`cat version.i.tmp`" != x"`cat version.i`"; then
                           ^-----------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
                                                     ^-------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
     test x"$(cat version.i.tmp)" != x"$(cat version.i)"; then

    For more information:
      https://www.shellcheck.net/wiki/SC2012 -- Use find instead of ls to better ...
      https://www.shellcheck.net/wiki/SC2015 -- Note that A && B || C is not if-t...
      https://www.shellcheck.net/wiki/SC2006 -- Use $(...) notation instead of le...

Change-Id: I519fd427b248bc8f460aa1e5b592aed0ea6858c2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10096
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: move script to generate version.i to its own file
Simon Marchi [Thu, 25 May 2023 18:36:49 +0000 (14:36 -0400)] 
build: move script to generate version.i to its own file

Move the script from src/common/Makefile.am to its own file.  This will
make it easier to read, modify and lint.

I inlined the big comment from Makefile.am in the new script.  I tried
to keep the code as-is as much as possible, but I needed to tweak a few
things.

 - Replace $(FOO) with $FOO
 - The script expects to get the top srcdir and the grep and sed
   binaries through the TOP_SRCDIR, GREP and SED env var.  GREP and SED
   are optional, to make it easier to run the script by hand

Change-Id: Iaa8948018785e0de4250285110b78ccea1abaedb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10095
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agoBump minimum supported automake version to 1.13
Erica Bugden [Thu, 10 Aug 2023 20:32:12 +0000 (16:32 -0400)] 
Bump minimum supported automake version to 1.13

since 1.13.4 is the earliest version of automake that we currently build
with regularly in the CI. Build tests are not currently run with 1.12 so
it is risky to claim supporting it.

Change-Id: I353a60f39c9ac8e1d279745b3225d64e40eab4cc
Signed-off-by: Erica Bugden <ebugden@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10586
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agofix: make flake8 6.x happy
Michael Jeanson [Tue, 15 Aug 2023 20:43:03 +0000 (16:43 -0400)] 
fix: make flake8 6.x happy

./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:143:12: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:151:12: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:156:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:160:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:164:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:168:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./tests/data/auto-source-discovery/params-log-level/bt_plugin_test.py:33:20: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`

Change-Id: I388dfe9b1c8fa7030a805e6c6e0e487e56947616
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10612
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agofix: running black on python 3.11
Michael Jeanson [Tue, 15 Aug 2023 18:29:22 +0000 (14:29 -0400)] 
fix: running black on python 3.11

Black 22.0 is incompatible with click >= 8.1 [1], pin it to a working
version.

Traceback (most recent call last):
  File ".pyenv/bin/black", line 8, in <module>
    sys.exit(patched_main())
             ^^^^^^^^^^^^^^
  File ".pyenv/lib/python3.11/site-packages/black/__init__.py", line 6606, in patched_main
    patch_click()
  File ".pyenv/lib/python3.11/site-packages/black/__init__.py", line 6595, in patch_click
    from click import _unicodefun  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name '_unicodefun' from 'click' (.pyenv/lib/python3.11/site-packages/click/__init__.py)

[1] https://github.com/psf/black/issues/2964

Change-Id: I502f10e4cdedae4c431a243fc621fa10ab8bc5cf
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10604
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
8 months agobt_query_executor_create_with_method_data(): fix docs note
Philippe Proulx [Wed, 9 Aug 2023 08:01:01 +0000 (04:01 -0400)] 
bt_query_executor_create_with_method_data(): fix docs note

The bt_graph_add_*_component*() functions accept a `params` parameter,
not the bt_graph_add_*_component_*_port_added_listener() ones.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib2b8fa0177a8915d344ccaf3e55c05d3c939d2ca
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10559

10 months agobuild: correct alignment of "GEN version.i"
Simon Marchi [Thu, 25 May 2023 18:37:55 +0000 (14:37 -0400)] 
build: correct alignment of "GEN version.i"

Before:

    make[1]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      CC       assert.lo
      CC       common.lo
      CC       uuid.lo
      CCLD     libbabeltrace2-common.la
      GEN        version.i

After:

    make[1]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      CC       assert.lo
      CC       common.lo
      CC       uuid.lo
      CCLD     libbabeltrace2-common.la
      GEN      version.i

Change-Id: Ia4968e5209ef1afc83c287797f4d88756fe30b2f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10094
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
10 months ago.gitignore: add missing '/tests/lib/test_fields_bin'
Michael Jeanson [Thu, 15 Jun 2023 19:59:52 +0000 (15:59 -0400)] 
.gitignore: add missing '/tests/lib/test_fields_bin'

Change-Id: Ia77516852a3d4aeca443a7d42b7c2ea4922d0195
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10375
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
10 months agopython: make all _get_ref/_put_ref proper static methods
Simon Marchi [Thu, 8 Jun 2023 14:57:48 +0000 (10:57 -0400)] 
python: make all _get_ref/_put_ref proper static methods

The pyright static type checker doesn't like for these methods in
_SharedObject:

    @staticmethod
    def _get_ref(ptr):
        raise NotImplementedError

    @staticmethod
    def _put_ref(ptr):
        raise NotImplementedError

... to be overriden by assignment like this:

    _get_ref = staticmethod(native_bt.field_class_get_ref)
    _put_ref = staticmethod(native_bt.field_class_put_ref)

The warnings it gives are:

    /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py

      /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:48:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
        Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
          Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)

      /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:49:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
        Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
          Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)

So, it's just the parameter name that it doesn't like.  The obvious
solution would be to rename the `ptr` parameters of
_SharedObject._{get,put}_ref to `field_class`, in _SharedObject, to
match the names in native_bt.py.  However, I don't want us to be tied to
the names in native_bt.py (which originally come from the C header
files), as in Python we often want to use `ptr` in the name to
differentiate the SWIG wrapper around the pointer and the higher-level.
Another solution might be to use SWIG code to rename function parameters
in the SWIG-generated code, but I'm not so well-versed in SWIG, I
couldn't find how to do that.

So, I propose to just use the standard syntax for methods instead, the
type checker seems to be happy with that.

Change-Id: Ife5ad007aea4fb315d3ff4f8da67c48f4bf3e96d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10240
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
10 months agopython: mark _SharedObject._{get,put}_ref as abstract methods
Simon Marchi [Thu, 8 Jun 2023 15:21:31 +0000 (11:21 -0400)] 
python: mark _SharedObject._{get,put}_ref as abstract methods

_get_ref and _put_ref must be implemented by any sub-class of
_SharedObject, marking them as abstract methods could help find
mistakes.

Change-Id: I0e161a0bbc1c432d9ed59279d3e4b1b6f6a26215
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10239
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
This page took 0.064178 seconds and 4 git commands to generate.