Skip to content

Commit 0ec1d05

Browse files
committed
Move STATIC_ASSERT_EXPR to utils.h
Static asserts are so useful we want to use them not only in our tests. Move STATIC_ASSERT_EXPR to utils.h, an internal header, to make it available to tests and the library implementation.
1 parent c8231c7 commit 0ec1d05

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

library/include/utils.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* \file utils.h
3+
*
4+
* \brief Mbed Crypto internal utilities
5+
*
6+
* This file contains the macros and functions useful for the development and
7+
* testing of Mbed Crypto.
8+
*
9+
*/
10+
/*
11+
* Copyright (C) 2018, ARM Limited, All Rights Reserved
12+
* SPDX-License-Identifier: Apache-2.0
13+
*
14+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
15+
* not use this file except in compliance with the License.
16+
* You may obtain a copy of the License at
17+
*
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
*
20+
* Unless required by applicable law or agreed to in writing, software
21+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
* See the License for the specific language governing permissions and
24+
* limitations under the License.
25+
*
26+
* This file is part of mbed TLS (https://tls.mbed.org)
27+
*/
28+
29+
#ifndef MC_UTILS_H
30+
#define MC_UTILS_H
31+
32+
/* A compile-time constant with the value 0. If `const_expr` is not a
33+
* compile-time constant with a nonzero value, cause a compile-time error. */
34+
#define STATIC_ASSERT_EXPR( const_expr ) \
35+
( 0 && sizeof( struct { int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) )
36+
37+
#endif /* MC_UTILS_H */

tests/suites/helpers.function

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "mbedtls/memory_buffer_alloc.h"
2424
#endif
2525

26+
#include "utils.h"
27+
2628
#ifdef _MSC_VER
2729
#include <basetsd.h>
2830
typedef UINT8 uint8_t;
@@ -180,10 +182,6 @@ typedef struct data_tag
180182
#define IS_ARRAY_NOT_POINTER( arg ) 1
181183
#endif
182184

183-
/* A compile-time constant with the value 0. If `const_expr` is not a
184-
* compile-time constant with a nonzero value, cause a compile-time error. */
185-
#define STATIC_ASSERT_EXPR( const_expr ) \
186-
( 0 && sizeof( struct { int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) )
187185
/* Return the scalar value `value` (possibly promoted). This is a compile-time
188186
* constant if `value` is. `condition` must be a compile-time constant.
189187
* If `condition` is false, arrange to cause a compile-time error. */

0 commit comments

Comments
 (0)