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.
This commit is contained in:
Henrik Rydgård committed 2026-09-05 13:31:16 -06:00
1 parent bc095c5e31
commit 618bdc2d72
4 files changed
+21 -11

No files matched your search

+8 -10
View File
@@ -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() {
+3
View File
@@ -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`.
+4
View File
@@ -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);
+6 -1
View File
@@ -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;
}