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

6.13.0 broken for non-copy-constructable String types #1126

Closed
mikee47 opened this issue Nov 5, 2019 · 3 comments
Closed

6.13.0 broken for non-copy-constructable String types #1126

mikee47 opened this issue Nov 5, 2019 · 3 comments

Comments

@mikee47
Copy link

mikee47 commented Nov 5, 2019

With commit 6da6f92 both ElementProxy and MemberProxy take copies of the
TString argument instead of taking a reference.

This breaks existing code which depends upon the referencing behaviour, and also has performance/efficiency implications.

The fault addressed by the above commit is briefly outlined in #1120, caused by a dangling reference. To clarify, this is where the ElementProxy/MemberProxy take a reference to a temporary object (e.g. arduino String) which the compiler optimises out before the reference is used. This leads to unpredictable behaviour, so clearly taking proper copies is the safest (default) behaviour.

However, I have a custom FlashString class (with adapter) which is not copy-constructible and so now no longer works as intended.

Here are the details:

I've been unable to find a workable solution without modifying ArduinoJson so I'll propose that and see where we go.

It feels like there's room for improvement here. Can we detect when it's safe to take a reference, and do that when possible?

@bblanchon
Copy link
Owner

Hi @mikee47,

I'm sorry I break your code; I didn't see that coming.
As you understood, I had to make this change to fix #1120, and I believe it was the right fix.

Mike, why is the FlashString non-copiable?

Best Regards,
Benoit

@mikee47
Copy link
Author

mikee47 commented Nov 5, 2019

It's used to access counted strings stored in flash memory by casting as a reference. i.e. reinterpret_cast<const FlashString&>(&struc) where struc represents the in-flash data. The data is potentially very large (one use is to directly import file data at compile time) so copying it makes no sense, though obviously such strings would never be used with a JSON document.

I am looking at a revision which uses FlashString a simple wrapper class, and if that make it as easy (or easier) to use then the problem goes away.

@mikee47
Copy link
Author

mikee47 commented Nov 20, 2019

@bblanchon Just to let you know I've fixed the incompatibility problem by adding copy constructor support. Inspired by your own libraries, I've created FlashString. Thank you for setting the standard!

Repository owner locked and limited conversation to collaborators Dec 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants