Skip to content

Commit dd92557

Browse files
committed
Sort compiler macros around
1 parent 40bf7bd commit dd92557

2 files changed

Lines changed: 92 additions & 31 deletions

File tree

include/mruby.h

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
/**
4141
* @file mruby.h
42-
* @brief Main header of mruby C API. Include this first.
4342
* @defgroup mruby MRuby C API
4443
* @{
4544
*/
@@ -57,11 +56,13 @@ struct mrb_irep;
5756
struct mrb_state;
5857

5958
/**
60-
* Function pointer type of custom allocator used in mrb_open_allocf.
59+
* Function pointer type of custom allocator used in @ref mrb_open_allocf.
6160
*
6261
* The function pointing it must behave similarly as realloc except:
6362
* - If ptr is NULL it must allocate new space.
6463
* - If s is NULL, ptr must be freed.
64+
*
65+
* See @ref mrb_default_allocf for the default implementation.
6566
*/
6667
typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
6768

@@ -205,18 +206,6 @@ typedef struct mrb_state {
205206
mrb_int atexit_stack_len;
206207
} mrb_state;
207208

208-
#if __STDC_VERSION__ >= 201112L
209-
# define mrb_noreturn _Noreturn
210-
#elif defined __GNUC__ && !defined __STRICT_ANSI__
211-
# define mrb_noreturn __attribute__((noreturn))
212-
# define mrb_deprecated __attribute__((deprecated))
213-
#elif defined _MSC_VER
214-
# define mrb_noreturn __declspec(noreturn)
215-
# define mrb_deprecated __declspec(deprecated)
216-
#else
217-
# define mrb_noreturn
218-
# define mrb_deprecated
219-
#endif
220209

221210
typedef mrb_value (*mrb_func_t)(mrb_state *mrb, mrb_value);
222211

@@ -278,8 +267,29 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*,
278267
MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value);
279268
MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
280269
MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
270+
271+
/**
272+
* Initialize a new object instace of c class.
273+
*
274+
* @param mrb
275+
* The current mruby state.
276+
* @param c
277+
* Reference to the class of the new object.
278+
* @param argc
279+
* Number of arguments in argv
280+
* @param argv
281+
* Array of @ref mrb_value "mrb_values" to initialize the object
282+
* @returns
283+
* The newly initialized object
284+
*/
281285
MRB_API mrb_value mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv);
282-
#define mrb_class_new_instance(mrb,argc,argv,c) mrb_obj_new(mrb,c,argc,argv)
286+
287+
/** See @ref mrb_obj_new */
288+
MRB_INLINE mrb_value mrb_class_new_instance(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv)
289+
{
290+
return mrb_obj_new(mrb,c,argc,argv);
291+
}
292+
283293
MRB_API mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
284294
MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
285295
MRB_API struct RClass * mrb_module_new(mrb_state *mrb);
@@ -464,19 +474,32 @@ char* mrb_locale_from_utf8(const char *p, size_t len);
464474
*/
465475
MRB_API mrb_state* mrb_open(void);
466476

467-
468477
/**
469-
* Create new mrb_state with custom allocator.
478+
* Create new mrb_state with custom allocators.
470479
*
480+
* @param f
481+
* Reference to the allocation function.
471482
* @param ud
472-
* will be passed to custom allocator f. If user data isn't required just
473-
* pass NULL. Function pointer f must satisfy requirements of its type.
483+
* User data will be passed to custom allocator f.
484+
* If user data isn't required just pass NULL.
485+
* @returns
486+
* Pointer to the newly created mrb_state.
487+
*/
488+
MRB_API mrb_state* mrb_open_allocf(mrb_allocf f, void *ud);
489+
490+
/**
491+
* Create new mrb_state with just the MRuby core
474492
*
493+
* @param f
494+
* Reference to the allocation function.
495+
* Use mrb_default_allocf for the default
496+
* @param ud
497+
* User data will be passed to custom allocator f.
498+
* If user data isn't required just pass NULL.
475499
* @returns
476500
* Pointer to the newly created mrb_state.
477501
*/
478-
MRB_API mrb_state* mrb_open_allocf(mrb_allocf, void *ud);
479-
MRB_API mrb_state* mrb_open_core(mrb_allocf, void *ud);
502+
MRB_API mrb_state* mrb_open_core(mrb_allocf f, void *ud);
480503

481504
/**
482505
* Closes and frees a mrb_state.
@@ -486,6 +509,11 @@ MRB_API mrb_state* mrb_open_core(mrb_allocf, void *ud);
486509
*/
487510
MRB_API void mrb_close(mrb_state *mrb);
488511

512+
/**
513+
* The default allocation function.
514+
*
515+
* @ref mrb_allocf
516+
*/
489517
MRB_API void* mrb_default_allocf(mrb_state*, void*, size_t, void*);
490518

491519
MRB_API mrb_value mrb_top_self(mrb_state *);

include/mruby/common.h

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,62 @@
77
#ifndef MRUBY_COMMON_H
88
#define MRUBY_COMMON_H
99

10+
/**
11+
* @file mruby/common.h
12+
* @defgroup mruby_common Shared compiler macros
13+
* @ingroup mruby
14+
* @{
15+
*/
16+
1017
#ifdef __cplusplus
11-
/** Start declarations in C++ mode */
12-
#define MRB_BEGIN_DECL extern "C" {
13-
/** End declarations in C++ mode */
14-
#define MRB_END_DECL }
18+
# define MRB_BEGIN_DECL extern "C" {
19+
# define MRB_END_DECL }
1520
#else
1621
/** Start declarations in C mode */
17-
#define MRB_BEGIN_DECL /* empty */
22+
# define MRB_BEGIN_DECL
1823
/** End declarations in C mode */
19-
#define MRB_END_DECL /* empty */
24+
# define MRB_END_DECL
25+
#endif
26+
27+
/** Declare a function that never returns. */
28+
#if __STDC_VERSION__ >= 201112L
29+
# define mrb_noreturn _Noreturn
30+
#elif defined __GNUC__ && !defined __STRICT_ANSI__
31+
# define mrb_noreturn __attribute__((noreturn))
32+
#elif defined _MSC_VER
33+
# define mrb_noreturn __declspec(noreturn)
34+
#else
35+
# define mrb_noreturn
36+
#endif
37+
38+
/** Mark a function as deprecated. */
39+
#if defined __GNUC__ && !defined __STRICT_ANSI__
40+
# define mrb_deprecated __attribute__((deprecated))
41+
#elif defined _MSC_VER
42+
# define mrb_deprecated __declspec(deprecated)
43+
#else
44+
# define mrb_deprecated
45+
#endif
46+
47+
/** Declare a function as always inlined. */
48+
#if defined(_MSC_VER)
49+
# define MRB_INLINE static __inline
50+
#else
51+
# define MRB_INLINE static inline
2052
#endif
2153

2254

55+
/** Declare a public MRuby API function. */
2356
#if defined(MRB_BUILD_AS_DLL)
2457
#if defined(MRB_CORE) || defined(MRB_LIB)
25-
#define MRB_API __declspec(dllexport)
58+
# define MRB_API __declspec(dllexport)
2659
#else
27-
#define MRB_API __declspec(dllimport)
60+
# define MRB_API __declspec(dllimport)
2861
#endif
2962
#else
30-
#define MRB_API extern
63+
# define MRB_API extern
3164
#endif
3265

33-
MRB_END_DECL
66+
/** @} */
3467

3568
#endif /* MRUBY_COMMON_H */

0 commit comments

Comments
 (0)