Skip to content

Commit 61bd7c6

Browse files
committed
Remove wrappers.
1 parent b29163a commit 61bd7c6

4 files changed

Lines changed: 31 additions & 87 deletions

File tree

libs/server-sdk/src/bindings/c/context_wrappers.hpp

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include <launchdarkly/server_side/bindings/c/evaluation_series_context.h>
2-
#include "context_wrappers.hpp"
2+
#include <launchdarkly/server_side/hooks/hook.hpp>
33

44
#include <launchdarkly/bindings/c/context.h>
55
#include <launchdarkly/bindings/c/value.h>
66
#include <launchdarkly/detail/c_binding_helpers.hpp>
77

8-
#define AS_WRAPPER(ptr) \
9-
(reinterpret_cast<launchdarkly::server_side::bindings::EvaluationSeriesContextWrapper const*>(ptr))
8+
#define AS_EVAL_SERIES_CONTEXT(ptr) \
9+
(reinterpret_cast<launchdarkly::server_side::hooks::EvaluationSeriesContext const*>(ptr))
1010

1111
#define AS_CONTEXT(ptr) \
1212
(reinterpret_cast<LDContext>(const_cast<launchdarkly::Context*>(ptr)))
@@ -20,40 +20,40 @@
2020
LD_EXPORT(char const*)
2121
LDEvaluationSeriesContext_FlagKey(LDServerSDKEvaluationSeriesContext eval_context) {
2222
LD_ASSERT(eval_context != nullptr);
23-
return AS_WRAPPER(eval_context)->context.FlagKey().data();
23+
return AS_EVAL_SERIES_CONTEXT(eval_context)->FlagKey().data();
2424
}
2525

2626
LD_EXPORT(LDContext)
2727
LDEvaluationSeriesContext_Context(LDServerSDKEvaluationSeriesContext eval_context) {
2828
LD_ASSERT(eval_context != nullptr);
29-
return AS_CONTEXT(&AS_WRAPPER(eval_context)->context.EvaluationContext());
29+
return AS_CONTEXT(&AS_EVAL_SERIES_CONTEXT(eval_context)->EvaluationContext());
3030
}
3131

3232
LD_EXPORT(LDValue)
3333
LDEvaluationSeriesContext_DefaultValue(
3434
LDServerSDKEvaluationSeriesContext eval_context) {
3535
LD_ASSERT(eval_context != nullptr);
3636
// Return pointer to the value in the C++ context (no copy needed)
37-
return AS_VALUE(&AS_WRAPPER(eval_context)->context.DefaultValue());
37+
return AS_VALUE(&AS_EVAL_SERIES_CONTEXT(eval_context)->DefaultValue());
3838
}
3939

4040
LD_EXPORT(char const*)
4141
LDEvaluationSeriesContext_Method(LDServerSDKEvaluationSeriesContext eval_context) {
4242
LD_ASSERT(eval_context != nullptr);
43-
return AS_WRAPPER(eval_context)->context.Method().data();
43+
return AS_EVAL_SERIES_CONTEXT(eval_context)->Method().data();
4444
}
4545

4646
LD_EXPORT(LDHookContext)
4747
LDEvaluationSeriesContext_HookContext(
4848
LDServerSDKEvaluationSeriesContext eval_context) {
4949
LD_ASSERT(eval_context != nullptr);
50-
return AS_HOOK_CONTEXT(&AS_WRAPPER(eval_context)->context.HookCtx());
50+
return AS_HOOK_CONTEXT(&AS_EVAL_SERIES_CONTEXT(eval_context)->HookCtx());
5151
}
5252

5353
LD_EXPORT(char const*)
5454
LDEvaluationSeriesContext_EnvironmentId(
5555
LDServerSDKEvaluationSeriesContext eval_context) {
5656
LD_ASSERT(eval_context != nullptr);
57-
auto env_id = AS_WRAPPER(eval_context)->context.EnvironmentId();
57+
auto env_id = AS_EVAL_SERIES_CONTEXT(eval_context)->EnvironmentId();
5858
return env_id.has_value() ? env_id->data() : nullptr;
5959
}

libs/server-sdk/src/bindings/c/hook_wrapper.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "hook_wrapper.hpp"
2-
#include "context_wrappers.hpp"
32

