Remove CxxModuleWrapper.makeDSO (#41309)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41309

Changelog: [Internal][Removed] CxxModuleWrapper.makeDSO is not actively used and has been replaced by TurboModule infra.

Reviewed By: NickGerleman

Differential Revision: D50878589

fbshipit-source-id: 9fd11c1ee860ea65f1e985a132de3216ed042752
This commit is contained in:
Pieter De Baets
2023-11-03 12:13:20 -07:00
committed by Facebook GitHub Bot
parent 87c2453120
commit 9b613855eb
4 changed files with 1 additions and 78 deletions
@@ -9,7 +9,6 @@ package com.facebook.react.bridge;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;
/** This does nothing interesting, except avoid breaking existing code. */
@DoNotStrip
@@ -17,12 +16,4 @@ public class CxxModuleWrapper extends CxxModuleWrapperBase {
protected CxxModuleWrapper(HybridData hd) {
super(hd);
}
private static native CxxModuleWrapper makeDsoNative(String soPath, String factory);
public static CxxModuleWrapper makeDso(String library, String factory) {
SoLoader.loadLibrary(library);
String soPath = SoLoader.unpackLibraryAndDependencies(library).getAbsolutePath();
return makeDsoNative(soPath, factory);
}
}
@@ -1,57 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "CxxModuleWrapper.h"
#include <glog/logging.h>
#include <folly/ScopeGuard.h>
#include <dlfcn.h>
using namespace facebook::jni;
using namespace facebook::xplat::module;
namespace facebook::react {
jni::local_ref<CxxModuleWrapper::javaobject> CxxModuleWrapper::makeDsoNative(
jni::alias_ref<jclass>,
const std::string& soPath,
const std::string& fname) {
// soPath is the path of a library which has already been loaded by
// java SoLoader.loadLibrary(). So this returns the same handle,
// and increments the reference counter. We can't just use
// dlsym(RTLD_DEFAULT, ...), because that crashes on 4.4.2 and
// earlier: https://code.google.com/p/android/issues/detail?id=61799
void* handle = dlopen(soPath.c_str(), RTLD_NOW);
if (!handle) {
throwNewJavaException(
gJavaLangIllegalArgumentException,
"module shared library %s is not found",
soPath.c_str());
}
// Now, arrange to close the handle so the counter is decremented.
// The handle will remain valid until java closes it. There's no
// way to do this on Android, but that's no reason to be sloppy
// here.
auto guard = folly::makeGuard([&] { CHECK(dlclose(handle) == 0); });
void* sym = dlsym(handle, fname.c_str());
if (!sym) {
throwNewJavaException(
gJavaLangIllegalArgumentException,
"module function %s in shared library %s is not found",
fname.c_str(),
soPath.c_str());
}
auto factory = reinterpret_cast<CxxModule* (*)()>(sym);
return CxxModuleWrapper::newObjectCxxArgs(
std::unique_ptr<CxxModule>((*factory)()));
}
} // namespace facebook::react
@@ -17,16 +17,6 @@ class CxxModuleWrapper
constexpr static const char* const kJavaDescriptor =
"Lcom/facebook/react/bridge/CxxModuleWrapper;";
static void registerNatives() {
registerHybrid(
{makeNativeMethod("makeDsoNative", CxxModuleWrapper::makeDsoNative)});
}
static jni::local_ref<CxxModuleWrapper::javaobject> makeDsoNative(
jni::alias_ref<jclass>,
const std::string& soPath,
const std::string& fname);
std::string getName() override {
return module_->getName();
}
@@ -14,7 +14,7 @@
#include <fbjni/fbjni.h>
#include "CatalystInstanceImpl.h"
#include "CxxModuleWrapper.h"
#include "CxxModuleWrapperBase.h"
#include "JCallback.h"
#include "JReactMarker.h"
#include "JavaScriptExecutorHolder.h"
@@ -78,7 +78,6 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
ProxyJavaScriptExecutorHolder::registerNatives();
CatalystInstanceImpl::registerNatives();
CxxModuleWrapperBase::registerNatives();
CxxModuleWrapper::registerNatives();
JCxxCallbackImpl::registerNatives();
NativeArray::registerNatives();
ReadableNativeArray::registerNatives();