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

Stack exaustion while value_from(std::filesystem::path) #975

Closed
RoyBellingan opened this issue Feb 1, 2024 · 5 comments · Fixed by #977
Closed

Stack exaustion while value_from(std::filesystem::path) #975

RoyBellingan opened this issue Feb 1, 2024 · 5 comments · Fixed by #977

Comments

@RoyBellingan
Copy link

RoyBellingan commented Feb 1, 2024

PLEASE DON'T FORGET TO "STAR" THIS REPOSITORY :)

Are you inviting me to have multiple account or more friend ?

Version of Boost

1.84

Steps necessary to reproduce the problem

#include <boost/json/src.hpp>
#include <filesystem>
#include <iostream>

namespace bj = boost::json;

int main() {
	std::filesystem::path p = "/cry";
	
	auto ref = bj::value_from(p);
	auto ser = bj::serialize(ref);
	std::cout << ser;
}

if the path is EMPTY it works fine, but if there is something it leads to a stack exausting crash, remaining struct inside those 2

loop (first one is gcc the other clang, quite similar but a bit different)

image(8)

image(9)

Also using

void tag_invoke(const bj::value_from_tag&, bj::value& jv, const std::filesystem::path& t) {
	jv = t.string();
}

std::filesystem::path tag_invoke(const bj::value_to_tag<std::filesystem::path>&, const boost::json::value& jv) {
	std::filesystem::path path = std::string_view(jv.as_string());
	return path;
}

or

void tag_invoke(const bj::value_from_tag&, bj::value& jv, const std::filesystem::__cxx11::path& t) {
	jv = t.string();
}

std::filesystem::path tag_invoke(const bj::value_to_tag<std::filesystem::__cxx11::path>&, const boost::json::value& jv) {
	std::filesystem::path path = std::string_view(jv.as_string());
	return path;
}

Does not help (in fact looks like they are not even used...)

@RoyBellingan
Copy link
Author

The solution is to put the tag_invoke INSIDE the boost::json namespace...

This already happened in another case, for std::chrono,

I think it should be worth to add a note into this page

https://www.boost.org/doc/libs/1_84_0/libs/json/doc/html/json/conversion/custom_conversions.html

To express that, sometimes... you have to put in namespace to help it!

@grisumbras
Copy link
Member

The solution (to the error) is to not treat path as a sequence. It's not what users want anyway (everyone would prefer conversion to a string). This will result in value_to<path> being a compilation error.

The next step will be to add a conversion category for paths.

@grisumbras
Copy link
Member

grisumbras commented Feb 1, 2024

The solution is to put the tag_invoke INSIDE the boost::json namespace...
I think it should be worth to add a note into this page

From that page:

embed the user-defined type into the arguments list (e.g. by using a tag type template such as value_to_tag) so that its associated namespaces and entities are examined when name lookup is performed.

Maybe we should be less cryptic.

@RoyBellingan
Copy link
Author

Yes maybe just drop a few lines about that specific example ?
Is ok if I do a pull request for

* discard candidates that are unrelated to that particular
?

@grisumbras
Copy link
Member

You can create a PR, but before please look for a good place to put the note.

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 a pull request may close this issue.

2 participants