Skip to content

Commit 1af9e36

Browse files
dabrozmatz
authored andcommitted
Fixes for compiling mruby as C++
1 parent 477e12c commit 1af9e36

File tree

7 files changed

+30
-14
lines changed

7 files changed

+30
-14
lines changed

include/mruby.h

+16
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,26 @@
2828
#ifndef MRUBY_H
2929
#define MRUBY_H
3030

31+
#ifdef __cplusplus
32+
#define __STDC_LIMIT_MACROS
33+
#define __STDC_CONSTANT_MACROS
34+
#define __STDC_FORMAT_MACROS
35+
#endif
36+
3137
#include <stdint.h>
3238
#include <stddef.h>
3339
#include <limits.h>
3440

41+
#ifdef __cplusplus
42+
#ifndef SIZE_MAX
43+
#ifdef __SIZE_MAX__
44+
#define SIZE_MAX __SIZE_MAX__
45+
#else
46+
#define SIZE_MAX std::numeric_limits<size_t>::max()
47+
#endif
48+
#endif
49+
#endif
50+
3551
#ifdef MRB_DEBUG
3652
#include <assert.h>
3753
#define mrb_assert(p) assert(p)

include/mruby/boxing_nan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef struct mrb_value {
5353
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
5454

5555
#define mrb_tt(o) ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1)
56-
#define mrb_type(o) ((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
56+
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
5757
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
5858
#define mrb_float(o) (o).f
5959
#define mrb_cptr(o) mrb_ptr(o)

mrbgems/mruby-inline-struct/test/inline.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
static mrb_value
77
istruct_test_initialize(mrb_state *mrb, mrb_value self)
88
{
9-
char *string = mrb_istruct_ptr(self);
9+
char *string = (char*)mrb_istruct_ptr(self);
1010
mrb_int size = mrb_istruct_size();
1111
mrb_value object;
1212
mrb_get_args(mrb, "o", &object);
@@ -31,7 +31,7 @@ istruct_test_initialize(mrb_state *mrb, mrb_value self)
3131
static mrb_value
3232
istruct_test_to_s(mrb_state *mrb, mrb_value self)
3333
{
34-
return mrb_str_new_cstr(mrb, mrb_istruct_ptr(self));
34+
return mrb_str_new_cstr(mrb, (const char*)mrb_istruct_ptr(self));
3535
}
3636

3737
static mrb_value
@@ -63,7 +63,7 @@ istruct_test_test_receive_direct(mrb_state *mrb, mrb_value self)
6363
static mrb_value
6464
istruct_test_mutate(mrb_state *mrb, mrb_value self)
6565
{
66-
char *ptr = mrb_istruct_ptr(self);
66+
char *ptr = (char*)mrb_istruct_ptr(self);
6767
memcpy(ptr, "mutate", 6);
6868
return mrb_nil_value();
6969
}

mrbgems/mruby-objectspace/src/mruby_objectspace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static mrb_value
4949
os_count_objects(mrb_state *mrb, mrb_value self)
5050
{
5151
struct os_count_struct obj_count = { 0 };
52-
enum mrb_vtype i;
52+
mrb_int i;
5353
mrb_value hash;
5454

5555
if (mrb_get_args(mrb, "|H", &hash) == 0) {

mrbgems/mruby-sprintf/src/sprintf.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -844,13 +844,13 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
844844
strncpy(nbuf, RSTRING_PTR(val), sizeof(nbuf));
845845
break;
846846
case 8:
847-
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRIo, v);
847+
snprintf(nbuf, sizeof(nbuf), "%" MRB_PRIo, v);
848848
break;
849849
case 10:
850-
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRId, v);
850+
snprintf(nbuf, sizeof(nbuf), "%" MRB_PRId, v);
851851
break;
852852
case 16:
853-
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRIx, v);
853+
snprintf(nbuf, sizeof(nbuf), "%" MRB_PRIx, v);
854854
break;
855855
}
856856
s = nbuf;
@@ -865,13 +865,13 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
865865
strncpy(++s, RSTRING_PTR(val), sizeof(nbuf)-1);
866866
break;
867867
case 8:
868-
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRIo, v);
868+
snprintf(++s, sizeof(nbuf)-1, "%" MRB_PRIo, v);
869869
break;
870870
case 10:
871-
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRId, v);
871+
snprintf(++s, sizeof(nbuf)-1, "%" MRB_PRId, v);
872872
break;
873873
case 16:
874-
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRIx, v);
874+
snprintf(++s, sizeof(nbuf)-1, "%" MRB_PRIx, v);
875875
break;
876876
}
877877
if (v < 0) {

src/backtrace.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static void
160160
output_backtrace_i(mrb_state *mrb, struct backtrace_location_raw *loc_raw, void *data)
161161
{
162162
struct backtrace_location loc;
163-
struct output_backtrace_args *args = data;
163+
struct output_backtrace_args *args = (struct output_backtrace_args *)data;
164164

165165
loc.i = loc_raw->i;
166166
loc.lineno = loc_raw->lineno;
@@ -338,7 +338,7 @@ save_backtrace_i(mrb_state *mrb,
338338
else {
339339
new_n_allocated = mrb->backtrace.n_allocated * 2;
340340
}
341-
mrb->backtrace.entries =
341+
mrb->backtrace.entries = (mrb_backtrace_entry *)
342342
mrb_realloc(mrb,
343343
mrb->backtrace.entries,
344344
sizeof(mrb_backtrace_entry) * new_n_allocated);

src/string.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n)
361361
return 0;
362362
}
363363
else if (m == 1) {
364-
const unsigned char *ys = memchr(y, *x, n);
364+
const unsigned char *ys = (const unsigned char *)memchr(y, *x, n);
365365

366366
if (ys)
367367
return ys - y;

0 commit comments

Comments
 (0)