Merge pull request #12035 from kjbracey-arm/callback_prep

Preparation for Callback changes
pull/12292/head^2
Anna Bridge 2020-01-21 11:50:43 +00:00 committed by GitHub
commit 80fe861f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 174 additions and 1165 deletions

View File

@ -695,12 +695,28 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
}
Case cases[] = {
#ifdef DO_BIG_TEST
Case("Testing callbacks with 0 uint64s", test_dispatch0<uint64_t>),
Case("Testing callbacks with 1 uint64s", test_dispatch1<uint64_t>),
Case("Testing callbacks with 2 uint64s", test_dispatch2<uint64_t>),
Case("Testing callbacks with 3 uint64s", test_dispatch3<uint64_t>),
Case("Testing callbacks with 4 uint64s", test_dispatch4<uint64_t>),
Case("Testing callbacks with 5 uint64s", test_dispatch5<uint64_t>),
#elif DO_SMALL_TEST
Case("Testing callbacks with 0 uchars", test_dispatch0<unsigned char>),
Case("Testing callbacks with 1 uchars", test_dispatch1<unsigned char>),
Case("Testing callbacks with 2 uchars", test_dispatch2<unsigned char>),
Case("Testing callbacks with 3 uchars", test_dispatch3<unsigned char>),
Case("Testing callbacks with 4 uchars", test_dispatch4<unsigned char>),
Case("Testing callbacks with 5 uchars", test_dispatch5<unsigned char>),
#else
Case("Testing callbacks with 0 ints", test_dispatch0<int>),
Case("Testing callbacks with 1 ints", test_dispatch1<int>),
Case("Testing callbacks with 2 ints", test_dispatch2<int>),
Case("Testing callbacks with 3 ints", test_dispatch3<int>),
Case("Testing callbacks with 4 ints", test_dispatch4<int>),
Case("Testing callbacks with 5 ints", test_dispatch5<int>),
#endif
};
Specification specification(test_setup, cases);

View File

