forked from Snaipe/Mimick
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Drop conflicting type aliasing. * Force C linkage if compiling for C++. * Cast explicitly and deal with C99 features. * Handle array arguments properly. * Avoid brace initializers for scalars. * Force C++11. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
- Loading branch information
Showing
20 changed files
with
375 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
!.cmake/* | ||
|
||
!*.c | ||
!*.cpp | ||
!*.h | ||
!*.S | ||
!*.asm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
#ifndef MMK_ALLOC_H_ | ||
# define MMK_ALLOC_H_ | ||
|
||
# ifdef __cplusplus | ||
extern "C" { | ||
# endif | ||
|
||
void *mmk_malloc(size_t size); | ||
void *mmk_realloc(void *ptr, size_t size); | ||
void mmk_free(void *ptr); | ||
|
||
# ifdef __cplusplus | ||
} | ||
# endif | ||
|
||
#endif /* !MMK_ALLOC_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright © 2016 Franklin "Snaipe" Mathieu <http://snai.pe/> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
#ifndef MMK_LITERAL_H_ | ||
# define MMK_LITERAL_H_ | ||
|
||
# undef mmk_struct_literal | ||
|
||
# ifdef __cplusplus | ||
|
||
# include <cstdarg> | ||
# include <utility> | ||
|
||
# include "preprocess.h" | ||
|
||
template<typename T, int ID> | ||
struct mmk_literal { | ||
static constexpr int id = ID; | ||
static T storage; | ||
}; | ||
|
||
template<typename T, int ID> | ||
T mmk_literal<T, ID>::storage{0}; | ||
|
||
template <typename T> | ||
T & mmk_assign(T & dst, T src) { | ||
return dst = std::move(src); | ||
} | ||
|
||
template <typename T, size_t N> | ||
T (& mmk_assign(T (&dst)[N], T * src))[N] { | ||
if (src) { | ||
mmk_memcpy(dst, src, sizeof(T) * N); | ||
} else { | ||
mmk_memset(dst, 0, sizeof(T) * N); | ||
} | ||
return dst; | ||
} | ||
|
||
va_list & mmk_assign(va_list & dst, va_list src) { | ||
// no-op | ||
return dst; | ||
} | ||
|
||
# define MMK_COMMA_APPEND(_, prefix, content) (void) (prefix content), | ||
|
||
# define mmk_struct_initialize(variable, ...) \ | ||
(MMK_EXPAND(MMK_APPLY_N_(MMK_COMMA_APPEND, MMK_VA_NARGS(__VA_ARGS__), variable, __VA_ARGS__)) \ | ||
variable) | ||
|
||
# define mmk_struct_literal(type, ...) \ | ||
mmk_struct_initialize((mmk_literal<type, __COUNTER__>::storage), __VA_ARGS__) | ||
|
||
# define mmk_literal(type, value) \ | ||
(mmk_assign(mmk_literal<type, __COUNTER__>::storage, (type) value)) | ||
|
||
# define mmk_default_value(type) type{0} | ||
|
||
# else /* !defined __cplusplus */ | ||
|
||
# define mmk_assign(dst, src) (dst) = (src) | ||
|
||
# define mmk_literal(type, value) ((type) value) | ||
|
||
# define mmk_struct_literal(type, ...) ((type) { __VA_ARGS__ }) | ||
|
||
# define mmk_default_value(type) {0} | ||
|
||
# endif | ||
|
||
#endif /* !MMK_LITERAL_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.