Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

USB: add pure specifiers and emit vtable#771

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
facchinm merged 1 commit intoarduino:mainfromardnew:usb-emit-vtable
Dec 4, 2023

Conversation

@ardnew
Copy link
Contributor

Issue#130 correctly identifies a newly-added method as pure virtual and fixes the declaration. However, for some reason it didn't address all of the other virtual methods in that same class (PluggableUSBModule) that do not define a default implementation.

The only virtual method that has a default implementation is provided inline in the class interface:

virtualvoidcallback_reset() {};

These issues combined prevent the compiler from being able to emit a vtable for thePluggableUSBModule class, thus preventing users from correctly subclassing it or any one of its derived classes such asUSBCDC,USBHID,USBMIDI, etc. Refer to the following answer on StackOverflow for a detailed explanation of the issue:

https://stackoverflow.com/a/57504289/1054397

This PR adds the pure specifier (= 0) to all of the virtual methods in this class that do not have a default implementation. It also moves the default empty definition ofvirtual void callback_reset() to the class definition inUSB/PluggableUSBDevice.cpp so that this class complies completely with the criteria for emitting a vtable.

Note

The error that I was encountering prior to these changes was pretty
cryptic (from PlatformIO):

.pio/build/hid/src/target.cpp.o: In function `foo()':USBHID/src/PluggableUSBHID.h:53: undefined reference to    `vtable for arduino::internal::PluggableUSBModule'.pio/build/hid/src/target.cpp.o: In function `foo()':foo.hpp:100: undefined reference to    `vtable for arduino::internal::PluggableUSBModule'collect2: error: ld returned 1 exit status*** [.pio/build/hid/firmware.elf] Error 1

Even stranger, the error would only be generated with a debug build;
i.e., the only difference in command-line arguments was the additional
CFLAGS of-Og -g2 -ggdb2. Without the debug flags, my project was
building without error.

With the changes in this PR, my project now builds with and without
these additional debug flags. Further verification was performed by
testing the example sketchesKeyboard,KeyboardRaw, andMouse
from libraryUSBHID as well as using the coreSerial object for
ordinary USB serial I/O (USBCDC).

Issuearduino#130 correctly identifies a newly-added method as pure virtual andfixes the declaration. However, for some reason it didn't address all ofthe other virtual methods in that same class (`PluggableUSBModule`) thatdo not define a default implementation.The only virtual method that has a default implementation is providedinline in the class interface:```c++    virtual void callback_reset() {};```These issues combined prevent the compiler from being able to emit avtable for the `PluggableUSBModule` class, thus preventing users fromcorrectly subclassing it or any one of its derived classes such as`USBCDC`, `USBHID`, `USBMIDI`, etc. Refer to the following answer onStackOverflow for a detailed explanation of the issue:https://stackoverflow.com/a/57504289/1054397This PR adds the pure specifier (`= 0`) to all of the virtual methods inthis class that do not have a default implementation. It also moves thedefault empty definition of `virtual void callback_reset()` to the classdefinition in `USB/PluggableUSBDevice.cpp` so that this class compliescompletely with the criteria for emitting a vtable.> #### Note>> The error that I was encountering prior to these changes was pretty> cryptic (from PlatformIO):>> ```txt> .pio/build/hid/src/target.cpp.o: In function `foo()':> USBHID/src/PluggableUSBHID.h:53: undefined reference to>     `vtable for arduino::internal::PluggableUSBModule'> .pio/build/hid/src/target.cpp.o: In function `foo()':> foo.hpp:100: undefined reference to>     `vtable for arduino::internal::PluggableUSBModule'> collect2: error: ld returned 1 exit status> *** [.pio/build/hid/firmware.elf] Error 1> ```>> Even stranger, the error would only be generated with a debug build;> i.e., the only difference in command-line arguments was the additional> CFLAGS of `-Og -g2 -ggdb2`. Without the debug flags, my project was> building without error.>> With the changes in this PR, my project now builds with and without> these additional debug flags. Further verification was performed by> testing the example sketches `Keyboard`, `KeyboardRaw`, and `Mouse`> from library `USBHID` as well as using the core `Serial` object for> ordinary USB serial I/O (`USBCDC`).
@CLAassistant
Copy link

CLAassistant commentedNov 23, 2023
edited
Loading

CLA assistant check
All committers have signed the CLA.

@facchinm
Copy link
Member

LGTM! Thanks!

@facchinmfacchinm merged commitfcbb950 intoarduino:mainDec 4, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@alrvidalrvidAwaiting requested review from alrvid

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@ardnew@CLAassistant@facchinm

[8]ページ先頭

©2009-2025 Movatter.jp