Skip to content

Missing prototype in Arduino 1.6.8 #140

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

Closed
Lauszus opened this issue May 2, 2016 · 7 comments
Closed

Missing prototype in Arduino 1.6.8 #140

Lauszus opened this issue May 2, 2016 · 7 comments
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project

Comments

@Lauszus
Copy link

Lauszus commented May 2, 2016

It seems like Arduino 1.6.8 does not generate the function prototypes for the following examples in the USB Host shield library correctly: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/WiiMulti/WiiMulti.ino and https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3Multi/PS3Multi.ino.

More specifically the function prototype void onInit(); does not seem to be properly generated.

This was originally reported by a user at the following issue: felis/USB_Host_Shield_2.0#237.

A workaround for now is just to create the function prototype manually:

void onInit();

The same examples work fine in Arduino 1.6.7.

The full debug output is available here: https://gist.github.com/Lauszus/3daf5e6a5a6dde47b849b72f498dbdc9.

@per1234
Copy link
Contributor

per1234 commented May 2, 2016

The bug is caused by the function of the same name in the library: https://github.com/felis/USB_Host_Shield_2.0/blob/master/Wii.h#L430.
A simplified sketch that demonstrates the issue is:

class test {
    void asdf() {}
};
void setup() {
  asdf();
}
void loop() {}
void asdf() {}

With Arduino IDE 1.6.8 and 1.6.9 2016/04/28 04:33 this fails to compile. With Arduino IDE 1.6.7 and previous it successfully compiles.

@matthijskooijman
Copy link
Collaborator

I suspect #131 would "fix" the original bug (not the testcase @per1234 provided), by not running ctags on the library code, just on the sketch code.

However, looking at the ctags output, this is what is generated for the asdf() method in the last example:

asdf sketch_may03a.ino /^ void asdf() {}$/;" kind:function line:4 class:test signature:() returntype:void

The class:test indicates that this is a method, not a function, but I suspect arduino-builder ignores that, so that should be fixed.

@per1234, thanks for looking into this and pointing out the cause! @facchinm, would you look into fixing this?

@facchinm
Copy link
Member

facchinm commented May 3, 2016

I'm taking a look right now.
Indeed, the Ps3Multi issue is solved by #131 , but @per1234 's simplified example is not (of course). The builder needs to be aware of class tag and skip any function outside the main scope. I'll patch this adding a commit to #131

facchinm added a commit to facchinm/arduino-builder that referenced this issue May 4, 2016
Signed-off-by: Martino Facchin <[email protected]>
matthijskooijman pushed a commit to matthijskooijman/arduino-builder that referenced this issue May 18, 2016
While generating prototypes, a scan is made for any function definitions
which would result in identical prototypes, and all but the first are
skipped. However, when doing so, this did not take into account function
definitions which were already marked to be skipped, which could cause
*all* definitions to be skipped.

This behaviour caused a particular problem when a method definition
existed with the same signature as a function definition. All method
definitions are skipped through `tagIsUnhandled`, but could still
make `skipDuplicates` skip the corresponding function definition. This
commit fixes this.

It is not entirely clear to me if this duplicate removal is actually
needed at all. If code contains multiple function definitions with the
same signature, you would expect the compiler to throw an error anyway.
If duplicate removal would be removed, only one testcase
(TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures) fails,
but that testcase uses a predefined ctags output that contains a
duplicate function definition. It is not quite clear what source files
this output was generated from (it seems to stem from
CharWithEscapedDoubleQuote.ino, which originated at
arduino/Arduino#1245, but those only contain
one version of the function definition, not two).

Still, since the ctags parsing will hopefully be replaced in the near
future, this just fixes the duplicate removal instead of removing it and
risking a regression on some corner case.

This fixes arduino#140.

Signed-off-by: Martino Facchin <[email protected]>
Signed-off-by: Matthijs Kooijman <[email protected]>
@matthijskooijman
Copy link
Collaborator

#154 should fix this issue completely (both the original one and the testcase from @per1234).

@Lauszus
Copy link
Author

Lauszus commented May 18, 2016

@matthijskooijman thanks and @per1234 thanks a lot for tracking down the cause of the bug!

@nitturis
Copy link

arduino 1.8.7 has same issue

@2scorpio
Copy link

arduino 1.8.13 has same issue

@per1234 per1234 added conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project labels Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants