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 JSON #1165

Merged
merged 5 commits into from
Dec 31, 2023
Merged

fix JSON #1165

merged 5 commits into from
Dec 31, 2023

Conversation

Reputeless
Copy link
Member

@Reputeless Reputeless commented Dec 12, 2023

Siv3D/include/Siv3D/JSON.hpp Outdated Show resolved Hide resolved
Siv3D/src/Siv3D/JSON/SivJSON.cpp Outdated Show resolved Hide resolved
Copy link
Member

@tomolatoon tomolatoon left a comment

Choose a reason for hiding this comment

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

1. 寿命について

以前触れたように、寿命を延長出来るようにして、次のコードが通るようにするのがいいと思います。
https://discord.com/channels/443310697397354506/999983621408567326/1162390851624898581

#include <Siv3D.hpp>

JSON f() {
	JSON json = UR"({
		"foo": 42,
		"bar": "Hello, world!",
		"baz": [1, 2, 3]
	})"_json;

	// operator[] の返り値はプロキシとして働く、pvalue の JSON なので、nlohmann::json の値を所有していない
	return json[U"baz"];
}

void Main() {
	// 現状: 返り値は元のインスタンスが所有している nlohmann::json を参照しているが、その nlohmann::json は既に破棄されているので実行時エラー
	Console << f();
}

2. メンバ関数clearについて

clearについても、not m_isValidのチェックを無くし、invalid な状態からの復帰が出来るようにするべきです。

@Raclamusi
Copy link
Member

1. 寿命について

以前触れたように、寿命を延長出来るようにして、次のコードが通るようにするのがいいと思います。 https://discord.com/channels/443310697397354506/999983621408567326/1162390851624898581

寿命の延長を実装するなら、detail::JSONDetail::RefTypestd::shared_ptr<detail::JSONDetail::ValueType> にするのがよさそうですね。

https://gist.github.com/Raclamusi/08fbf4e70d0f1ac418793b7cdce30f7e/revisions#diff-018619d34dd37983bbc72f3e0cdfbd1a131c0670de6bec1d6bf04bddd206dece

@Reputeless
Copy link
Member Author

ありがとうございます。JSON クラス、v0.6.15 以降で根本的に作り直したいので、寿命の延長関連は新規のほうで検討しましょう。そちらは別の Issue を立てます。

Co-authored-by: Raclamusi <61970673+Raclamusi@users.noreply.github.com>
@Reputeless
Copy link
Member Author

メンバ関数 clear について → JSON.clear() は少し特殊で、クリア後も JSONValueType を保持する仕様になっています。例えば配列を .clear() したら空の配列になるなど。

そのため、Invalid の .clear() 結果が Invalid であるのも不自然ではないと考えています。
#1175 ではそもそも Invalid を廃止することも検討しているので、ここら辺の仕様変更はスキップしたいと思います。

@Reputeless
Copy link
Member Author

レビューありがとうございました。 @Raclamusi @tomolatoon
気になった点は修正したので、これでマージする予定です。#1175 についても参加いただけると幸いです。

@Reputeless Reputeless merged commit bb2c27f into v6_develop Dec 31, 2023
4 checks passed
@Reputeless Reputeless deleted the v6_develop_jsonfix branch December 31, 2023 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants