Skip to content
Permalink
Browse files
renamed "inline" to "istruct" to represent inline struct; ref #3251
  • Loading branch information
matz committed Nov 17, 2016
1 parent 4cca8ba commit 8438792d27bac2a236d5eef9824d36f815c0472f
Showing 8 changed files with 77 additions and 77 deletions.

This file was deleted.

@@ -0,0 +1,47 @@
/*
** mruby/instruct.h - Inline structures
**
** See Copyright Notice in mruby.h
*/

#ifndef MRUBY_ISTRUCT_H
#define MRUBY_ISTRUCT_H

#include "common.h"
#include <string.h>

/**
* Inline structures that fit in RVALUE
*
* They cannot have finalizer, and cannot have instance variables.
*/
MRB_BEGIN_DECL

#define ISTRUCT_DATA_SIZE (sizeof(void*) * 3)

struct RIstruct {
MRB_OBJECT_HEADER;
char inline_data[ISTRUCT_DATA_SIZE];
};

#define RISTRUCT(obj) ((struct RIstruct*)(mrb_ptr(obj)))
#define ISTRUCT_PTR(obj) (RISTRUCT(obj)->inline_data)

MRB_INLINE mrb_int mrb_istruct_size()
{
return ISTRUCT_DATA_SIZE;
}

MRB_INLINE void* mrb_istruct_ptr(mrb_value object)
{
return ISTRUCT_PTR(object);
}

MRB_INLINE void mrb_istruct_copy(mrb_value dest, mrb_value src)
{
memcpy(ISTRUCT_PTR(dest), ISTRUCT_PTR(src), ISTRUCT_DATA_SIZE);
}

MRB_END_DECL

#endif /* MRUBY_ISTRUCT_H */
@@ -116,7 +116,7 @@ enum mrb_vtype {
MRB_TT_ENV, /* 20 */
MRB_TT_DATA, /* 21 */
MRB_TT_FIBER, /* 22 */
MRB_TT_INLINE, /* 23 */
MRB_TT_ISTRUCT, /* 23 */
MRB_TT_MAXDEFINE /* 24 */
};

@@ -1,13 +1,13 @@
#include <mruby.h>
#include <mruby/class.h>
#include <mruby/string.h>
#include <mruby/inline.h>
#include <mruby/istruct.h>

static mrb_value
inline_test_initialize(mrb_state *mrb, mrb_value self)
istruct_test_initialize(mrb_state *mrb, mrb_value self)
{
char *string = mrb_inline_ptr(self);
mrb_int size = mrb_inline_size();
char *string = mrb_istruct_ptr(self);
mrb_int size = mrb_istruct_size();
mrb_value object;
mrb_get_args(mrb, "o", &object);

@@ -29,41 +29,41 @@ inline_test_initialize(mrb_state *mrb, mrb_value self)
}

static mrb_value
inline_test_to_s(mrb_state *mrb, mrb_value self)
istruct_test_to_s(mrb_state *mrb, mrb_value self)
{
return mrb_str_new_cstr(mrb, mrb_inline_ptr(self));
return mrb_str_new_cstr(mrb, mrb_istruct_ptr(self));
}

static mrb_value
inline_test_length(mrb_state *mrb, mrb_value self)
istruct_test_length(mrb_state *mrb, mrb_value self)
{
return mrb_fixnum_value(mrb_inline_size());
return mrb_fixnum_value(mrb_istruct_size());
}

static mrb_value
inline_test_test_receive(mrb_state *mrb, mrb_value self)
istruct_test_test_receive(mrb_state *mrb, mrb_value self)
{
mrb_value object;
mrb_get_args(mrb, "o", &object);
if (mrb_obj_class(mrb, object) != mrb_class_get(mrb, "InlineStructTest"))
{
mrb_raisef(mrb, E_TYPE_ERROR, "Expected InlineStructTest");
}
return mrb_bool_value(((char*)mrb_inline_ptr(object))[0] == 's');
return mrb_bool_value(((char*)mrb_istruct_ptr(object))[0] == 's');
}

static mrb_value
inline_test_test_receive_direct(mrb_state *mrb, mrb_value self)
istruct_test_test_receive_direct(mrb_state *mrb, mrb_value self)
{
char *ptr;
mrb_get_args(mrb, "I", &ptr);
return mrb_bool_value(ptr[0] == 's');
}

static mrb_value
inline_test_mutate(mrb_state *mrb, mrb_value self)
istruct_test_mutate(mrb_state *mrb, mrb_value self)
{
char *ptr = mrb_inline_ptr(self);
char *ptr = mrb_istruct_ptr(self);
memcpy(ptr, "mutate", 6);
return mrb_nil_value();
}
@@ -73,11 +73,11 @@ void mrb_mruby_inline_struct_gem_test(mrb_state *mrb)
struct RClass *cls;

