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

Fix NO_GLOBAL_INSTANCES #8184

Merged
merged 15 commits into from
Jul 17, 2021
Merged

Fix NO_GLOBAL_INSTANCES #8184

merged 15 commits into from
Jul 17, 2021

Conversation

paulocsanz
Copy link
Contributor

@paulocsanz paulocsanz commented Jun 27, 2021

Fixes #8183

It's not clear to me if this is the best solution. This is just a first draft so the community can debate on a better solution.

But it seems a fairly simple thing to fix. But something needed, if something is used internally it should be declared + defined.

It's not clear to me if we should create it when NO_GLOBAL_STREAMDEV is specifically defined.

@paulocsanz paulocsanz changed the title Create devnull static if needed Create devnull variable if needed Jun 27, 2021
@paulocsanz
Copy link
Contributor Author

Is it better as static or as a regular stack variable? Since it only occupies 1 byte.

@paulocsanz
Copy link
Contributor Author

paulocsanz commented Jul 4, 2021

@dok-net Can you review it after the Serial changes? I fear it may cause breaking changes since it will force people to define Serial when they didn't have to before.

@paulocsanz paulocsanz requested a review from devyte July 4, 2021 17:52
Copy link
Contributor

@dok-net dok-net left a comment

Choose a reason for hiding this comment

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

ArduinoCore-avr does void serialEventRun(void) differently, I suggest adopting that implementation:
Implement void serialEventRun(void) in HardwareSerial.cpp unconditionally, that is, outside the #if block. In turn, enclose the code inside the function body in the same preprocessor conditional directive.
One could potentially add serialEvent1, too, in the same way.

cores/esp8266/HardwareSerial.h Show resolved Hide resolved
@paulocsanz
Copy link
Contributor Author

I've undone the Serial changes, because it seems is a more complex issue that doesn't need to block this PR. We can talk about this more in the issue and if it makes sense, doesn't break compatibility and we find all the other declaration that are not defined we can make a new PR.

@dok-net
Copy link
Contributor

dok-net commented Jul 9, 2021

I've undone the Serial changes, because it seems is a more complex issue that doesn't need to block this PR. We can talk about this more in the issue and if it makes sense, doesn't break compatibility and we find all the other declaration that are not defined we can make a new PR.

Declaring symbols that are not defined is an error, don't you think so? Your reversal simply could cause the compile phase to succeed, but then linking will fail. I'm speaking from my perception that it's all about NO_GLOBALS in general, not devnull in particular, of course.

As to my remark involving the extern void serialEventRun(void) __attribute__((weak));, reminding myself that Serial1 is TX-only leaves the existing code as just right. With a little cleanup of a comment, this would be the commit, that you unfortunately just reverted:

diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp
index 4f09d26f..88b47b33 100644
--- a/cores/esp8266/HardwareSerial.cpp
+++ b/cores/esp8266/HardwareSerial.cpp
@@ -35,9 +35,6 @@

 // SerialEvent functions are weak, so when the user doesn't define them,
 // the linker just sets their address to 0 (which is checked below).
-// The Serialx_available is just a wrapper around Serialx.available(),
-// but we can refer to it weakly so we don't pull in the entire
-// HardwareSerial instance if the user doesn't also refer to it.
 void serialEvent() __attribute__((weak));

 HardwareSerial::HardwareSerial(int uart_nr)
diff --git a/cores/esp8266/HardwareSerial.h b/cores/esp8266/HardwareSerial.h
index bdccae5e..ea17f60e 100644
--- a/cores/esp8266/HardwareSerial.h
+++ b/cores/esp8266/HardwareSerial.h
@@ -233,8 +233,12 @@ protected:
     size_t _rx_size;
 };

+#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
 extern HardwareSerial Serial;
+#endif
+#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1)
 extern HardwareSerial Serial1;
+#endif

@paulocsanz
Copy link
Contributor Author

I added it again

Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

Thanks for trying to fix multiple things, but it’s really neat if you do one change per PR, please. Can you remove the unrelated hardware serial stuff?

@dok-net
Copy link
Contributor

dok-net commented Jul 9, 2021

Thanks for trying to fix multiple things, but it’s really neat if you do one change per PR, please. Can you remove the unrelated hardware serial stuff?

@earlephilhower If it were a mistake, it would be on me, I've asked the submitter to add it back in. You would have to try and see it from a different angle: The issue is not to create the devnull, but the fact that NO_GLOBAL_INSTANCES is not handled correctly. This applies to both HardwareSerial and HttpClient. Plus, the comment that got removed is non-applicable to ESP8266's implementation and confusing, which turns up when doing this change.

There are NO further issues in this core regarding NO_GLOBAL_INSTANCES!

So, isn't it best to rename this PR, instead of splitting it up into extraordinarily small chunks? Besides, it's a simple fix for HardwareSerial, nothing else, or what could possible be the point in declaring something extern (no weak or anything) in the core headers that is not defined? It's just going to produce a linker error, which are harder on the average coder to understand.

@paulocsanz
Copy link
Contributor Author

Awaiting further instructions. I'm OK with both approaches, just ping me and I will edit the PR accordingly (or make a new PR to split the changes). But I don't have much to contribute to the discussion. I agree that this could become a PR to fix all the problems related to NO_GLOCAL_INSTANCES, but I haven't ensured those are the only ones, they are the ones I found while maintaining our system.

@dok-net
Copy link
Contributor

dok-net commented Jul 12, 2021

@paulocsanz I grepped all cores and libraries and found no other uses, that's all.

@paulocsanz paulocsanz changed the title Create devnull variable if needed Fix NO_GLOBAL_INSTANCES Jul 12, 2021
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

OK, I'm convinced. LGTM.

@earlephilhower earlephilhower added this to the 3.0.2 milestone Jul 17, 2021
@earlephilhower earlephilhower merged commit c9f2741 into esp8266:master Jul 17, 2021
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 this pull request may close these issues.

-DNO_GLOBAL_INSTANCES breaks ESP8266HttpClient
5 participants