aboutsummaryrefslogtreecommitdiffstats
path: root/ruby_missing.h
blob: 8b59b49d333b695c228bcfb41ff43f41cd330599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * $Id$
 * 'OpenSSL for Ruby' project
 * Copyright (C) 2001-2003  Michal Rokos <m.rokos@sh.cvut.cz>
 * All rights reserved.
 */
/*
 * This program is licenced under the same licence as Ruby.
 * (See the file 'LICENCE'.)
 */
#if !defined(_OSSL_RUBY_MISSING_H_)
#define _OSS_RUBY_MISSING_H_

#if !defined(StringValue)
#  define StringValue(v) \
    if (TYPE(v) != T_STRING) v = rb_str_to_str(v)
#endif

#if !defined(StringValuePtr)
#  define StringValuePtr(v) \
    RSTRING((TYPE(v) == T_STRING) ? (v) : rb_str_to_str(v))->ptr
#endif

#if !defined(SafeStringValue)
#  define SafeStringValue(v) do {\
    StringValue(v);\
    rb_check_safe_str(v);\
} while (0)
#endif

#if RUBY_VERSION_CODE < 180
#  define rb_cstr_to_inum(a,b,c) \
    rb_cstr2inum(a,b)
#  define rb_check_frozen(obj) \
    if (OBJ_FROZEN(obj)) rb_error_frozen(rb_obj_classname(obj))
#  define rb_obj_classname(obj) \
    rb_class2name(CLASS_OF(obj))
#endif

#if HAVE_RB_DEFINE_ALLOC_FUNC
#  define DEFINE_ALLOC_WRAPPER(func)
#else
#  define DEFINE_ALLOC_WRAPPER(func)			\
    static VALUE					\
    func##_wrapper(int argc, VALUE *argv, VALUE klass)  \
    {							\
	VALUE obj;					\
							\
	obj = func(klass);				\
							\
	rb_obj_call_init(obj, argc, argv);		\
							\
	return obj;					\
    }
#  define rb_define_alloc_func(klass, func) \
    rb_define_singleton_method(klass, "new", func##_wrapper, -1)
#endif

/* the following clone wrapper is incomplete */
#if RUBY_VERSION_CODE >= 180
#define DEFINE_CLONE_WRAPPER(func)
#define rb_define_clone_func(klass, func)
#else
#define DEFINE_CLONE_WRAPPER(func)				\
	static VALUE ossl_##func##_clone_wrapper(VALUE self) {	\
		VALUE obj;					\
								\
		obj = ossl_##func##_alloc(CLASS_OF(self));	\
		ossl_##func##_copy(obj, self);			\
								\
		return obj;					\
	}
#define rb_define_clone_func(klass, func)			\
	rb_define_method(klass, "clone", func##_wrapper, 0)
#endif


#if RUBY_VERSION_CODE >= 180 
#if !defined(HAVE_RB_OBJ_INIT_COPY)
#    define rb_define_copy_func(klass, func) \
	rb_define_method(klass, "copy_object", func, 1)
#  else
#    define rb_define_copy_func(klass, func) \
	rb_define_method(klass, "initialize_copy", func, 1)
#  endif
#else
#  define rb_define_copy_func(klass, func)
#endif

#endif /* _OSS_RUBY_MISSING_H_ */

#if !HAVE_RB_BLOCK_PROC
#  define rb_block_proc rb_f_lambda
#endif