mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fixes for compiling mruby as C++
This commit is contained in:
committed by
Yukihiro "Matz" Matsumoto
parent
477e12c182
commit
1af9e363f2
@@ -28,10 +28,26 @@
|
||||
#ifndef MRUBY_H
|
||||
#define MRUBY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifndef SIZE_MAX
|
||||
#ifdef __SIZE_MAX__
|
||||
#define SIZE_MAX __SIZE_MAX__
|
||||
#else
|
||||
#define SIZE_MAX std::numeric_limits<size_t>::max()
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MRB_DEBUG
|
||||
#include <assert.h>
|
||||
#define mrb_assert(p) assert(p)
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef struct mrb_value {
|
||||
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
|
||||
|
||||
#define mrb_tt(o) ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1)
|
||||
#define mrb_type(o) ((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
|
||||
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
|
||||
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
|
||||
#define mrb_float(o) (o).f
|
||||
#define mrb_cptr(o) mrb_ptr(o)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
static mrb_value
|
||||
istruct_test_initialize(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
char *string = mrb_istruct_ptr(self);
|
||||
char *string = (char*)mrb_istruct_ptr(self);
|
||||
mrb_int size = mrb_istruct_size();
|
||||
mrb_value object;
|
||||
mrb_get_args(mrb, "o", &object);
|
||||
@@ -31,7 +31,7 @@ istruct_test_initialize(mrb_state *mrb, mrb_value self)
|
||||
static mrb_value
|
||||
istruct_test_to_s(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
return mrb_str_new_cstr(mrb, mrb_istruct_ptr(self));
|
||||
return mrb_str_new_cstr(mrb, (const char*)mrb_istruct_ptr(self));
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
@@ -63,7 +63,7 @@ istruct_test_test_receive_direct(mrb_state *mrb, mrb_value self)
|
||||
static mrb_value
|
||||
istruct_test_mutate(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
char *ptr = mrb_istruct_ptr(self);
|
||||
char *ptr = (char*)mrb_istruct_ptr(self);
|
||||
memcpy(ptr, "mutate", 6);
|
||||
return mrb_nil_value();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ static mrb_value
|
||||
os_count_objects(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
struct os_count_struct obj_count = { 0 };
|
||||
enum mrb_vtype i;
|
||||
mrb_int i;
|
||||
mrb_value hash;
|
||||
|
||||
if (mrb_get_args(mrb, "|H", &hash) == 0) {
|
||||
|
||||
@@ -844,13 +844,13 @@ retry:
|
||||
strncpy(nbuf, RSTRING_PTR(val), sizeof(nbuf));
|
||||
break;
|
||||
case 8:
|
||||
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRIo, v);
|
||||
snprintf(nbuf, sizeof(nbuf), "%" MRB_PRIo, v);
|
||||
break;
|
||||
case 10:
|
||||
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRId, v);
|
||||
snprintf(nbuf, sizeof(nbuf), "%" MRB_PRId, v);
|
||||
break;
|
||||
case 16:
|
||||
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRIx, v);
|
||||
snprintf(nbuf, sizeof(nbuf), "%" MRB_PRIx, v);
|
||||
break;
|
||||
}
|
||||
s = nbuf;
|
||||
@@ -865,13 +865,13 @@ retry:
|
||||
strncpy(++s, RSTRING_PTR(val), sizeof(nbuf)-1);
|
||||
break;
|
||||
case 8:
|
||||
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRIo, v);
|
||||
snprintf(++s, sizeof(nbuf)-1, "%" MRB_PRIo, v);
|
||||
break;
|
||||
case 10:
|
||||
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRId, v);
|
||||
snprintf(++s, sizeof(nbuf)-1, "%" MRB_PRId, v);
|
||||
break;
|
||||
case 16:
|
||||
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRIx, v);
|
||||
snprintf(++s, sizeof(nbuf)-1, "%" MRB_PRIx, v);
|
||||
break;
|
||||
}
|
||||
if (v < 0) {
|
||||
|
||||
+2
-2
@@ -160,7 +160,7 @@ static void
|
||||
output_backtrace_i(mrb_state *mrb, struct backtrace_location_raw *loc_raw, void *data)
|
||||
{
|
||||
struct backtrace_location loc;
|
||||
struct output_backtrace_args *args = data;
|
||||
struct output_backtrace_args *args = (struct output_backtrace_args *)data;
|
||||
|
||||
loc.i = loc_raw->i;
|
||||
loc.lineno = loc_raw->lineno;
|
||||
@@ -338,7 +338,7 @@ save_backtrace_i(mrb_state *mrb,
|
||||
else {
|
||||
new_n_allocated = mrb->backtrace.n_allocated * 2;
|
||||
}
|
||||
mrb->backtrace.entries =
|
||||
mrb->backtrace.entries = (mrb_backtrace_entry *)
|
||||
mrb_realloc(mrb,
|
||||
mrb->backtrace.entries,
|
||||
sizeof(mrb_backtrace_entry) * new_n_allocated);
|
||||
|
||||
+1
-1
@@ -361,7 +361,7 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n)
|
||||
return 0;
|
||||
}
|
||||
else if (m == 1) {
|
||||
const unsigned char *ys = memchr(y, *x, n);
|
||||
const unsigned char *ys = (const unsigned char *)memchr(y, *x, n);
|
||||
|
||||
if (ys)
|
||||
return ys - y;
|
||||
|
||||
Reference in New Issue
Block a user