Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host tests: different Arduino.h contents #7359

Closed
6 tasks done
mcspr opened this issue Jun 7, 2020 · 4 comments · Fixed by #7377
Closed
6 tasks done

Host tests: different Arduino.h contents #7359

mcspr opened this issue Jun 7, 2020 · 4 comments · Fixed by #7377

Comments

@mcspr
Copy link
Collaborator

mcspr commented Jun 7, 2020

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: Host tests
  • Core Version: e70092c
  • Development Env: esp8266 Arduino Mock

Problem Description

As noticed in the #6294 , host tests Arduino.h should be in sync with the one used to build the real firmware.

MCVE

This does not cause any immediate issues, just introduces different build settings for host. Some (but not all) examples are:

  • boolean typedef
  • implicit #include <cmath>
  • abs redefinition

This may cause more problems in the future, perhaps both headers should use the common source and adjust platform-specific settings.

@d-a-v
Copy link
Collaborator

d-a-v commented Jun 13, 2020

@mcspr do you intend to propose a PR ?

@mcspr
Copy link
Collaborator Author

mcspr commented Jun 13, 2020

Yes. I have a somewhat working POC with only a cores/esp8266/Arduino.h, just need some time to actually push it

Significant issue with std::abs <-> abs is still there for me, not really sure why cstdlib / stdlib.h / Arduino.h decides to be included in a different order in mocks and in real hardware builds... But, more in the PR itself, with some code examples.

@d-a-v
Copy link
Collaborator

d-a-v commented Jun 13, 2020

What happens in mock does not follow any official rule. Bend it if you can, to comply with arduino.

@mcspr
Copy link
Collaborator Author

mcspr commented Jun 14, 2020

For the specific issue with abs, problem is with compiler versions. Even with 7.5.0 used by the CI, the following example based on the Arduino.h assumptions is invalid.

extern "C" {
#include <stdlib.h>
#include <stdio.h>
}
#undef abs
#define abs(x) ((x > 0) ? (x) : -(x))

#include <algorithm>
int main() {
    printf("%d\n", std::abs(-1));
}
~> g++ --version
g++ (GCC) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

~> g++ -c -o example.o example.cpp
example.cpp: In function ‘int main()’:
example.cpp:6:16: error: expected unqualified-id before ‘(’ token
    6 | #define abs(x) ((x > 0) ? (x) : -(x))
      |                ^
example.cpp:10:25: note: in expansion of macro ‘abs’
   10 |     printf("%d\n", std::abs(-1));
      |                         ^~~
~> ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-g++ --version
xtensa-lx106-elf-g++ (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

~> ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-g++ -c -o example.o example.cpp
~> # builds just fine

GCC 10 PR already exposed this issue, because it includes <cstdlib> right from the top, stdlib.h now is a proxy-header from the C++ stdlib and not the original C header, as was expected before. So the original code expects to receive abs definition from the stdlib.h, undef it, load cstdlib (implicitly loaded via algorithm header) and have c++ abs. What happens in CI, it loads cstdlib from the get-go, there is no abs to undef by the Arduino.h, but it still sets up it's own definition.

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

Successfully merging a pull request may close this issue.

2 participants