cls = mrb_define_class(mrb, "InlineStructTest", mrb->object_class);
MRB_SET_INSTANCE_TT(cls, MRB_TT_INLINE);
mrb_define_method(mrb, cls, "initialize", inline_test_initialize, MRB_ARGS_REQ(1));
mrb_define_method(mrb, cls, "to_s", inline_test_to_s, MRB_ARGS_NONE());
mrb_define_method(mrb, cls, "mutate", inline_test_mutate, MRB_ARGS_NONE());
mrb_define_class_method(mrb, cls, "length", inline_test_length, MRB_ARGS_NONE());
mrb_define_class_method(mrb, cls, "test_receive", inline_test_test_receive, MRB_ARGS_REQ(1));
mrb_define_class_method(mrb, cls, "test_receive_direct", inline_test_test_receive_direct, MRB_ARGS_REQ(1));
MRB_SET_INSTANCE_TT(cls, MRB_TT_ISTRUCT);
mrb_define_method(mrb, cls, "initialize", istruct_test_initialize, MRB_ARGS_REQ(1));
mrb_define_method(mrb, cls, "to_s", istruct_test_to_s, MRB_ARGS_NONE());
mrb_define_method(mrb, cls, "mutate", istruct_test_mutate, MRB_ARGS_NONE());
mrb_define_class_method(mrb, cls, "length", istruct_test_length, MRB_ARGS_NONE());
mrb_define_class_method(mrb, cls, "test_receive", istruct_test_test_receive, MRB_ARGS_REQ(1));
mrb_define_class_method(mrb, cls, "test_receive_direct", istruct_test_test_receive_direct, MRB_ARGS_REQ(1));
}
@@ -14,7 +14,7 @@
#include <mruby/variable.h>
#include <mruby/error.h>
#include <mruby/data.h>
#include <mruby/inline.h>
#include <mruby/istruct.h>

KHASH_DEFINE(mt, mrb_sym, struct RProc*, TRUE, kh_int_hash_func, kh_int_hash_equal)

@@ -712,11 +712,11 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, void**);
if (i < argc) {
ss = ARGV[arg_i];
if (mrb_type(ss) != MRB_TT_INLINE)
if (mrb_type(ss) != MRB_TT_ISTRUCT)
{
mrb_raisef(mrb, E_TYPE_ERROR, "%S is not inline struct", ss);
}
*p = mrb_inline_ptr(ss);
*p = mrb_istruct_ptr(ss);
arg_i++;
i++;
}
@@ -139,7 +139,7 @@ mrb_obj_id(mrb_value obj)
case MRB_TT_EXCEPTION:
case MRB_TT_FILE:
case MRB_TT_DATA:
case MRB_TT_INLINE:
case MRB_TT_ISTRUCT:
default:
return MakeID(mrb_ptr(obj));
}
@@ -11,7 +11,7 @@
#include <mruby/string.h>
#include <mruby/variable.h>
#include <mruby/error.h>
#include <mruby/inline.h>
#include <mruby/istruct.h>

typedef enum {
NOEX_PUBLIC = 0x00,
@@ -302,8 +302,8 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
case MRB_TT_EXCEPTION:
mrb_iv_copy(mrb, dest, obj);
break;
case MRB_TT_INLINE:
mrb_inline_copy(dest, obj);
case MRB_TT_ISTRUCT:
mrb_istruct_copy(dest, obj);
break;

default:
@@ -348,7 +348,7 @@ mrb_check_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const
{
mrb_value v;

if (mrb_type(val) == type && type != MRB_TT_DATA && type != MRB_TT_INLINE) return val;
if (mrb_type(val) == type && type != MRB_TT_DATA && type != MRB_TT_ISTRUCT) return val;
v = convert_type(mrb, val, tname, method, FALSE);
if (mrb_nil_p(v) || mrb_type(v) != type) return mrb_nil_value();
return v;
@@ -390,7 +390,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
enum mrb_vtype xt;

xt = mrb_type(x);
if ((xt != t) || (xt == MRB_TT_DATA) || (xt == MRB_TT_INLINE)) {
if ((xt != t) || (xt == MRB_TT_DATA) || (xt == MRB_TT_ISTRUCT)) {
while (type->type < MRB_TT_MAXDEFINE) {
if (type->type == t) {
const char *etype;

0 comments on commit 8438792

Please sign in to comment.