43
#include <launchdarkly/bindings/c/data/evaluation_detail.h>
54
#include <launchdarkly/bindings/c/value.h>
@@ -8,15 +7,15 @@
87
#include <cassert>
98

109
// Helper macros for type conversions
11-
#define AS_EVAL_SERIES_CONTEXT_WRAPPER(ptr) \
12-
(reinterpret_cast<LDServerSDKEvaluationSeriesContext>(ptr))
10+
#define AS_EVAL_SERIES_CONTEXT(ptr) \
11+
(reinterpret_cast<LDServerSDKEvaluationSeriesContext>(const_cast<launchdarkly::server_side::hooks::EvaluationSeriesContext*>(ptr)))
1312

1413
#define AS_EVAL_SERIES_DATA(ptr) \
1514
(reinterpret_cast<LDServerSDKEvaluationSeriesData>( \
1615
&const_cast<launchdarkly::server_side::hooks::EvaluationSeriesData&>(ptr)))
1716

18-
#define AS_TRACK_SERIES_CONTEXT_WRAPPER(ptr) \
19-
(reinterpret_cast<LDServerSDKTrackSeriesContext>(ptr))
17+
#define AS_TRACK_SERIES_CONTEXT(ptr) \
18+
(reinterpret_cast<LDServerSDKTrackSeriesContext>(const_cast<launchdarkly::server_side::hooks::TrackSeriesContext*>(ptr)))
2019

2120
#define AS_EVAL_DETAIL(ptr) \
2221
(reinterpret_cast<LDEvalDetail>( \
@@ -48,20 +47,17 @@ hooks::EvaluationSeriesData CHookWrapper::BeforeEvaluation(
4847
return data;
4948
}
5049

51-
// Create wrapper on stack - holds context reference + default value copy
52-
EvaluationSeriesContextWrapper wrapper(series_context);
53-
54-
// Convert to C types
50+
// Convert to C types - cast context directly
5551
const auto c_series_context =
56-
AS_EVAL_SERIES_CONTEXT_WRAPPER(&wrapper);
52+
AS_EVAL_SERIES_CONTEXT(&series_context);
5753

5854
// Create a heap-allocated copy of the data to pass to C callback
5955
// This gives the callback ownership that it can return or modify
6056
const auto c_data_input =
6157
reinterpret_cast<LDServerSDKEvaluationSeriesData>(
6258
new hooks::EvaluationSeriesData(data));
6359

64-
// Call the C callback - wrapper stays alive for entire call
60+
// Call the C callback - context stays alive for entire call
6561
LDServerSDKEvaluationSeriesData result_data =
6662
before_evaluation_(c_series_context, c_data_input, user_data_);
6763

@@ -95,12 +91,9 @@ hooks::EvaluationSeriesData CHookWrapper::AfterEvaluation(
9591
return data;
9692
}
9793

98-
// Create wrapper on stack - holds context reference + default value copy
99-
EvaluationSeriesContextWrapper wrapper(series_context);
100-
101-
// Convert to C types
94+
// Convert to C types - cast context directly
10295
const auto c_series_context =
103-
AS_EVAL_SERIES_CONTEXT_WRAPPER(&wrapper);
96+
AS_EVAL_SERIES_CONTEXT(&series_context);
10497

10598
// Create a heap-allocated copy of the data to pass to C callback
10699
// This gives the callback ownership that it can return or modify
@@ -110,7 +103,7 @@ hooks::EvaluationSeriesData CHookWrapper::AfterEvaluation(
110103

111104
const auto c_detail = AS_EVAL_DETAIL(&detail);
112105

113-
// Call the C callback - wrapper stays alive for entire call
106+
// Call the C callback - context stays alive for entire call
114107
LDServerSDKEvaluationSeriesData result_data =
115108
after_evaluation_(c_series_context, c_data_input, c_detail, user_data_);
116109

@@ -142,14 +135,11 @@ void CHookWrapper::AfterTrack(
142135
return;
143136
}
144137

145-
// Create wrapper on stack - holds context reference
146-
TrackSeriesContextWrapper wrapper(series_context);
147-
148-
// Convert to C type
138+
// Convert to C type - cast context directly
149139
const auto c_series_context =
150-
AS_TRACK_SERIES_CONTEXT_WRAPPER(&wrapper);
140+
AS_TRACK_SERIES_CONTEXT(&series_context);
151141

152-
// Call the C callback - wrapper stays alive for entire call
142+
// Call the C callback - context stays alive for entire call
153143
after_track_(c_series_context, user_data_);
154144
}
155145

libs/server-sdk/src/bindings/c/track_series_context.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include <launchdarkly/server_side/bindings/c/track_series_context.h>
2-
#include "context_wrappers.hpp"
2+
#include <launchdarkly/server_side/hooks/hook.hpp>
33

44
#include <launchdarkly/bindings/c/context.h>
55
#include <launchdarkly/bindings/c/value.h>
66
#include <launchdarkly/detail/c_binding_helpers.hpp>
77

8-
#define AS_WRAPPER(ptr) \
9-
(reinterpret_cast<launchdarkly::server_side::bindings::TrackSeriesContextWrapper const*>(ptr))
8+
#define AS_TRACK_SERIES_CONTEXT(ptr) \
9+
(reinterpret_cast<launchdarkly::server_side::hooks::TrackSeriesContext const*>(ptr))
1010

1111
#define AS_CONTEXT(ptr) \
1212
(reinterpret_cast<LDContext>(const_cast<launchdarkly::Context*>(ptr)))
@@ -20,13 +20,13 @@
2020
LD_EXPORT(char const*)
2121
LDTrackSeriesContext_Key(LDServerSDKTrackSeriesContext track_context) {
2222
LD_ASSERT(track_context != nullptr);
23-
return AS_WRAPPER(track_context)->context.Key().data();
23+
return AS_TRACK_SERIES_CONTEXT(track_context)->Key().data();
2424
}
2525

2626
LD_EXPORT(LDContext)
2727
LDTrackSeriesContext_Context(LDServerSDKTrackSeriesContext track_context) {
2828
LD_ASSERT(track_context != nullptr);
29-
return AS_CONTEXT(&AS_WRAPPER(track_context)->context.TrackContext());
29+
return AS_CONTEXT(&AS_TRACK_SERIES_CONTEXT(track_context)->TrackContext());
3030
}
3131

3232
LD_EXPORT(bool)
@@ -35,7 +35,7 @@ LDTrackSeriesContext_Data(LDServerSDKTrackSeriesContext track_context,
3535
LD_ASSERT(track_context != nullptr);
3636
LD_ASSERT(out_data != nullptr);
3737

38-
auto data = AS_WRAPPER(track_context)->context.Data();
38+
auto data = AS_TRACK_SERIES_CONTEXT(track_context)->Data();
3939
if (data.has_value()) {
4040
// Return a pointer to the existing value - no heap allocation needed
4141
*out_data = AS_VALUE(&data->get());
@@ -51,7 +51,7 @@ LDTrackSeriesContext_MetricValue(LDServerSDKTrackSeriesContext track_context,
5151
LD_ASSERT(track_context != nullptr);
5252
LD_ASSERT(out_metric_value != nullptr);
5353

54-
auto metric = AS_WRAPPER(track_context)->context.MetricValue();
54+
auto metric = AS_TRACK_SERIES_CONTEXT(track_context)->MetricValue();
5555
if (metric.has_value()) {
5656
*out_metric_value = *metric;
5757
return true;
@@ -62,12 +62,12 @@ LDTrackSeriesContext_MetricValue(LDServerSDKTrackSeriesContext track_context,
6262
LD_EXPORT(LDHookContext)
6363
LDTrackSeriesContext_HookContext(LDServerSDKTrackSeriesContext track_context) {
6464
LD_ASSERT(track_context != nullptr);
65-
return AS_HOOK_CONTEXT(&AS_WRAPPER(track_context)->context.HookCtx());
65+
return AS_HOOK_CONTEXT(&AS_TRACK_SERIES_CONTEXT(track_context)->HookCtx());
6666
}
6767

6868
LD_EXPORT(char const*)
6969
LDTrackSeriesContext_EnvironmentId(LDServerSDKTrackSeriesContext track_context) {
7070
LD_ASSERT(track_context != nullptr);
71-
auto env_id = AS_WRAPPER(track_context)->context.EnvironmentId();
71+
auto env_id = AS_TRACK_SERIES_CONTEXT(track_context)->EnvironmentId();
7272
return env_id.has_value() ? env_id->data() : nullptr;
7373
}

0 commit comments

Comments
 (0)