From 618bdc2d729e04503577bbad58e0135a0d5fb4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 5 Sep 2026 13:31:16 -0600 Subject: [PATCH] naett: Let naettInit be called more than once It asserted that it was the first call, so net::Init - which is documented as safe to call repeatedly, and is - needed a bool of its own purely to guard this one line. That's bookkeeping the library may as well do itself, and the WSA half of the same function already says as much: it doesn't track anything because WSAStartup counts its own references. So a repeat call does nothing, and net::Init loses g_naettInitialized. Asking HTTPSAvailable() twice costs nothing - on Linux it's a cached dlopen result and everywhere else it's a constant. --- Common/Net/Resolve.cpp | 18 ++++++++---------- ext/naett-lib/README-ppsspp.md | 3 +++ ext/naett-lib/naett.h | 4 ++++ ext/naett-lib/src/naett_core.c | 7 ++++++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Common/Net/Resolve.cpp b/Common/Net/Resolve.cpp index bc52b912ac..e43192ee9d 100644 --- a/Common/Net/Resolve.cpp +++ b/Common/Net/Resolve.cpp @@ -31,7 +31,6 @@ extern JavaVM *gJvm; namespace net { -static bool g_naettInitialized; static bool g_wsaInitialized; void Init() { @@ -44,19 +43,18 @@ void Init() { g_wsaInitialized = true; } #endif - if (!g_naettInitialized) { + // naett ignores repeat calls the same way WSAStartup does, so there's nothing to track here + // either. HTTPSAvailable is cheap to ask twice - on Linux it's a cached dlopen result. #ifndef HTTPS_NOT_AVAILABLE #if PPSSPP_PLATFORM(ANDROID) - _assert_(gJvm != nullptr); - naettInit(gJvm); + _assert_(gJvm != nullptr); + naettInit(gJvm); #else - if (HTTPSAvailable()) { - naettInit(NULL); - } -#endif -#endif - g_naettInitialized = true; + if (HTTPSAvailable()) { + naettInit(NULL); } +#endif +#endif } bool HTTPSAvailable() { diff --git a/ext/naett-lib/README-ppsspp.md b/ext/naett-lib/README-ppsspp.md index b0612eb6fb..008b7262fb 100644 --- a/ext/naett-lib/README-ppsspp.md +++ b/ext/naett-lib/README-ppsspp.md @@ -116,3 +116,6 @@ Keep this list up to date - it's what makes it possible to move to a newer upstr release build that walked into a null dereference. Returns NULL instead. - `src/naett_osx.c`: the delegate callbacks ignore a response that's already complete, so a cancellation we asked for doesn't overwrite the error that caused it. +- `src/naett_core.c` / `naett.h`: `naettInit` asserted it was only ever called once, so a caller + that can be entered more than again needed a flag purely to guard it. A repeat call is a no-op + now, the way `WSAStartup` behaves, and `net::Init` dropped its `g_naettInitialized`. diff --git a/ext/naett-lib/naett.h b/ext/naett-lib/naett.h index 67716a0626..7d6102671d 100644 --- a/ext/naett-lib/naett.h +++ b/ext/naett-lib/naett.h @@ -17,6 +17,10 @@ typedef void* naettInitData; /** * @brief Global init method. * Call to initialize the library. + * + * PPSSPP: calling this more than once is fine - everything after the first call does nothing, + * including the platform setup, so the init data from the first call is the one that sticks. + * Not thread safe; call it during startup, before anything else can reach the library. */ void naettInit(naettInitData initThing); diff --git a/ext/naett-lib/src/naett_core.c b/ext/naett-lib/src/naett_core.c index b6f4efc8c3..7140beaebd 100644 --- a/ext/naett-lib/src/naett_core.c +++ b/ext/naett-lib/src/naett_core.c @@ -137,7 +137,12 @@ static void applyOptionParams(InternalRequest* req, InternalOption* option) { // Public API void naettInit(naettInitData initData) { - assert(!initialized); + // PPSSPP: upstream asserted that this was the first call. Callers that can be entered more + // than once then need a flag of their own purely to guard this, which is bookkeeping the + // library may as well do itself - so a repeat call is a no-op instead. + if (initialized) { + return; + } naettPlatformInit(initData); initialized = 1; }