@ -13,536 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
using namespace utest::v1;
// static functions
template <typename T>
T static_func0()
{
return 0;
}
template <typename T>
T static_func1(T a0)
{
return 0 | a0;
}
template <typename T>
T static_func2(T a0, T a1)
{
return 0 | a0 | a1;
}
template <typename T>
T static_func3(T a0, T a1, T a2)
{
return 0 | a0 | a1 | a2;
}
template <typename T>
T static_func4(T a0, T a1, T a2, T a3)
{
return 0 | a0 | a1 | a2 | a3;
}
template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4)
{
return 0 | a0 | a1 | a2 | a3 | a4;
}
// class functions
template <typename T>
struct Thing {
T t;
Thing() : t(0x80) {}
T member_func0()
{
return t;
}
T member_func1(T a0)
{
return t | a0;
}
T member_func2(T a0, T a1)
{
return t | a0 | a1;
}
T member_func3(T a0, T a1, T a2)
{
return t | a0 | a1 | a2;
}
T member_func4(T a0, T a1, T a2, T a3)
{
return t | a0 | a1 | a2 | a3;
}
T member_func5(T a0, T a1, T a2, T a3, T a4)
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_member_func0() const
{
return t;
}
T const_member_func1(T a0) const
{
return t | a0;
}
T const_member_func2(T a0, T a1) const
{
return t | a0 | a1;
}
T const_member_func3(T a0, T a1, T a2) const
{
return t | a0 | a1 | a2;
}
T const_member_func4(T a0, T a1, T a2, T a3) const
{
return t | a0 | a1 | a2 | a3;
}
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
{
return t | a0 | a1 | a2 | a3 | a4;
}
T volatile_member_func0() volatile
{
return t;
}
T volatile_member_func1(T a0) volatile
{
return t | a0;
}
T volatile_member_func2(T a0, T a1) volatile
{
return t | a0 | a1;
}
T volatile_member_func3(T a0, T a1, T a2) volatile
{
return t | a0 | a1 | a2;
}
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
{
return t | a0 | a1 | a2 | a3;
}
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_volatile_member_func0() const volatile
{
return t;
}
T const_volatile_member_func1(T a0) const volatile
{
return t | a0;
}
T const_volatile_member_func2(T a0, T a1) const volatile
{
return t | a0 | a1;
}
T const_volatile_member_func3(T a0, T a1, T a2) const volatile
{
return t | a0 | a1 | a2;
}
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
{
return t | a0 | a1 | a2 | a3;
}
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
};
// bound functions
template <typename T>
T bound_func0(Thing<T> *t)
{
return t->t;
}
template <typename T>
T bound_func1(Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const bound functions
template <typename T>
T const_func0(const Thing<T> *t)
{
return t->t;
}
template <typename T>
T const_func1(const Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T const_func2(const Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T const_func3(const Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// volatile bound functions
template <typename T>
T volatile_func0(volatile Thing<T> *t)
{
return t->t;
}
template <typename T>
T volatile_func1(volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T volatile_func2(volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const volatile bound functions
template <typename T>
T const_volatile_func0(const volatile Thing<T> *t)
{
return t->t;
}
template <typename T>
T const_volatile_func1(const volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// function call and result verification
template <typename T>
struct Verifier {
static void verify0(Callback<T()> func)
{
T result = func();
TEST_ASSERT_EQUAL(result, 0x00);
}
template <typename O, typename M>
static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method);
T result = func();
TEST_ASSERT_EQUAL(result, 0x80);
}
static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
}
template <typename O, typename M>
static void verify1(O *obj, M method)
{
Callback<T(T)> func(obj, method);
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
}
static void verify2(Callback<T(T, T)> func)
{
T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
}
template <typename O, typename M>
static void verify2(O *obj, M method)
{
Callback<T(T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
}
static void verify3(Callback<T(T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
}
template <typename O, typename M>
static void verify3(O *obj, M method)
{
Callback<T(T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
}
static void verify4(Callback<T(T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
template <typename O, typename M>
static void verify4(O *obj, M method)
{
Callback<T(T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
static void verify5(Callback<T(T, T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
template <typename O, typename M>
static void verify5(O *obj, M method)
{
Callback<T(T, T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
};
// test dispatch
template <typename T>
void test_dispatch0()
{
Thing<T> thing;
Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
Verifier<T>::verify0((const Thing<T> *)&thing, &Thing<T>::const_member_func0);
Verifier<T>::verify0((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func0);
Verifier<T>::verify0((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&bound_func0<T>, &thing);
Verifier<T>::verify0(&const_func0<T>, (const Thing<T> *)&thing);
Verifier<T>::verify0(&volatile_func0<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify0(&const_volatile_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(callback(static_func0<T>));
Callback<T()> cb(static_func0);
Verifier<T>::verify0(cb);
cb = static_func0;
Verifier<T>::verify0(cb);
cb = {&bound_func0<T>, &thing};
Verifier<T>::verify0(&cb, &Callback<T()>::call);
Verifier<T>::verify0(&Callback<T()>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch1()
{
Thing<T> thing;
Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
Verifier<T>::verify1((const Thing<T> *)&thing, &Thing<T>::const_member_func1);
Verifier<T>::verify1((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func1);
Verifier<T>::verify1((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&bound_func1<T>, &thing);
Verifier<T>::verify1(&const_func1<T>, (const Thing<T> *)&thing);
Verifier<T>::verify1(&volatile_func1<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify1(&const_volatile_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(callback(static_func1<T>));
Callback<T(T)> cb(static_func1);
Verifier<T>::verify1(cb);
cb = static_func1;
Verifier<T>::verify1(cb);
cb = {&bound_func1<T>, &thing};
Verifier<T>::verify1(&cb, &Callback<T(T)>::call);
Verifier<T>::verify1(&Callback<T(T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch2()
{
Thing<T> thing;
Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
Verifier<T>::verify2((const Thing<T> *)&thing, &Thing<T>::const_member_func2);
Verifier<T>::verify2((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func2);
Verifier<T>::verify2((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&bound_func2<T>, &thing);
Verifier<T>::verify2(&const_func2<T>, (const Thing<T> *)&thing);
Verifier<T>::verify2(&volatile_func2<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify2(&const_volatile_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(callback(static_func2<T>));
Callback<T(T, T)> cb(static_func2);
Verifier<T>::verify2(cb);
cb = static_func2;
Verifier<T>::verify2(cb);
cb = {&bound_func2<T>, &thing};
Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call);
Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch3()
{
Thing<T> thing;
Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
Verifier<T>::verify3((const Thing<T> *)&thing, &Thing<T>::const_member_func3);
Verifier<T>::verify3((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func3);
Verifier<T>::verify3((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&bound_func3<T>, &thing);
Verifier<T>::verify3(&const_func3<T>, (const Thing<T> *)&thing);
Verifier<T>::verify3(&volatile_func3<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify3(&const_volatile_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(callback(static_func3<T>));
Callback<T(T, T, T)> cb(static_func3);
Verifier<T>::verify3(cb);
cb = static_func3;
Verifier<T>::verify3(cb);
cb = {&bound_func3<T>, &thing};
Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call);
Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch4()
{
Thing<T> thing;
Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
Verifier<T>::verify4((const Thing<T> *)&thing, &Thing<T>::const_member_func4);
Verifier<T>::verify4((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func4);
Verifier<T>::verify4((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&bound_func4<T>, &thing);
Verifier<T>::verify4(&const_func4<T>, (const Thing<T> *)&thing);
Verifier<T>::verify4(&volatile_func4<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify4(&const_volatile_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(callback(static_func4<T>));
Callback<T(T, T, T, T)> cb(static_func4);
Verifier<T>::verify4(cb);
cb = static_func4;
Verifier<T>::verify4(cb);
cb = {&bound_func4<T>, &thing};
Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call);
Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch5()
{
Thing<T> thing;
Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
Verifier<T>::verify5((const Thing<T> *)&thing, &Thing<T>::const_member_func5);
Verifier<T>::verify5((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func5);
Verifier<T>::verify5((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&bound_func5<T>, &thing);
Verifier<T>::verify5(&const_func5<T>, (const Thing<T> *)&thing);
Verifier<T>::verify5(&volatile_func5<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify5(&const_volatile_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(callback(static_func5<T>));
Callback<T(T, T, T, T, T)> cb(static_func5);
Verifier<T>::verify5(cb);
cb = static_func5;
Verifier<T>::verify5(cb);
cb = {&bound_func5<T>, &thing};
Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call);
Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void *)&cb);
}
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case("Testing callbacks with 0 uint64s", test_dispatch0<uint64_t>),
Case("Testing callbacks with 1 uint64s", test_dispatch1<uint64_t>),
Case("Testing callbacks with 2 uint64s", test_dispatch2<uint64_t>),
Case("Testing callbacks with 3 uint64s", test_dispatch3<uint64_t>),
Case("Testing callbacks with 4 uint64s", test_dispatch4<uint64_t>),
Case("Testing callbacks with 5 uint64s", test_dispatch5<uint64_t>),
};
Specification specification(test_setup, cases);
int main()
{
return !Harness::run(specification);
}
#define DO_BIG_TEST 1
#include "../callback/main.cpp"

View File

@ -13,536 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
using namespace utest::v1;
// static functions
template <typename T>
T static_func0()
{
return 0;
}
template <typename T>
T static_func1(T a0)
{
return 0 | a0;
}
template <typename T>
T static_func2(T a0, T a1)
{
return 0 | a0 | a1;
}
template <typename T>
T static_func3(T a0, T a1, T a2)
{
return 0 | a0 | a1 | a2;
}
template <typename T>
T static_func4(T a0, T a1, T a2, T a3)
{
return 0 | a0 | a1 | a2 | a3;
}
template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4)
{
return 0 | a0 | a1 | a2 | a3 | a4;
}
// class functions
template <typename T>
struct Thing {
T t;
Thing() : t(0x80) {}
T member_func0()
{
return t;
}
T member_func1(T a0)
{
return t | a0;
}
T member_func2(T a0, T a1)
{
return t | a0 | a1;
}
T member_func3(T a0, T a1, T a2)
{
return t | a0 | a1 | a2;
}
T member_func4(T a0, T a1, T a2, T a3)
{
return t | a0 | a1 | a2 | a3;
}
T member_func5(T a0, T a1, T a2, T a3, T a4)
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_member_func0() const
{
return t;
}
T const_member_func1(T a0) const
{
return t | a0;
}
T const_member_func2(T a0, T a1) const
{
return t | a0 | a1;
}
T const_member_func3(T a0, T a1, T a2) const
{
return t | a0 | a1 | a2;
}
T const_member_func4(T a0, T a1, T a2, T a3) const
{
return t | a0 | a1 | a2 | a3;
}
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
{
return t | a0 | a1 | a2 | a3 | a4;
}
T volatile_member_func0() volatile
{
return t;
}
T volatile_member_func1(T a0) volatile
{
return t | a0;
}
T volatile_member_func2(T a0, T a1) volatile
{
return t | a0 | a1;
}
T volatile_member_func3(T a0, T a1, T a2) volatile
{
return t | a0 | a1 | a2;
}
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
{
return t | a0 | a1 | a2 | a3;
}
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_volatile_member_func0() const volatile
{
return t;
}
T const_volatile_member_func1(T a0) const volatile
{
return t | a0;
}
T const_volatile_member_func2(T a0, T a1) const volatile
{
return t | a0 | a1;
}
T const_volatile_member_func3(T a0, T a1, T a2) const volatile
{
return t | a0 | a1 | a2;
}
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
{
return t | a0 | a1 | a2 | a3;
}
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
};
// bound functions
template <typename T>
T bound_func0(Thing<T> *t)
{
return t->t;
}
template <typename T>
T bound_func1(Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const bound functions
template <typename T>
T const_func0(const Thing<T> *t)
{
return t->t;
}
template <typename T>
T const_func1(const Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T const_func2(const Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T const_func3(const Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// volatile bound functions
template <typename T>
T volatile_func0(volatile Thing<T> *t)
{
return t->t;
}
template <typename T>
T volatile_func1(volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T volatile_func2(volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const volatile bound functions
template <typename T>
T const_volatile_func0(const volatile Thing<T> *t)
{
return t->t;
}
template <typename T>
T const_volatile_func1(const volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T>
T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T>
T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T>
T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T>
T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// function call and result verification
template <typename T>
struct Verifier {
static void verify0(Callback<T()> func)
{
T result = func();
TEST_ASSERT_EQUAL(result, 0x00);
}
template <typename O, typename M>
static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method);
T result = func();
TEST_ASSERT_EQUAL(result, 0x80);
}
static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
}
template <typename O, typename M>
static void verify1(O *obj, M method)
{
Callback<T(T)> func(obj, method);
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
}
static void verify2(Callback<T(T, T)> func)
{
T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
}
template <typename O, typename M>
static void verify2(O *obj, M method)
{
Callback<T(T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
}
static void verify3(Callback<T(T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
}
template <typename O, typename M>
static void verify3(O *obj, M method)
{
Callback<T(T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
}
static void verify4(Callback<T(T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
template <typename O, typename M>
static void verify4(O *obj, M method)
{
Callback<T(T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
static void verify5(Callback<T(T, T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
template <typename O, typename M>
static void verify5(O *obj, M method)
{
Callback<T(T, T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
};
// test dispatch
template <typename T>
void test_dispatch0()
{
Thing<T> thing;
Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
Verifier<T>::verify0((const Thing<T> *)&thing, &Thing<T>::const_member_func0);
Verifier<T>::verify0((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func0);
Verifier<T>::verify0((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&bound_func0<T>, &thing);
Verifier<T>::verify0(&const_func0<T>, (const Thing<T> *)&thing);
Verifier<T>::verify0(&volatile_func0<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify0(&const_volatile_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(callback(static_func0<T>));
Callback<T()> cb(static_func0);
Verifier<T>::verify0(cb);
cb = static_func0;
Verifier<T>::verify0(cb);
cb = {&bound_func0<T>, &thing};
Verifier<T>::verify0(&cb, &Callback<T()>::call);
Verifier<T>::verify0(&Callback<T()>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch1()
{
Thing<T> thing;
Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
Verifier<T>::verify1((const Thing<T> *)&thing, &Thing<T>::const_member_func1);
Verifier<T>::verify1((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func1);
Verifier<T>::verify1((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&bound_func1<T>, &thing);
Verifier<T>::verify1(&const_func1<T>, (const Thing<T> *)&thing);
Verifier<T>::verify1(&volatile_func1<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify1(&const_volatile_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(callback(static_func1<T>));
Callback<T(T)> cb(static_func1);
Verifier<T>::verify1(cb);
cb = static_func1;
Verifier<T>::verify1(cb);
cb = {&bound_func1<T>, &thing};
Verifier<T>::verify1(&cb, &Callback<T(T)>::call);
Verifier<T>::verify1(&Callback<T(T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch2()
{
Thing<T> thing;
Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
Verifier<T>::verify2((const Thing<T> *)&thing, &Thing<T>::const_member_func2);
Verifier<T>::verify2((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func2);
Verifier<T>::verify2((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&bound_func2<T>, &thing);
Verifier<T>::verify2(&const_func2<T>, (const Thing<T> *)&thing);
Verifier<T>::verify2(&volatile_func2<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify2(&const_volatile_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(callback(static_func2<T>));
Callback<T(T, T)> cb(static_func2);
Verifier<T>::verify2(cb);
cb = static_func2;
Verifier<T>::verify2(cb);
cb = {&bound_func2<T>, &thing};
Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call);
Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch3()
{
Thing<T> thing;
Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
Verifier<T>::verify3((const Thing<T> *)&thing, &Thing<T>::const_member_func3);
Verifier<T>::verify3((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func3);
Verifier<T>::verify3((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&bound_func3<T>, &thing);
Verifier<T>::verify3(&const_func3<T>, (const Thing<T> *)&thing);
Verifier<T>::verify3(&volatile_func3<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify3(&const_volatile_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(callback(static_func3<T>));
Callback<T(T, T, T)> cb(static_func3);
Verifier<T>::verify3(cb);
cb = static_func3;
Verifier<T>::verify3(cb);
cb = {&bound_func3<T>, &thing};
Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call);
Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch4()
{
Thing<T> thing;
Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
Verifier<T>::verify4((const Thing<T> *)&thing, &Thing<T>::const_member_func4);
Verifier<T>::verify4((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func4);
Verifier<T>::verify4((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&bound_func4<T>, &thing);
Verifier<T>::verify4(&const_func4<T>, (const Thing<T> *)&thing);
Verifier<T>::verify4(&volatile_func4<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify4(&const_volatile_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(callback(static_func4<T>));
Callback<T(T, T, T, T)> cb(static_func4);
Verifier<T>::verify4(cb);
cb = static_func4;
Verifier<T>::verify4(cb);
cb = {&bound_func4<T>, &thing};
Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call);
Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void *)&cb);
}
template <typename T>
void test_dispatch5()
{
Thing<T> thing;
Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
Verifier<T>::verify5((const Thing<T> *)&thing, &Thing<T>::const_member_func5);
Verifier<T>::verify5((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func5);
Verifier<T>::verify5((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&bound_func5<T>, &thing);
Verifier<T>::verify5(&const_func5<T>, (const Thing<T> *)&thing);
Verifier<T>::verify5(&volatile_func5<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify5(&const_volatile_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(callback(static_func5<T>));
Callback<T(T, T, T, T, T)> cb(static_func5);
Verifier<T>::verify5(cb);
cb = static_func5;
Verifier<T>::verify5(cb);
cb = {&bound_func5<T>, &thing};
Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call);
Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void *)&cb);
}
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case("Testing callbacks with 0 uchars", test_dispatch0<unsigned char>),
Case("Testing callbacks with 1 uchars", test_dispatch1<unsigned char>),
Case("Testing callbacks with 2 uchars", test_dispatch2<unsigned char>),
Case("Testing callbacks with 3 uchars", test_dispatch3<unsigned char>),
Case("Testing callbacks with 4 uchars", test_dispatch4<unsigned char>),
Case("Testing callbacks with 5 uchars", test_dispatch5<unsigned char>),
};
Specification specification(test_setup, cases);
int main()
{
return !Harness::run(specification);
}
#define DO_SMALL_TEST 1
#include "../callback/main.cpp"

View File

@ -524,7 +524,7 @@ static void rf_if_reset_radio(void)
#else
rf->spi.frequency(MBED_CONF_ATMEL_RF_LOW_SPI_SPEED);
#endif
rf->IRQ.rise(0);
rf->IRQ.rise(nullptr);
rf->RST = 1;
ThisThread::sleep_for(2);
rf->RST = 0;

View File

@ -41,7 +41,7 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
: _sdk_v(-1, -1, -1),
_at_v(-1, -1, -1),
_tcp_passive(false),
_callback(0),
_callback(),
_serial(tx, rx, MBED_CONF_ESP8266_SERIAL_BAUDRATE),
_serial_rts(rts),
_serial_cts(cts),

View File

@ -71,7 +71,7 @@ ESP8266Interface::ESP8266Interface()
_connect_retval(NSAPI_ERROR_OK),
_disconnect_retval(NSAPI_ERROR_OK),
_conn_stat(NSAPI_STATUS_DISCONNECTED),
_conn_stat_cb(NULL),
_conn_stat_cb(),
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
_oob_event_id(0),
_connect_event_id(0),
@ -113,7 +113,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
_connect_retval(NSAPI_ERROR_OK),
_disconnect_retval(NSAPI_ERROR_OK),
_conn_stat(NSAPI_STATUS_DISCONNECTED),
_conn_stat_cb(NULL),
_conn_stat_cb(),
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
_oob_event_id(0),
_connect_event_id(0),

View File

@ -216,7 +216,7 @@ public:
/** Begin asynchronous write using 8bit buffer.
*
* The write operation ends with any of the enabled events and invokes
* registered callback function (which can be NULL to not receive callback at all).
* registered callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_write() when
* no events are enabled.
@ -233,7 +233,7 @@ public:
/** Begin asynchronous write using 16bit buffer.
*
* The write operation ends with any of the enabled events and invokes
* registered callback function (which can be NULL to not receive callback at all).
* registered callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_write() when
* no events are enabled.
@ -256,7 +256,7 @@ public:
/** Begin asynchronous reading using 8bit buffer.
*
* The read operation ends with any of the enabled events and invokes registered
* callback function (which can be NULL to not receive callback at all).
* callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_read() when
* no events are enabled.
@ -274,7 +274,7 @@ public:
/** Begin asynchronous reading using 16bit buffer.
*
* The read operation ends with any of the enabled events and invokes registered
* callback function (which can be NULL to not receive callback at all).
* callback function (which can be empty to not receive callback at all).
* Events that are not enabled by event argument are simply ignored.
* Operation has to be ended explicitly by calling abort_read() when
* no events are enabled.

View File

@ -42,7 +42,7 @@ public:
*
* @param cb Callback called when dispatch needs to be called
*/
PolledQueue(mbed::Callback<void()> cb = NULL);
PolledQueue(mbed::Callback<void()> cb = nullptr);
virtual ~PolledQueue();

View File

@ -147,7 +147,7 @@ public:
* @param callback Method pointer to be called when a packet is transferred
* @returns true if successful, false otherwise
*/
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback<void()> callback = NULL);
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback<void()> callback = nullptr);
/**
* Add an endpoint

View File

@ -56,7 +56,7 @@ CAN::~CAN()
// Detaching interrupts releases the sleep lock if it was locked
for (int irq = 0; irq < IrqCnt; irq++) {
attach(NULL, (IrqType)irq);
attach(nullptr, (IrqType)irq);
}
can_irq_free(&_can);
can_free(&_can);
@ -147,7 +147,7 @@ void CAN::attach(Callback<void()> func, IrqType type)
if (_irq[(CanIrqType)type]) {
sleep_manager_unlock_deep_sleep();
}
_irq[(CanIrqType)type] = NULL;
_irq[(CanIrqType)type] = nullptr;
can_irq_set(&_can, (CanIrqType)type, 0);
}
unlock();

View File

@ -26,8 +26,8 @@ namespace mbed {
// constructor, with a default value for the PinMode.
InterruptIn::InterruptIn(PinName pin) : gpio(),
gpio_irq(),
_rise(NULL),
_fall(NULL)
_rise(),
_fall()
{
// No lock needed in the constructor
irq_init(pin);
@ -37,8 +37,8 @@ InterruptIn::InterruptIn(PinName pin) : gpio(),
InterruptIn::InterruptIn(PinName pin, PinMode mode) :
gpio(),
gpio_irq(),
_rise(NULL),
_fall(NULL)
_rise(),
_fall()
{
// No lock needed in the constructor
irq_init(pin);
@ -76,7 +76,7 @@ void InterruptIn::rise(Callback<void()> func)
_rise = func;
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
} else {
_rise = NULL;
_rise = nullptr;
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
}
core_util_critical_section_exit();
@ -89,7 +89,7 @@ void InterruptIn::fall(Callback<void()> func)
_fall = func;
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
} else {
_fall = NULL;
_fall = nullptr;
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
}
core_util_critical_section_exit();

View File

@ -151,14 +151,14 @@ SPI::~SPI()
lock();
/* Make sure a stale pointer isn't left in peripheral's owner field */
if (_peripheral->owner == this) {
_peripheral->owner = NULL;
_peripheral->owner = nullptr;
}
unlock();
}
SPI::spi_peripheral_s *SPI::_lookup(SPI::SPIName name)
{
SPI::spi_peripheral_s *result = NULL;
SPI::spi_peripheral_s *result = nullptr;
core_util_critical_section_enter();
for (int idx = 0; idx < _peripherals_used; idx++) {
if (_peripherals[idx].name == name) {

View File

@ -28,11 +28,11 @@ Serial::Serial(const serial_pinmap_t &static_pinmap, const char *name, int baud)
{
}
Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream(NULL)
Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream()
{
}
Serial::Serial(const serial_pinmap_t &static_pinmap, int baud): SerialBase(static_pinmap, baud), Stream(NULL)
Serial::Serial(const serial_pinmap_t &static_pinmap, int baud): SerialBase(static_pinmap, baud), Stream()
{
}

View File

@ -34,21 +34,13 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
{
// No lock needed in the constructor
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
_irq[i] = NULL;
}
(this->*_init_func)();
}
SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
#if DEVICE_SERIAL_ASYNCH
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
_rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL),
_rx_callback(NULL), _tx_asynch_set(false),
_rx_asynch_set(false),
_thunk_irq(this),
#endif
_serial(),
_baud(baud),
_tx_pin(static_pinmap.tx_pin),
_rx_pin(static_pinmap.rx_pin),
@ -57,10 +49,6 @@ SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
{
// No lock needed in the constructor
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
_irq[i] = NULL;
}
(this->*_init_func)();
}
@ -118,7 +106,7 @@ void SerialBase::attach(Callback<void()> func, IrqType type)
if (_irq[type]) {
sleep_manager_unlock_deep_sleep();
}
_irq[type] = NULL;
_irq[type] = nullptr;
serial_irq_set(&_serial, (SerialIrq)type, 0);
}
core_util_critical_section_exit();
@ -187,7 +175,7 @@ void SerialBase::enable_input(bool enable)
core_util_critical_section_enter();
if (enable) {
// Enable rx IRQ and lock deep sleep if a rx handler is attached
// (indicated by rx IRQ callback not NULL)
// (indicated by rx IRQ callback not empty)
if (_irq[RxIrq]) {
_irq[RxIrq].call();
sleep_manager_lock_deep_sleep();
@ -197,7 +185,7 @@ void SerialBase::enable_input(bool enable)
// Disable rx IRQ
serial_irq_set(&_serial, (SerialIrq)RxIrq, 0);
// Unlock deep sleep if a rx handler is attached
// (indicated by rx IRQ callback not NULL)
// (indicated by rx IRQ callback not empty)
if (_irq[RxIrq]) {
sleep_manager_unlock_deep_sleep();
}
@ -224,7 +212,7 @@ void SerialBase::enable_output(bool enable)
core_util_critical_section_enter();
if (enable) {
// Enable tx IRQ and lock deep sleep if a tx handler is attached
// (indicated by tx IRQ callback not NULL)
// (indicated by tx IRQ callback not empty)
if (_irq[TxIrq]) {
_irq[TxIrq].call();
sleep_manager_lock_deep_sleep();
@ -234,7 +222,7 @@ void SerialBase::enable_output(bool enable)
// Disable tx IRQ
serial_irq_set(&_serial, (SerialIrq)TxIrq, 0);
// Unlock deep sleep if a tx handler is attached
// (indicated by tx IRQ callback not NULL)
// (indicated by tx IRQ callback not empty)
if (_irq[TxIrq]) {
sleep_manager_unlock_deep_sleep();
}
@ -297,7 +285,7 @@ SerialBase::~SerialBase()
// Detaching interrupts releases the sleep lock if it was locked
for (int irq = 0; irq < IrqCnt; irq++) {
attach(NULL, (IrqType)irq);
attach(nullptr, (IrqType)irq);
}
}
@ -389,7 +377,7 @@ void SerialBase::abort_write(void)
lock();
core_util_critical_section_enter();
if (_tx_asynch_set) {
_tx_callback = NULL;
_tx_callback = nullptr;
_tx_asynch_set = false;
serial_tx_abort_asynch(&_serial);
sleep_manager_unlock_deep_sleep();
@ -403,7 +391,7 @@ void SerialBase::abort_read(void)
lock();
core_util_critical_section_enter();
if (_rx_asynch_set) {
_rx_callback = NULL;
_rx_callback = nullptr;
_rx_asynch_set = false;
serial_rx_abort_asynch(&_serial);
sleep_manager_unlock_deep_sleep();
@ -475,7 +463,7 @@ void SerialBase::interrupt_handler_asynch(void)
if (_rx_asynch_set && rx_event) {
event_callback_t cb = _rx_callback;
_rx_asynch_set = false;
_rx_callback = NULL;
_rx_callback = nullptr;
if (cb) {
cb.call(rx_event);
}
@ -486,7 +474,7 @@ void SerialBase::interrupt_handler_asynch(void)
if (_tx_asynch_set && tx_event) {
event_callback_t cb = _tx_callback;
_tx_asynch_set = false;
_tx_callback = NULL;
_tx_callback = nullptr;
if (cb) {
cb.call(tx_event);
}

View File

@ -23,12 +23,12 @@
namespace mbed {
Ticker::Ticker() : TimerEvent(), _delay(0), _function(0), _lock_deepsleep(true)
Ticker::Ticker() : TimerEvent(), _delay(0), _lock_deepsleep(true)
{
}
// When low power ticker is in use, then do not disable deep sleep.
Ticker::Ticker(const ticker_data_t *data) : TimerEvent(data), _delay(0), _function(0), _lock_deepsleep(!data->interface->runs_in_deep_sleep)
Ticker::Ticker(const ticker_data_t *data) : TimerEvent(data), _delay(0), _lock_deepsleep(!data->interface->runs_in_deep_sleep)
{
}

View File

@ -67,7 +67,7 @@ void UARTSerial::set_baud(int baud)
void UARTSerial::set_data_carrier_detect(PinName dcd_pin, bool active_high)
{
delete _dcd_irq;
_dcd_irq = NULL;
_dcd_irq = nullptr;
if (dcd_pin != NC) {
_dcd_irq = new InterruptIn(dcd_pin);
@ -361,7 +361,7 @@ void UARTSerial::enable_rx_irq()
void UARTSerial::disable_rx_irq()
{
SerialBase::attach(NULL, RxIrq);
SerialBase::attach(nullptr, RxIrq);
_rx_irq_enabled = false;
}
@ -373,7 +373,7 @@ void UARTSerial::enable_tx_irq()
void UARTSerial::disable_tx_irq()
{
SerialBase::attach(NULL, TxIrq);
SerialBase::attach(nullptr, TxIrq);
_tx_irq_enabled = false;
}

View File

@ -85,9 +85,9 @@ void AsyncOp::complete()
core_util_critical_section_enter();
mbed::Callback<void()> cb = _callback;
_callback = NULL;
_list = NULL;
if (_wait != NULL) {
_callback = nullptr;
_list = nullptr;
if (_wait != nullptr) {
_wait->release();
}
@ -115,11 +115,11 @@ void AsyncOp::_abort(bool timeout)
core_util_critical_section_enter();
OperationListBase *list = _list;
if (list) {
_callback = NULL;
_callback = nullptr;
_aborted = true;
_wait = NULL;
_wait = nullptr;
_timeout = timeout;
_list = NULL;
_list = nullptr;
}
core_util_critical_section_exit();
if (list) {

View File

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "stdint.h"
#include <stdint.h>
#include <string.h>
#include "USBAudio.h"
#include "USBAudio_Types.h"
#include "EndpointResolver.h"

View File

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "stdint.h"
#include <stdint.h>
#include <string.h>
#include "USBCDC.h"
#include "EndpointResolver.h"
#include "AsyncOp.h"

View File

@ -1177,7 +1177,7 @@ void USBDevice::endpoint_remove(usb_ep_t endpoint)
_phy->endpoint_abort(endpoint);
}
info->callback = NULL;
info->callback = nullptr;
info->flags = 0;
info->pending = 0;
info->max_packet_size = 0;

View File

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "stdint.h"
#include <stdint.h>
#include <string.h>
#include "USBHID.h"
#include "EndpointResolver.h"
#include "usb_phy_api.h"

View File

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "stdint.h"
#include <stdint.h>
#include <string.h>
#include "USBMIDI.h"
#include "EndpointResolver.h"
#include "usb_phy_api.h"

View File

@ -17,6 +17,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "USBMSD.h"
#include "EndpointResolver.h"
#include "usb_phy_api.h"

View File

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "stdint.h"
#include <stdint.h>
#include <string.h>
#include "USBMouse.h"
#include "ThisThread.h"
#include "usb_phy_api.h"

View File

@ -53,10 +53,10 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
AT_CellularDevice::~AT_CellularDevice()
{
if (get_property(PROPERTY_AT_CGEREP)) {
_at->set_urc_handler("+CGEV: NW DEACT", 0);
_at->set_urc_handler("+CGEV: ME DEACT", 0);
_at->set_urc_handler("+CGEV: NW PDN D", 0);
_at->set_urc_handler("+CGEV: ME PDN D", 0);
_at->set_urc_handler("+CGEV: NW DEACT", nullptr);
_at->set_urc_handler("+CGEV: ME DEACT", nullptr);
_at->set_urc_handler("+CGEV: NW PDN D", nullptr);
_at->set_urc_handler("+CGEV: ME PDN D", nullptr);
}
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up.

View File

@ -72,7 +72,7 @@ static const char *const rat_str[AT_CellularNetwork::RAT_MAX] = {
AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler, AT_CellularDevice &device) :
_connection_status_cb(NULL), _ciotopt_network_support_cb(NULL), _op_act(RAT_UNKNOWN),
_connection_status_cb(), _ciotopt_network_support_cb(), _op_act(RAT_UNKNOWN),
_connect_status(NSAPI_STATUS_DISCONNECTED), _supported_network_opt(CIOT_OPT_MAX),
_at(atHandler), _device(device)
{
@ -101,15 +101,15 @@ AT_CellularNetwork::~AT_CellularNetwork()
(void)set_packet_domain_event_reporting(false);
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
if (_device.get_property((AT_CellularDevice::CellularProperty)type) != RegistrationModeDisable) {
_at.set_urc_handler(at_reg[type].urc_prefix, 0);
_at.set_urc_handler(at_reg[type].urc_prefix, nullptr);
}
}
if (_device.get_property(AT_CellularDevice::PROPERTY_AT_CGEREP)) {
_at.set_urc_handler("+CGEV: ME DET", 0);
_at.set_urc_handler("+CGEV: NW DET", 0);
_at.set_urc_handler("+CGEV: ME DET", nullptr);
_at.set_urc_handler("+CGEV: NW DET", nullptr);
}
_at.set_urc_handler("+CCIOTOPTI:", 0);
_at.set_urc_handler("+CCIOTOPTI:", nullptr);
}
void AT_CellularNetwork::urc_cgev()

View File

@ -177,7 +177,7 @@ static const unsigned char gsm_to_ascii[] = {
const int GSM_TO_ASCII_TABLE_SIZE = sizeof(gsm_to_ascii) / sizeof(gsm_to_ascii[0]);
AT_CellularSMS::AT_CellularSMS(ATHandler &at, AT_CellularDevice &device) : _cb(0), _mode(CellularSMSMmodeText),
AT_CellularSMS::AT_CellularSMS(ATHandler &at, AT_CellularDevice &device) : _cb(), _mode(CellularSMSMmodeText),
_use_8bit_encoding(false), _sim_wait_time(0), _sms_message_ref_number(1),
_sms_info(NULL), _at(at), _device(device)
{

View File

@ -291,7 +291,7 @@ void ATHandler::set_is_filehandle_usable(bool usable)
_fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
} else {
_fileHandle->set_blocking(true); // set back to default state
_fileHandle->sigio(NULL);
_fileHandle->sigio(nullptr);
}
_is_fh_usable = usable;
}

View File

@ -59,12 +59,11 @@ MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance()
}
CellularContext::CellularContext() : _next(0), _stack(0), _pdp_type(DEFAULT_PDP_TYPE),
_authentication_type(CellularContext::CHAP), _connect_status(NSAPI_STATUS_DISCONNECTED), _status_cb(0),
_authentication_type(CellularContext::CHAP), _connect_status(NSAPI_STATUS_DISCONNECTED), _status_cb(),
_cid(-1), _new_context_set(false), _is_context_active(false), _is_context_activated(false),
_apn(0), _uname(0), _pwd(0), _dcd_pin(NC), _active_high(false), _cp_netif(0), _retry_array_length(0),
_retry_count(0), _device(0), _nw(0), _is_blocking(true), _nonip_req(false), _cp_in_use(false)
_apn(0), _uname(0), _pwd(0), _dcd_pin(NC), _active_high(false), _cp_netif(0), _retry_timeout_array(),
_retry_array_length(0), _retry_count(0), _device(0), _nw(0), _is_blocking(true), _nonip_req(false), _cp_in_use(false)
{
memset(_retry_timeout_array, 0, sizeof(_retry_timeout_array));
}
void CellularContext::cp_data_received()

View File

@ -40,7 +40,7 @@ CellularDevice::CellularDevice(FileHandle *fh) :
_sms_ref_count(0),
#endif //MBED_CONF_CELLULAR_USE_SMS
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0),
_status_cb(0), _nw(0)
_status_cb(), _nw(0)
#ifdef MBED_CONF_RTOS_PRESENT
, _queue_thread(osPriorityNormal, 2048, NULL, "cellular_queue")
#endif // MBED_CONF_RTOS_PRESENT

View File

@ -50,7 +50,7 @@ namespace mbed {
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue, CellularNetwork &nw) :
_cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state),
_event_status_cb(0), _network(nw), _queue(queue), _sim_pin(0), _retry_count(0),
_event_status_cb(), _network(nw), _queue(queue), _sim_pin(0), _retry_count(0),
_event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false),
_is_retry(false), _cb_data(), _current_event(CellularDeviceReady), _status(0)
{
@ -345,7 +345,7 @@ bool CellularStateMachine::device_ready()
#endif // MBED_CONF_CELLULAR_DEBUG_AT
send_event_cb(CellularDeviceReady);
_cellularDevice.set_ready_cb(0);
_cellularDevice.set_ready_cb(nullptr);
return true;
}

View File

@ -34,9 +34,9 @@ GEMALTO_CINTERION_CellularStack::GEMALTO_CINTERION_CellularStack(ATHandler &atHa
GEMALTO_CINTERION_CellularStack::~GEMALTO_CINTERION_CellularStack()
{
_at.set_urc_handler("^SIS:", 0);
_at.set_urc_handler("^SISW:", 0);
_at.set_urc_handler("^SISR:", 0);
_at.set_urc_handler("^SIS:", nullptr);
_at.set_urc_handler("^SISW:", nullptr);
_at.set_urc_handler("^SISR:", nullptr);
}
void GEMALTO_CINTERION_CellularStack::urc_sis()

View File

@ -48,8 +48,8 @@ QUECTEL_BC95_CellularStack::~QUECTEL_BC95_CellularStack()
_event_queue->cancel(_txfull_event_id);
}
_at.set_urc_handler("+NSONMI:", NULL);
_at.set_urc_handler("+NSOCLI:", NULL);
_at.set_urc_handler("+NSONMI:", nullptr);
_at.set_urc_handler("+NSOCLI:", nullptr);
}
nsapi_error_t QUECTEL_BC95_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)

View File

@ -39,7 +39,7 @@ QUECTEL_BG96_CellularContext::QUECTEL_BG96_CellularContext(ATHandler &at, Cellul
QUECTEL_BG96_CellularContext::~QUECTEL_BG96_CellularContext()
{
if (_nonip_req) {
_at.set_urc_handler("+QIND:", 0);
_at.set_urc_handler("+QIND:", nullptr);
}
}

View File

@ -39,14 +39,14 @@ QUECTEL_M26_CellularStack::QUECTEL_M26_CellularStack(ATHandler &atHandler, int c
QUECTEL_M26_CellularStack::~QUECTEL_M26_CellularStack()
{
_at.set_urc_handler("5, CLOSED", NULL);
_at.set_urc_handler("4, CLOSED", NULL);
_at.set_urc_handler("3, CLOSED", NULL);
_at.set_urc_handler("2, CLOSED", NULL);
_at.set_urc_handler("1, CLOSED", NULL);
_at.set_urc_handler("0, CLOSED", NULL);
_at.set_urc_handler("5, CLOSED", nullptr);
_at.set_urc_handler("4, CLOSED", nullptr);
_at.set_urc_handler("3, CLOSED", nullptr);
_at.set_urc_handler("2, CLOSED", nullptr);
_at.set_urc_handler("1, CLOSED", nullptr);
_at.set_urc_handler("0, CLOSED", nullptr);
_at.set_urc_handler("+QIRDI:", NULL);
_at.set_urc_handler("+QIRDI:", nullptr);
}
nsapi_error_t QUECTEL_M26_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)

View File

@ -56,7 +56,7 @@ void UBLOX_N2XX::set_at_urcs_impl()
UBLOX_N2XX::~UBLOX_N2XX()
{
_at->set_urc_handler("+NPIN:", NULL);
_at->set_urc_handler("+NPIN:", nullptr);
}
// Callback for Sim Pin.

View File

@ -31,7 +31,7 @@ UBLOX_N2XX_CellularStack::UBLOX_N2XX_CellularStack(ATHandler &atHandler, int cid
UBLOX_N2XX_CellularStack::~UBLOX_N2XX_CellularStack()
{
_at.set_urc_handler("+NSONMI:", NULL);
_at.set_urc_handler("+NSONMI:", nullptr);
}
nsapi_error_t UBLOX_N2XX_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)

View File

@ -22,6 +22,7 @@ Copyright (c) 2017, Arm Limited and affiliates.
SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdlib.h>
#include <string.h>
#include "LoRaMac.h"
#include "mbed-trace/mbed_trace.h"

View File

@ -22,6 +22,7 @@ Copyright (c) 2017, Arm Limited and affiliates.
SPDX-License-Identifier: BSD-3-Clause
*/
#include <string.h>
#include "LoRaMacCommand.h"
#include "LoRaMac.h"

View File

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "LoRaMacCrypto.h"
#include "system/lorawan_data_structures.h"

View File

@ -29,6 +29,7 @@
*
*/
#include <string.h>
#include "LoRaPHYAU915.h"
#include "lora_phy_ds.h"

View File

@ -29,6 +29,7 @@
*
*/
#include <string.h>
#include "LoRaPHYUS915.h"
#include "lora_phy_ds.h"

View File

@ -47,7 +47,7 @@ nsapi_error_t nsapi_ppp_set_blocking(bool blocking);
*
* @return 0 on success, negative error code on failure
*/
nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t, intptr_t)> status_cb = 0, const char *uname = 0, const char *pwd = 0, const nsapi_ip_stack_t stack = DEFAULT_STACK);
nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t, intptr_t)> status_cb = nullptr, const char *uname = 0, const char *pwd = 0, const nsapi_ip_stack_t stack = DEFAULT_STACK);
/** Close a PPP connection
*

View File

@ -93,7 +93,7 @@ public:
Deferred &operator=(const Deferred &);
public:
Deferred(T t, Callback<void(T)> ondefer = NULL)
Deferred(T t, Callback<void(T)> ondefer = nullptr)
: _t(t), _ondefer(ondefer)
{
}

View File

@ -44,9 +44,9 @@ namespace mbed {
* // Increase reference count
* SharedPtr<MyStruct> ptr2( ptr );
*
* ptr = NULL; // Reference to the struct instance is still held by ptr2
* ptr = nullptr; // Reference to the struct instance is still held by ptr2
*
* ptr2 = NULL; // The raw pointer is freed
* ptr2 = nullptr; // The raw pointer is freed
* }
* @endcode
*

View File

@ -0,0 +1,56 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_NEW_
#define MSTD_NEW_
/* <mstd_new>
*
* - includes toolchain's <new>
* - For all toolchains, C++17 backports:
* - mstd::launder
*/
#include <new>
#if __cpp_lib_launder < 201606
#include <type_traits>
#endif
namespace mstd
{
using std::nothrow_t;
using std::nothrow;
using std::new_handler;
using std::set_new_handler;
#if __cpp_lib_launder >= 201606
using std::launder;
#else
template <typename T>
constexpr T *launder(T *p) noexcept
{
static_assert(!std::is_function<T>::value && !std::is_void<T>::value, "Can only launder complete object types");
#if defined __clang__ || __GNUC__ >= 9
return __builtin_launder(p);
#else
return p;
#endif
}
#endif
} // namespace mstd
#endif // MSTD_NEW_

View File

@ -19,6 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <string.h>
#include "rtos/Thread.h"
#include "rtos/ThisThread.h"
#include "rtos_idle.h"