Skip to content

Commit 8d3a256

Browse files
committed
避免Opaque冲突
1 parent 36ba092 commit 8d3a256

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

include/CppObjectMapperQuickjs.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct CppObjectMapper
2828
{
2929
inline static CppObjectMapper* Get(JSContext* ctx)
3030
{
31-
return reinterpret_cast<CppObjectMapper*>(JS_GetRuntimeOpaque(JS_GetRuntime(ctx)));
31+
return reinterpret_cast<CppObjectMapper*>(JS_GetRuntimeOpaque1(JS_GetRuntime(ctx)));
3232
}
3333

3434
void Initialize(JSContext* ctx_);
@@ -60,8 +60,7 @@ struct CppObjectMapper
6060

6161
inline static eastl::weak_ptr<int> GetEnvLifeCycleTracker(JSContext* ctx)
6262
{
63-
JSRuntime* rt = JS_GetRuntime(ctx);
64-
CppObjectMapper* mapper = reinterpret_cast<CppObjectMapper*>(JS_GetRuntimeOpaque(rt));
63+
CppObjectMapper* mapper = Get(ctx);
6564
return mapper->GetEnvLifeCycleTracker();
6665
}
6766

include/PapiData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ namespace qjsimpl
6868

6969
static struct pesapi_scope__ *getCurrentScope(JSContext *ctx)
7070
{
71-
return (struct pesapi_scope__ *) JS_GetContextOpaque(ctx);
71+
return (struct pesapi_scope__ *) JS_GetContextOpaque1(ctx);
7272
}
7373

7474
static void setCurrentScope(JSContext *ctx, struct pesapi_scope__ *scope)
7575
{
76-
JS_SetContextOpaque(ctx, scope);
76+
JS_SetContextOpaque1(ctx, scope);
7777
}
7878

7979
struct caught_exception_info

quickjs/quickjs.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ struct JSRuntime {
302302
JSShape **shape_hash;
303303
bf_context_t bf_ctx;
304304
void *user_opaque;
305+
void *user_opaque1;
305306
void *libc_opaque;
306307
JSRuntimeFinalizerState *finalizers;
307308
};
@@ -442,6 +443,7 @@ struct JSContext {
442443
const char *input, size_t input_len,
443444
const char *filename, int flags, int scope_idx);
444445
void *user_opaque;
446+
void *user_opaque1;
445447
};
446448

447449
typedef union JSFloat64Union {
@@ -55902,4 +55904,24 @@ int JS_ValueRefCount(JSContext *ctx, JSValue v)
5590255904
return -1;
5590355905
}
5590455906

55907+
void *JS_GetContextOpaque1(JSContext *ctx)
55908+
{
55909+
return ctx->user_opaque1;
55910+
}
55911+
55912+
void JS_SetContextOpaque1(JSContext *ctx, void *opaque)
55913+
{
55914+
ctx->user_opaque1 = opaque;
55915+
}
55916+
55917+
void *JS_GetRuntimeOpaque1(JSRuntime *rt)
55918+
{
55919+
return rt->user_opaque1;
55920+
}
55921+
55922+
void JS_SetRuntimeOpaque1(JSRuntime *rt, void *opaque)
55923+
{
55924+
rt->user_opaque1 = opaque;
55925+
}
55926+
5590555927
/*-------end additional function---------*/

quickjs/quickjs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,12 @@ JS_BOOL JS_GetArrayBufferViewInfo(JSContext *ctx, JSValueConst obj,
10511051

10521052
int JS_ValueRefCount(JSContext *ctx, JSValue v);
10531053

1054+
// avoid conflict
1055+
void *JS_GetContextOpaque1(JSContext *ctx);
1056+
void JS_SetContextOpaque1(JSContext *ctx, void *opaque);
1057+
void *JS_GetRuntimeOpaque1(JSRuntime *rt);
1058+
void JS_SetRuntimeOpaque1(JSRuntime *rt, void *opaque);
1059+
10541060
/*-------end additional function---------*/
10551061

10561062
#ifdef __cplusplus

source/CppObjectMapperQuickjs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct FuncFinalizeData
1515

1616
void PApiFuncFinalizer(JSRuntime* rt, JSValue val)
1717
{
18-
CppObjectMapper* mapper = reinterpret_cast<CppObjectMapper*>(JS_GetRuntimeOpaque(rt));
18+
CppObjectMapper* mapper = reinterpret_cast<CppObjectMapper*>(JS_GetRuntimeOpaque1(rt));
1919
FuncFinalizeData* data = (FuncFinalizeData*)JS_GetOpaque(val, mapper->funcTracerClassId);
2020
if (data->finalize)
2121
{
@@ -68,7 +68,7 @@ JSValue CppObjectMapper::CreateError(JSContext* ctx, const char* message)
6868

6969
void PApiObjectFinalizer(JSRuntime* rt, JSValue val)
7070
{
71-
CppObjectMapper* mapper = reinterpret_cast<CppObjectMapper*>(JS_GetRuntimeOpaque(rt));
71+
CppObjectMapper* mapper = reinterpret_cast<CppObjectMapper*>(JS_GetRuntimeOpaque1(rt));
7272
ObjectUserData* object_udata = (ObjectUserData*)JS_GetOpaque(val, mapper->classId);
7373

7474
if (object_udata->callFinalize && object_udata->typeInfo->Finalize)
@@ -338,7 +338,7 @@ void CppObjectMapper::Initialize(JSContext* ctx_)
338338
{
339339
ctx = ctx_;
340340
rt = JS_GetRuntime(ctx);
341-
JS_SetRuntimeOpaque(rt, this);
341+
JS_SetRuntimeOpaque1(rt, this);
342342
//new (&CDataCache) eastl::unordered_map<const void*, FObjectCacheNode, eastl::hash<const void*>,
343343
// eastl::equal_to<const void*>, eastl::allocator_malloc>();
344344
//new (&TypeIdToFunctionMap) eastl::unordered_map<const void*, JSValue, eastl::hash<const void*>,
@@ -441,7 +441,7 @@ void destroy_qjs_env(pesapi_env_ref env_ref)
441441
//auto scope = pesapi::qjsimpl::g_pesapi_ffi.open_scope(env_ref);
442442
JSContext* ctx = reinterpret_cast<JSContext*>(pesapi::qjsimpl::g_pesapi_ffi.get_env_from_ref(env_ref));
443443
JSRuntime* rt = JS_GetRuntime(ctx);
444-
pesapi::qjsimpl::CppObjectMapper* mapper = reinterpret_cast<pesapi::qjsimpl::CppObjectMapper*>(JS_GetRuntimeOpaque(rt));
444+
pesapi::qjsimpl::CppObjectMapper* mapper = pesapi::qjsimpl::CppObjectMapper::Get(ctx);
445445
//pesapi::qjsimpl::g_pesapi_ffi.close_scope(scope);
446446
pesapi::qjsimpl::g_pesapi_ffi.release_env_ref(env_ref);
447447
mapper->Cleanup();

0 commit comments

Comments
 (0)