-
Notifications
You must be signed in to change notification settings - Fork 62
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
PrintFile and StreamFile warnings with -Woverloaded-virtual #85
Comments
I would rather have the the patch so I can apply it to my development version. I am about to post a new beta which has much new code. I like to test mods on many boards before posting and I am about to test the new beta. If will I get these mods if I just use this version of ArduinoFiles.h? |
I took your version of ArduinoFiles.h and ran it though clang_format since I now don't fuss with formatting during development and use clang_format. I modified the current version of SdFat-beta ArduinoFiles.h so:
Is
|
Re-uploaded after running clang-format I also forgot about Print::flush() in the first one |
I added Print::flush() and now your fix-wov/beta matches the version I am testing for the next SdFat-beta. The next SdFat-beta will have have an RP2040 PIO SDIO driver I wrote and can read/write at about 25 MB/sec for small, transfers. I tried the ESP32 SDIO driver but it is not worth adding since there is no way to make it go fast for transfers smaller than about 16 KB. Then it is still fairly slow. Unfortunately most SDIO drivers were written for FatFs and don't have a way to use the code I wrote for shared SPI. I probably will only write new SDIO drivers for MCUs I use. |
I started testing and found a problem. I searched through 21 Arduino packages for the regular expression "virtual +int +read" in Stream.h and found ESP8266 was the only one that had
These seem to be the standard virtual member function in true Arduino packages:
I decided to try changing:
to:
Then it matches other files:
|
Hm... this was added for StreamDev.h API in ESP8266 (previosuly virtual size_t readBytes()), so it is definitely not real-real Arduino API. We can change it to have diff --git a/src/common/ArduinoFiles.h b/src/common/ArduinoFiles.h
index 4c39dad..0aabf09 100644
--- a/src/common/ArduinoFiles.h
+++ b/src/common/ArduinoFiles.h
@@ -106,9 +106,20 @@ class StreamFile : public stream_t, public BaseFile {
* \return For success return the number of read bytes.
* If an error occurs or end of file is reached return -1.
*/
- int read(uint8_t* buffer, size_t size) override {
+ int read(void* buffer, size_t size) {
return BaseFile::read(buffer, size);
}
+#if defined(ESP8266)
+ int read(uint8_t* buffer, size_t size) override {
+ return BaseFile::read((void*)buffer, size);
+ }
+ size_t readBytes(uint8_t* buffer, size_t size) override {
+ return (size_t)read((void*)buffer, size);
+ }
+ size_t readBytes(char* buffer, size_t size) {
+ return readBytes((uint8_t*)buffer, size);
+ }
+#endif
/** Rewind a file if it is a directory */
void rewindDirectory() {
if (BaseFile::isDir()) { |
Another problem.
The big problem is Arduino Due. These are the only virtual members.
The new standard Arduino API has these four virtual members.
I am thinking of removing it from It is in the base files so it should not break apps
Any suggestions? P.S. You can see why I don't blindly use pull-requests. I find almost all pull-requests tested on only one board package break some other board package. |
Here is the history of flush from Arduino. Strange they say this: Since it is rarely in the Stream class.
This explains why Due has the error for flush() in Print. Flush should be in Print but the main use of flush is in Serial which has Stream as the base class and Stream has Print as the Base class. So for implementations of Serial flush can be in either Print or Stream. Maybe I can remove flush from ArduinoFiles.h and not break anything. |
flush() can lose override keyword, apparently C++ does not care whether it is there (I did care, though :) But warnings would still trigger for different arguments in similarly named methods |
I understand. Maybe the answer is to have the override in the StreamFile class and not the PrintFile class. A C++ compiler can't know whether flush appears in Stream or Print since Stream has Print as a base class. Try this and see if you get warnings. I only have the PrintFile class for backward compatibility with the old SdFile class. I don't use it in any version 2.x examples.
There are now over 100 board packages for the Arduino IDE. It is hopeless to write a modern safe C++ library for this motley collection. |
No warnings w/ the suggested change for PrintFile. I do see now that StreamFile is what ESP8266 have been using through File32, PrintFile just got noticed at the same time since it gets pulled from SdFat.h as well btw I only noticed this warning after trying to build our Core tests with gcc13.2, which happen to include SdFat to check SDFS & SD APIs. By default it builds with -Wall -Werror, and -Woverloaded-virtual=1 is now enabled by default with >=gcc13 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87729 (-Woverloaded-virtual=2 also passes the build, only errors come from ESP8266 classes) |
I decided to make a change so PrintFile builds correctly. I added an exception for SAM_DUE. The board package for Due clearly has a bug with flush() being in Stream and not in Print. I may post an issue about flush() for Due. Arduino probably won't bother to fix it since no one has posted an issue about flush() not being in Print. This is my mod for flush() in PrintFile:
This is flush() in StreamFile:
Arduino is modifying most board packages to use this new ArduinoCore-API package. It has flush() here. If the Due package is updated, the above patch should still work. Here is a zip with the current version of ArduinoFiles.h |
Building with esp8266/Arduino, gcc10.3 and forcibly enabled -Woverloded-virtual
...etc...
If I understood the intent correctly, changes should be something like this - hiding original methods by removing 'using = ...' and adding explicit override to the methods required for Print & Stream
mcspr/ESP8266SdFat@f4d4076
(we are still at SdFat version 2.1.1, but the issue applies to both latest release and beta version here. plus, updated formatting)
Do you accept pull-requests here?
The text was updated successfully, but these errors were encountered: