Skip to content

Commit 0e6d702

Browse files
committed
all test cases passing now.
1 parent ab87b86 commit 0e6d702

File tree

5 files changed

+82
-63
lines changed

5 files changed

+82
-63
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ if(cToStr) { // Function materialized?
2222
*No includes. No compile-time linking. No argument type-casting. No guesswork.*
2323
*Just run-time lookup and type-safe invocation*.
2424

25-
### ⚡ Performance!
25+
### ⚡ Performance
2626

2727
Overhead? Practically none. **RTL**’s reflective calls — when return and argument types are known — are just a native function-pointer hop, often faster than `std::function`.
2828

2929
Yes — `rtl::function` is faster than `std::function`.
3030

3131
Microbenchmarks show reflective invocations through `rtl::function` have lower call overhead — a single, native pointer jump with no extra indirection.
32-
Once the functions start doing real work, both perform identically — always, under all conditions.
32+
Once the functions start doing real work, both perform identically.
3333

3434
### 💡 In One Line
3535

RTLTestRunApp/src/FunctionalityTests/PerfectForwardingTests.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,11 @@ namespace rtl_tests
321321
const auto& isValid = updateZooKeeper->hasSignature<const std::string&>();
322322
EXPECT_TRUE(isValid);
323323

324-
const auto zookeeper = std::string(animal::ZOO_KEEPER);
325-
auto [err, ret] = updateZooKeeper->bind<const std::string&>()(zookeeper);
324+
rtl::static_method<rtl::Return(std::string)> updateZooKeeperMth = updateZooKeeper.value()
325+
.argsT<std::string>()
326+
.returnT<>();
327+
328+
auto [err, ret] = updateZooKeeperMth.bind<const std::string&>()(animal::ZOO_KEEPER);
326329

327330
EXPECT_TRUE(err == error::None);
328331
ASSERT_FALSE(ret.isEmpty());
@@ -349,8 +352,10 @@ namespace rtl_tests
349352
const auto& isValid = updateZooKeeper->hasSignature<const std::string&>();
350353
EXPECT_TRUE(isValid);
351354

352-
auto zookeeper = std::string(animal::ZOO_KEEPER);
353-
auto [err, ret] = updateZooKeeper->bind<std::string&>()(zookeeper);
355+
rtl::static_method<rtl::Return(std::string)> updateZooKeeperMth = updateZooKeeper.value()
356+
.argsT<std::string>()
357+
.returnT<>();
358+
auto [err, ret] = updateZooKeeperMth.bind<std::string&>()(animal::ZOO_KEEPER);
354359

355360
EXPECT_TRUE(err == error::None);
356361
ASSERT_FALSE(ret.isEmpty());

RTLTestRunApp/src/FunctionalityTests/StaticMethodTests.cpp

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,30 @@ namespace rtl_tests
112112
optional<Record> classPerson = cxx::mirror().getRecord(person::class_);
113113
ASSERT_TRUE(classPerson);
114114

115-
optional<Method> getDefaults = classPerson->getMethod(person::str_getDefaults);
116-
ASSERT_TRUE(getDefaults);
117-
EXPECT_TRUE(getDefaults->hasSignature<>()); //empty template params checks for zero arguments.
115+
optional<Method> getDefaultsOpt = classPerson->getMethod(person::str_getDefaults);
116+
ASSERT_TRUE(getDefaultsOpt);
117+
EXPECT_TRUE(getDefaultsOpt->hasSignature<>()); //empty template params checks for zero arguments.
118+
{
119+
rtl::method<rtl::RObject, rtl::Return()> getDefaults = getDefaultsOpt.value().targetT().argsT().returnT();
118120

119-
auto [err0, person] = classPerson->create<alloc::Heap>();
121+
EXPECT_FALSE(getDefaults);
122+
EXPECT_EQ(getDefaults.get_init_error(), error::InvalidStaticMethodCaller);
120123

121-
EXPECT_TRUE(err0 == error::None);
122-
ASSERT_FALSE(person.isEmpty());
123-
{
124-
auto [err, ret] = getDefaults->bind(person).call();
125-
EXPECT_TRUE(err == error::None);
126-
ASSERT_FALSE(ret.isEmpty());
127-
EXPECT_TRUE(ret.canViewAs<string>());
124+
auto [err0, person] = classPerson->create<alloc::Heap>();
128125

129-
auto& retStr = ret.view<string>()->get();
130-
EXPECT_EQ(retStr, person::get_str_returned_on_call_getDefaults());
126+
EXPECT_EQ(err0, error::None);
127+
ASSERT_FALSE(person.isEmpty());
128+
129+
auto [err, ret] = getDefaults(person)();
130+
131+
EXPECT_EQ(err, error::InvalidStaticMethodCaller);
132+
EXPECT_TRUE(ret.isEmpty());
131133
} {
132-
auto [err, ret] = getDefaults->bind(person).call();
133-
EXPECT_TRUE(err == error::None);
134+
rtl::static_method<rtl::Return()> getDefaults = getDefaultsOpt.value().argsT().returnT();
135+
136+
auto [err, ret] = getDefaults();
137+
138+
EXPECT_EQ(err, error::None);
134139
ASSERT_FALSE(ret.isEmpty());
135140
EXPECT_TRUE(ret.canViewAs<string>());
136141

@@ -145,38 +150,39 @@ namespace rtl_tests
145150
optional<Record> classPerson = cxx::mirror().getRecord(person::class_);
146151
ASSERT_TRUE(classPerson);
147152

148-
auto [err0, person] = classPerson->create<alloc::Heap>();
153+
optional<Method> getProfileOpt = classPerson->getMethod(person::str_getProfile);
154+
ASSERT_TRUE(getProfileOpt);
155+
EXPECT_TRUE((getProfileOpt->hasSignature<string, size_t>()));
149156

150-
EXPECT_TRUE(err0 == error::None);
151-
ASSERT_FALSE(person.isEmpty());
152-
153-
optional<Method> getProfile = classPerson->getMethod(person::str_getProfile);
154-
ASSERT_TRUE(getProfile);
155-
EXPECT_TRUE((getProfile->hasSignature<string, size_t>()));
156-
157-
size_t age = person::AGE;
158-
string occupation = person::OCCUPATION;
159157
{
160-
auto [err, ret] = getProfile->bind(person).call(occupation, age);
158+
rtl::method<rtl::RObject, rtl::Return(std::string, std::size_t)> getProfile = getProfileOpt.value()
159+
.targetT()
160+
.argsT<std::string, std::size_t>()
161+
.returnT();
162+
EXPECT_FALSE(getProfile);
163+
EXPECT_EQ(getProfile.get_init_error(), error::InvalidStaticMethodCaller);
161164

162-
EXPECT_TRUE(err == error::None);
163-
ASSERT_FALSE(ret.isEmpty());
164-
EXPECT_TRUE(ret.canViewAs<string>());
165+
auto [err0, person] = classPerson->create<alloc::Heap>();
165166

166-
const string& retStr = ret.view<string>()->get();
167-
const string& checkStr = person::get_str_returned_on_call_getProfile<string, size_t>();
167+
EXPECT_EQ(err0, error::None);
168+
ASSERT_FALSE(person.isEmpty());
168169

169-
EXPECT_EQ(retStr, checkStr);
170+
auto [err, ret] = getProfile(person)(person::OCCUPATION, person::AGE);
171+
172+
EXPECT_EQ(err, error::InvalidStaticMethodCaller);
173+
ASSERT_TRUE(ret.isEmpty());
170174
} {
171-
auto [err, ret] = getProfile->bind(person).call(occupation, age);
175+
rtl::static_method<rtl::Return(std::string, std::size_t)> getProfile = getProfileOpt.value()
176+
.argsT<std::string, std::size_t>()
177+
.returnT();
178+
auto [err, ret] = getProfile(person::OCCUPATION, person::AGE);
172179

173-
EXPECT_TRUE(err == error::None);
180+
EXPECT_EQ(err, error::None);
174181
ASSERT_FALSE(ret.isEmpty());
175182
EXPECT_TRUE(ret.canViewAs<string>());
176183

177184
const string& retStr = ret.view<string>()->get();
178185
const string& checkStr = person::get_str_returned_on_call_getProfile<string, size_t>();
179-
180186
EXPECT_EQ(retStr, checkStr);
181187
}
182188
}

RTLTestRunApp/src/FunctionalityTests/StaticTypeReflectiveCalls/StrictStaticTypeDispatch_StaticMethod.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,34 @@ namespace rtl_tests
201201
EXPECT_EQ(ret_str, exp_str);
202202
}
203203
}
204+
205+
206+
TEST(StrictStaticTypeRtl_static_method, ptr_and_const_ptr_overload_resolution_with_known_signatures)
207+
{
208+
std::optional<rtl::Record> optStringUtil = cxx::mirror().getRecord(StringS::struct_);
209+
ASSERT_TRUE(optStringUtil);
210+
211+
std::string str = STRA;
212+
std::optional<rtl::Method> reverseString = optStringUtil->getMethod(str_reverseString);
213+
ASSERT_TRUE(reverseString);
214+
{
215+
rtl::static_method<std::string(std::string*)> reverse_string = reverseString.value()
216+
.argsT<std::string*>()
217+
.returnT<std::string>();
218+
ASSERT_TRUE(reverse_string);
219+
220+
std::string ret_str = reverse_string(&str);
221+
auto exp_str = std::string(STRA_REVERSE) + SUFFIX_std_string_ptr + SUFFIX_static;
222+
EXPECT_EQ(ret_str, exp_str);
223+
} {
224+
rtl::static_method<std::string(const std::string*)> reverse_string = reverseString.value()
225+
.argsT<const std::string*>()
226+
.returnT<std::string>();
227+
ASSERT_TRUE(reverse_string);
228+
229+
std::string ret_str = reverse_string(&str);
230+
auto exp_str = std::string(STRA_REVERSE) + SUFFIX_std_string_cptr + SUFFIX_static;
231+
EXPECT_EQ(ret_str, exp_str);
232+
}
233+
}
204234
}

