Add version to the interface of Random extensions
This commit is contained in:
parent
0ae5de1a5d
commit
6eaed20e14
132
ext/-test-/random/bad_version.c
Normal file
132
ext/-test-/random/bad_version.c
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
#include "ruby/random.h"
|
||||||
|
|
||||||
|
#if RUBY_RANDOM_INTERFACE_VERSION_MAJOR < RUBY_RANDOM_INTERFACE_VERSION_MAJOR_MAX
|
||||||
|
# define DEFINE_VERSION_MAX 1
|
||||||
|
#else
|
||||||
|
# define DEFINE_VERSION_MAX 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NORETURN(static void must_not_reach(void));
|
||||||
|
static void
|
||||||
|
must_not_reach(void)
|
||||||
|
{
|
||||||
|
rb_raise(rb_eTypeError, "must not reach");
|
||||||
|
}
|
||||||
|
|
||||||
|
NORETURN(static void bad_version_init(rb_random_t *, const uint32_t *, size_t));
|
||||||
|
static void
|
||||||
|
bad_version_init(rb_random_t *rnd, const uint32_t *buf, size_t len)
|
||||||
|
{
|
||||||
|
must_not_reach();
|
||||||
|
}
|
||||||
|
|
||||||
|
NORETURN(static void bad_version_get_bytes(rb_random_t *, void *, size_t));
|
||||||
|
static void
|
||||||
|
bad_version_get_bytes(rb_random_t *rnd, void *p, size_t n)
|
||||||
|
{
|
||||||
|
must_not_reach();
|
||||||
|
}
|
||||||
|
|
||||||
|
NORETURN(static uint32_t bad_version_get_int32(rb_random_t *));
|
||||||
|
static uint32_t
|
||||||
|
bad_version_get_int32(rb_random_t *rnd)
|
||||||
|
{
|
||||||
|
must_not_reach();
|
||||||
|
UNREACHABLE_RETURN(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
bad_version_alloc(VALUE klass, const rb_data_type_t *type)
|
||||||
|
{
|
||||||
|
rb_random_t *rnd;
|
||||||
|
VALUE obj = TypedData_Make_Struct(klass, rb_random_t, type, rnd);
|
||||||
|
rb_random_base_init(rnd);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* version 0 */
|
||||||
|
static const rb_random_interface_t random_version_zero_if;
|
||||||
|
|
||||||
|
static rb_random_data_type_t version_zero_type = {
|
||||||
|
"random/version_zero",
|
||||||
|
{
|
||||||
|
rb_random_mark,
|
||||||
|
RUBY_TYPED_DEFAULT_FREE,
|
||||||
|
},
|
||||||
|
RB_RANDOM_PARENT,
|
||||||
|
(void *)&random_version_zero_if,
|
||||||
|
RUBY_TYPED_FREE_IMMEDIATELY
|
||||||
|
};
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
version_zero_alloc(VALUE klass)
|
||||||
|
{
|
||||||
|
return bad_version_alloc(klass, &version_zero_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_version_zero(VALUE mod, VALUE base)
|
||||||
|
{
|
||||||
|
VALUE c = rb_define_class_under(mod, "VersionZero", base);
|
||||||
|
rb_define_alloc_func(c, version_zero_alloc);
|
||||||
|
RB_RANDOM_DATA_INIT_PARENT(version_zero_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEFINE_VERSION_MAX
|
||||||
|
/* version max */
|
||||||
|
static const rb_random_interface_t random_version_max_if;
|
||||||
|
static rb_random_data_type_t version_max_type = {
|
||||||
|
"random/version_max",
|
||||||
|
{
|
||||||
|
rb_random_mark,
|
||||||
|
RUBY_TYPED_DEFAULT_FREE,
|
||||||
|
},
|
||||||
|
RB_RANDOM_PARENT,
|
||||||
|
(void *)&random_version_max_if,
|
||||||
|
RUBY_TYPED_FREE_IMMEDIATELY
|
||||||
|
};
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
version_max_alloc(VALUE klass)
|
||||||
|
{
|
||||||
|
return bad_version_alloc(klass, &version_max_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_version_max(VALUE mod, VALUE base)
|
||||||
|
{
|
||||||
|
VALUE c = rb_define_class_under(mod, "VersionMax", base);
|
||||||
|
rb_define_alloc_func(c, version_max_alloc);
|
||||||
|
RB_RANDOM_DATA_INIT_PARENT(version_max_type);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void
|
||||||
|
init_version_max(mod, base)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
Init_random_bad_version(VALUE mod, VALUE base)
|
||||||
|
{
|
||||||
|
init_version_zero(mod, base);
|
||||||
|
init_version_max(mod, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef RUBY_RANDOM_INTERFACE_VERSION_MAJOR
|
||||||
|
|
||||||
|
#define RUBY_RANDOM_INTERFACE_VERSION_MAJOR 0
|
||||||
|
static const rb_random_interface_t random_version_zero_if = {
|
||||||
|
0,
|
||||||
|
RB_RANDOM_INTERFACE_DEFINE(bad_version)
|
||||||
|
};
|
||||||
|
#undef RUBY_RANDOM_INTERFACE_VERSION_MAJOR
|
||||||
|
|
||||||
|
#if DEFINE_VERSION_MAX
|
||||||
|
#define RUBY_RANDOM_INTERFACE_VERSION_MAJOR RUBY_RANDOM_INTERFACE_VERSION_MAJOR_MAX
|
||||||
|
static const rb_random_interface_t random_version_max_if = {
|
||||||
|
0,
|
||||||
|
RB_RANDOM_INTERFACE_DEFINE(bad_version)
|
||||||
|
};
|
||||||
|
#undef RUBY_RANDOM_INTERFACE_VERSION_MAJOR
|
||||||
|
#endif
|
@ -1,4 +1,164 @@
|
|||||||
# AUTOGENERATED DEPENDENCIES START
|
# AUTOGENERATED DEPENDENCIES START
|
||||||
|
bad_version.o: $(RUBY_EXTCONF_H)
|
||||||
|
bad_version.o: $(arch_hdrdir)/ruby/config.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/assert.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/assume.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/attributes.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/bool.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/inttypes.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/limits.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/long_long.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/stdalign.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/backward/2/stdarg.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/defines.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/intern.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/abi.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/anyargs.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/char.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/double.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/fixnum.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/gid_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/int.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/intptr_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/long.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/long_long.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/mode_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/off_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/pid_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/short.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/size_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/st_data_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/arithmetic/uid_t.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/assume.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/alloc_size.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/artificial.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/cold.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/const.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/constexpr.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/deprecated.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/diagnose_if.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/enum_extensibility.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/error.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/flag_enum.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/forceinline.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/format.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/maybe_unused.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/noalias.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/nodiscard.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/noexcept.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/noinline.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/nonnull.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/noreturn.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/pure.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/restrict.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/returns_nonnull.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/warning.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/attr/weakref.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/cast.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_is.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_is/apple.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_is/clang.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_is/gcc.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_is/intel.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_is/msvc.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_is/sunpro.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/compiler_since.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/config.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/constant_p.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rarray.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rbasic.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rbignum.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rclass.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rdata.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rfile.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rhash.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/robject.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rregexp.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rstring.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rstruct.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/core/rtypeddata.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/ctype.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/dllexport.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/dosish.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/error.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/eval.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/event.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/fl_type.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/gc.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/glob.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/globals.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/attribute.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/builtin.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/c_attribute.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/cpp_attribute.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/declspec_attribute.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/extension.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/feature.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/has/warning.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/array.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/bignum.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/class.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/compar.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/complex.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/cont.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/dir.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/enum.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/enumerator.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/error.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/eval.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/file.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/gc.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/hash.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/io.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/load.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/marshal.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/numeric.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/object.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/parse.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/proc.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/process.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/random.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/range.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/rational.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/re.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/ruby.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/select.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/select/largesize.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/signal.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/sprintf.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/string.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/struct.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/thread.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/time.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/variable.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/intern/vm.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/interpreter.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/iterator.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/memory.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/method.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/module.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/newobj.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/rgengc.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/scan_args.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/special_consts.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/static_assert.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/stdalign.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/stdbool.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/symbol.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/value.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/value_type.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/variable.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/warning_push.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/internal/xmalloc.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/missing.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/random.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/ruby.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/st.h
|
||||||
|
bad_version.o: $(hdrdir)/ruby/subst.h
|
||||||
|
bad_version.o: bad_version.c
|
||||||
init.o: $(RUBY_EXTCONF_H)
|
init.o: $(RUBY_EXTCONF_H)
|
||||||
init.o: $(arch_hdrdir)/ruby/config.h
|
init.o: $(arch_hdrdir)/ruby/config.h
|
||||||
init.o: $(hdrdir)/ruby.h
|
init.o: $(hdrdir)/ruby.h
|
||||||
|
@ -16,6 +16,26 @@
|
|||||||
|
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* version
|
||||||
|
* 0: before versioning; deprecated
|
||||||
|
* 1: added version and flags
|
||||||
|
*/
|
||||||
|
#define RUBY_RANDOM_INTERFACE_VERSION_MAJOR 1
|
||||||
|
#define RUBY_RANDOM_INTERFACE_VERSION_MINOR 0
|
||||||
|
|
||||||
|
#define RUBY_RANDOM_PASTE_VERSION_SUFFIX(x, y, z) x##_##y##_##z
|
||||||
|
#define RUBY_RANDOM_WITH_VERSION_SUFFIX(name, major, minor) \
|
||||||
|
RUBY_RANDOM_PASTE_VERSION_SUFFIX(name, major, minor)
|
||||||
|
#define rb_random_data_type \
|
||||||
|
RUBY_RANDOM_WITH_VERSION_SUFFIX(rb_random_data_type, \
|
||||||
|
RUBY_RANDOM_INTERFACE_VERSION_MAJOR, \
|
||||||
|
RUBY_RANDOM_INTERFACE_VERSION_MINOR)
|
||||||
|
#define RUBY_RANDOM_INTERFACE_VERSION_INITIALIZER \
|
||||||
|
{RUBY_RANDOM_INTERFACE_VERSION_MAJOR, RUBY_RANDOM_INTERFACE_VERSION_MINOR}
|
||||||
|
#define RUBY_RANDOM_INTERFACE_VERSION_MAJOR_MAX 0xff
|
||||||
|
#define RUBY_RANDOM_INTERFACE_VERSION_MINOR_MAX 0xff
|
||||||
|
|
||||||
RBIMPL_SYMBOL_EXPORT_BEGIN()
|
RBIMPL_SYMBOL_EXPORT_BEGIN()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,6 +104,18 @@ typedef struct {
|
|||||||
/** Number of bits of seed numbers. */
|
/** Number of bits of seed numbers. */
|
||||||
size_t default_seed_bits;
|
size_t default_seed_bits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Major/minor versions of this interface
|
||||||
|
*/
|
||||||
|
struct {
|
||||||
|
uint8_t major, minor;
|
||||||
|
} version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reserved flags
|
||||||
|
*/
|
||||||
|
uint16_t flags;
|
||||||
|
|
||||||
/** Initialiser function. */
|
/** Initialiser function. */
|
||||||
rb_random_init_func *init;
|
rb_random_init_func *init;
|
||||||
|
|
||||||
@ -161,6 +193,7 @@ typedef struct {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
#define RB_RANDOM_INTERFACE_DEFINE(prefix) \
|
#define RB_RANDOM_INTERFACE_DEFINE(prefix) \
|
||||||
|
RUBY_RANDOM_INTERFACE_VERSION_INITIALIZER, 0, \
|
||||||
prefix##_init, \
|
prefix##_init, \
|
||||||
prefix##_get_int32, \
|
prefix##_get_int32, \
|
||||||
prefix##_get_bytes
|
prefix##_get_bytes
|
||||||
|
9
random.c
9
random.c
@ -400,6 +400,15 @@ random_init(int argc, VALUE *argv, VALUE obj)
|
|||||||
rb_raise(rb_eTypeError, "undefined random interface: %s",
|
rb_raise(rb_eTypeError, "undefined random interface: %s",
|
||||||
RTYPEDDATA_TYPE(obj)->wrap_struct_name);
|
RTYPEDDATA_TYPE(obj)->wrap_struct_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int major = rng->version.major;
|
||||||
|
unsigned int minor = rng->version.minor;
|
||||||
|
if (major != RUBY_RANDOM_INTERFACE_VERSION_MAJOR) {
|
||||||
|
rb_raise(rb_eTypeError, "Random interface version "
|
||||||
|
STRINGIZE(RUBY_RANDOM_INTERFACE_VERSION_MAJOR) "."
|
||||||
|
STRINGIZE(RUBY_RANDOM_INTERFACE_VERSION_MINOR) " "
|
||||||
|
"expected: %d.%d", major, minor);
|
||||||
|
}
|
||||||
argc = rb_check_arity(argc, 0, 1);
|
argc = rb_check_arity(argc, 0, 1);
|
||||||
rb_check_frozen(obj);
|
rb_check_frozen(obj);
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
module TestRandomExt
|
module TestRandomExt
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
assert_nothing_raised(LoadError) {require '-test-/random'}
|
||||||
|
end
|
||||||
|
|
||||||
class TestLoop < Test::Unit::TestCase
|
class TestLoop < Test::Unit::TestCase
|
||||||
def setup
|
include TestRandomExt
|
||||||
super
|
|
||||||
assert_nothing_raised(LoadError) {require '-test-/random'}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_bytes
|
def test_bytes
|
||||||
rnd = Bug::Random::Loop.new(1)
|
rnd = Bug::Random::Loop.new(1)
|
||||||
@ -24,4 +26,20 @@ module TestRandomExt
|
|||||||
assert_equal(1.00, Bug::Random::Loop.new(4<<14).rand)
|
assert_equal(1.00, Bug::Random::Loop.new(4<<14).rand)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class TestVersionZero < Test::Unit::TestCase
|
||||||
|
include TestRandomExt
|
||||||
|
|
||||||
|
def test_bad_version
|
||||||
|
assert_raise(TypeError) {Bug::Random::VersionZero.new}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class TestVersionMax < Test::Unit::TestCase
|
||||||
|
include TestRandomExt
|
||||||
|
|
||||||
|
def test_bad_version
|
||||||
|
assert_raise(TypeError) {Bug::Random::VersionMax.new}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user