Skip to content

[25748] Portability fixes for restricted standard libraries - #351

Open
emiliocuestaf wants to merge 6 commits into
masterfrom
feature/fastcdr-face-portability-fixes
Open

emiliocuestaf wants to merge 6 commits into
masterfrom
feature/fastcdr-face-portability-fixes

Conversation

@emiliocuestaf

@emiliocuestaf emiliocuestaf commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Every header now includes what it uses, and the C library names are written as C++ declares them: <cstdint>, <cstring>, <cstdlib>... and std::uint32_t, std::size_t, std::memcpy... Each form is only guaranteed by its own header, so code mixing them (<cstdint> with uint32_t) only builds with standard libraries that declare both, as GNU's does. <malloc.h>, which is not standard, is replaced by <cstdlib>.

The MEMCCPY macro of fixed_size_string.hpp, used by fixed_string, is kept, but now names eprosima::fastcdr::detail::memccpy, a standard C++ copy with the same result, instead of memccpy (_memccpy on Windows), which is POSIX and not standard C++. memory_helpers.hpp includes <atomic> only for MSVC, the only compiler whose clobber_memory() uses it.

No other behavior change: the rest is includes and names.

utils/face/check_face.py checks Fast CDR against the C++11 General Purpose capability set of the FACE Technical Standard, Edition 3.2. It compiles Fast CDR as the FACE Conformance Test Suite (CTS) compiles a Unit of Conformance: each public header alone and each source, with the compiler flags of the CTS toolchain and only the gold standard headers of the profile. Then the functions the objects use must be defined by the gold standard libraries (built from their CTS sources), the default allowed definitions of the CTS, or utils/face/allowed_symbols.txt (the C++ exception runtime, and _GLOBAL_OFFSET_TABLE_). It lists every issue where it is, with the files that run into it, and fails when there is any. Only the gold standard files are fetched from the CTS 3.2.3 archive, with HTTP range requests, and checked against their SHA-256; a local CTS can be given instead (--cts-dir).

The check runs in a face-check job of the Ubuntu CI of its own, apart from the build and test matrix: it only needs the configured sources, and runs the script directly, as it is run by hand. On this PR alone the job fails, because the profile excludes wide characters and strings: #352 adds the option to leave them out and configures the job with it.

Contributor Checklist

  • Commit messages follow the project guidelines.
  • The code follows the style guidelines of this project.
  • Tests that thoroughly check the new feature have been added/Regression tests checking the bug and its fix have been added; the added tests pass locally
  • Any new/modified methods have been properly documented using Doxygen.
  • Changes are backport compatible: they do NOT break ABI nor change library core behavior.
  • Changes are API compatible.
  • New feature has been added to the versions.md file (if applicable).
  • Applicable backports have been included in the description.

Reviewer Checklist

  • The PR has a milestone assigned.
  • The title and description correctly express the PR's purpose.
  • Check contributor checklist is correct.
  • Check CI results: changes do not issue any warning.
  • Check CI results: CI pass and failing tests are unrelated with the changes.

@richiware richiware left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also create a tool to check FACE rules here in Fast CDR and can be used as a test

Comment thread include/fastcdr/config.h.in Resolved
@emiliocuestaf
emiliocuestaf force-pushed the feature/fastcdr-face-portability-fixes branch from b0d57af to a826b74 Compare November 5, 2026 15:57
@emiliocuestaf
emiliocuestaf requested review from richiprosima and removed request for richiprosima November 5, 2026 15:58
Every header now includes what it uses, and the C library names are written as C++ declares them: <cstdint>,
<cstring>, <cstdlib>... and std::uint32_t, std::size_t, std::memcpy... Each form is only guaranteed by its own
header, so code mixing them (<cstdint> with uint32_t) only builds with standard libraries that declare both, as
GNU's does. <malloc.h>, which is not standard, is replaced by <cstdlib>.

The C headers in config.h are for the code generated by Fast DDS Gen, which uses the C names without std::.

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
fixed_string copies with a bounded loop and std::memcpy instead of memccpy (_memccpy on Windows), which is POSIX
and not standard C++, with the same result: the terminator is copied when it fits. The MEMCCPY macro is removed.

memory_helpers.hpp includes <atomic> only for MSVC, the only compiler whose clobber_memory() uses it, so that the
other compilers do not need the header.

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
MEMCCPY is defined by a public header, so code that includes Fast CDR may use it. It is kept, and now names
eprosima::fastcdr::detail::memccpy, a standard C++ copy with memccpy's semantics, instead of POSIX's memccpy
(_memccpy on Windows), which is not standard C++. fixed_string::set uses it again.

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
config.h included <stddef.h>, <stdint.h> and <string.h> for the code generated by Fast DDS Gen, which used size_t,
uint32_t and memcpy without std::. The generated code now includes what it uses and writes the std:: names
(eProsima/Fast-DDS-Gen-Pro#49), and config.h uses none of them, so they are removed.

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
utils/face/check_face.py compiles Fast CDR as the FACE Conformance Test Suite compiles a Unit of Conformance: each
public header alone and each source, with the compiler flags of the CTS toolchain and only the gold standard headers
of the profile. Then the functions the objects use must be defined by the gold standard libraries, built from their
CTS sources, the default allowed definitions of the CTS, or allowed_symbols.txt (the C++ exception runtime). It lists
every issue where it is, with the files that run into it, and fails when there is any.

Only the gold standard files are fetched from the CTS 3.2.3 archive, with HTTP range requests (10 MB), and checked
against their SHA-256. It runs in a job of the Ubuntu CI of its own, independent of the build and test matrix: it only
needs the configured sources (for config.h). The job runs utils/face/check_face.py directly, which is also how it runs
by hand.

It fails until wide strings can be left out (#352): the profile excludes them.

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
@emiliocuestaf
emiliocuestaf force-pushed the feature/fastcdr-face-portability-fixes branch from a826b74 to b67b75b Compare November 13, 2026 12:13
@emiliocuestaf
emiliocuestaf requested review from richiprosima and removed request for richiprosima November 13, 2026 12:14
Comment thread include/fastcdr/Cdr.h
#else
#include <stdlib.h>
#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
#include <cstdlib>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Could dropping <malloc.h> break code that relied on it through Cdr.h?

Before this change, Cdr.h included <malloc.h> everywhere except Apple, FreeBSD and VxWorks. Fast CDR itself doesn't use anything from it, but downstream code (Fast DDS, or types generated by Fast DDS-Gen) may be calling alloca, _alloca or malloc_usable_size without including <malloc.h> itself. <cstdlib> doesn't declare those, so that code would stop compiling. In a minor or patch release that's a source-compatibility break.

Can we grep Fast DDS and the Fast DDS-Gen templates for those names? If nothing turns up, a release-note entry is enough. Otherwise, keep the old include behind a guard that FACE builds turn off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants