Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

change include directives to use double quotes #2

Merged
merged 2 commits into from
May 25, 2021
Merged

change include directives to use double quotes #2

merged 2 commits into from
May 25, 2021

Conversation

LuanVSO
Copy link
Contributor

@LuanVSO LuanVSO commented Apr 26, 2021

this will close #1
did this with the following regex substitution + manual pruning of some files.

#include\s?<(\w*|Arduino_AVRSTL\.h|system_configuration\.h|unwind-cxx\.h)>
#include "$1"

after these changes i was successfully able to compile a sketch with the following includes:

#include <Arduino_AVRSTL.h>
#include <array>
#include <iostream>

@CLAassistant
Copy link

CLAassistant commented Apr 26, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@aentinger aentinger left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thank you @LuanVSO 🚀

@aentinger aentinger merged commit 8cc1c0e into arduino-libraries:main May 25, 2021
@LuanVSO LuanVSO deleted the include-fix branch May 25, 2021 14:54
@matthijskooijman
Copy link

For future reference, I think this change was needed to ensure that this library always includes its own files, rather than the AVr core files. This is particularly the case for the <new> header, which is defined both by uclibc++ and AVR. See also mike-matera/ArduinoSTL#66 (comment) and mike-matera/ArduinoSTL#56 (comment)

@matthijskooijman
Copy link

matthijskooijman commented Jan 10, 2022

I also wonder if this is really the right fix. Even with this applied, I'm still seeing compilation errors:

In file included from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/common/util/Callable.h:6:0,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/common/util/Logger.h:4,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/common/tuitkit/Core.h:9,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/Menus.h:3,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/DebugMenus.cpp:1:
/home/matthijs/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/new:25:10: error: redefinition of 'struct std::nothrow_t'
   struct nothrow_t {};
          ^~~~~~~~~
In file included from /home/matthijs/docs/MKIT/3Devo/FeFirmware/libraries/ArduinoSTL/src/memory:20:0,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/libraries/ArduinoSTL/src/char_traits:22,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/libraries/ArduinoSTL/src/iosfwd:21,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/libraries/ArduinoSTL/src/iterator:21,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/libraries/ArduinoSTL/src/algorithm:19,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/common/tuitkit/Core.h:5,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/Menus.h:3,
                 from /home/matthijs/docs/MKIT/3Devo/FeFirmware/src/DebugMenus.cpp:1:
/home/matthijs/docs/MKIT/3Devo/FeFirmware/libraries/ArduinoSTL/src/new:32:21: note: previous definition of 'struct std::nothrow_t'
  struct _UCXXEXPORT nothrow_t {};

This is with a fairly complex sketch, but I would expect the same thing to happen with a simpler sketch too.

I wonder if it would not be better for this library to simply use the AVR-provided if it is present, or revert to its own version of when the AVR core does not provide it. I thought this could be done by reverting this PR, and appling the second suggestions from mike-matera/ArduinoSTL#56 (comment) to fix the _UCXXEXPORT issue, but that still seems to leave a conflict about std::no_throw being defined twice (previously pointed out here).

More generally, there is more new-related stuff between the AVR core and this library's .cpp files (i.e. it's not just a matter of header conflicts). In practice, it seems it's only the std::nothrow that has an issue, but that's probably because a bunch of other new/delete operators are declared weak in the AVR core, so can be replaced by the uclibc++ implementations. It would make some sense to simply remove all the new-related stuff from this library, but that breaks compatibility with older AVR core versions that did not (completely) define the <new> header yet.

Ideally, you would just sort this using preprocessor directives (are already some checks for ARDUINO < 100 in e.g. new_op.cpp), but there is not currently any way AFAIK to detect the core version number (ARDUINO worked when the AVR core and IDE version were tightly coupled, but is currently completely meaningless, especially since IDE and arduino-cli/arduino-builder versions are unrelated too).

One workaround would be to #include <new> and then check for the include guard defined by new in this library, __STD_NEW_OPERATOR (or alternatively add a more specifically named define specifically for this purpose). This allows detecting whether the AVR core offers <new> or not, and allows this library to omit all new-related stuff if it does (i.e. add guards in all new_*.cpp and del_*.cpp files). I think this should fix the issue completely, except for AVR core 1.8.3, which does expose <new>, but it is incomplete (though it might be sufficient for most sketches if uclibc itself doesn't choke on the missing parts).

I've gone ahead and implemented my suggested approach, which seems to work. I haven't done extensive testing, though, so testing is very welcome. PR is here: #8

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

include confusion
4 participants