RTLTestRunApp/src/MyReflectionTests/MyReflectionTests.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,6 @@ namespace
176176
std::optional<rtl::view<std::string>> strView = ret.view<std::string>();
177177
ASSERT_TRUE(strView);
178178

179-
const std::string& retStr = strView->get();
180-
// Confirms the expected static function was invoked.
181-
EXPECT_EQ(retStr, expectReturnStr);
182-
} {
183-
// Now create a `Person` object and reflect it into RTL.
184-
rtl::RObject robj = rtl::reflect(Person(""));
185-
186-
// Even if we bind a target object before calling the static function,
187-
// it has no effect — the call remains valid and succeeds.
188-
// This matches C++ native semantics: binding an instance is irrelevant
189-
// for static member functions.
190-
auto [err, ret] = getDefaults->bind(robj).call();
191-
192-
// Validate reflective call succeeded.
193-
EXPECT_TRUE(err == rtl::error::None);
194-
EXPECT_FALSE(ret.isEmpty());
195-
196-
// Verify return type and extract result.
197-
EXPECT_TRUE(ret.canViewAs<std::string>());
198-
std::optional<rtl::view<std::string>> strView = ret.view<std::string>();
199-
ASSERT_TRUE(strView);
200-
201179
const std::string& retStr = strView->get();
202180
// Confirms the expected static function was invoked.
203181
EXPECT_EQ(retStr, expectReturnStr);

0 commit comments

Comments
 (0)