Skip to content

Commit 70357bd

Browse files
* Update conn.c ruby >= 3.0: use rb_cObject instead of rb_cData ruby < 3.0: use rb_cData ruby 2.7 will be outdated soon. * replace RUBY_VERSION_CODE with RB_LDAP_RVC --------- Co-authored-by: minamino <[email protected]>
1 parent 10a2e1b commit 70357bd

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

conn.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,15 +1855,20 @@ Init_ldap_conn ()
18551855
{
18561856
rb_ldap_sort_obj = Qnil;
18571857

1858+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 30000
1859+
rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cData);
1860+
#endif
1861+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
18581862
rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cObject);
18591863
rb_undef_alloc_func(rb_cLDAP_Conn);
1864+
#endif
18601865
rb_define_attr (rb_cLDAP_Conn, "referrals", 1, 0);
18611866
rb_define_attr (rb_cLDAP_Conn, "controls", 1, 0);
18621867
rb_define_attr (rb_cLDAP_Conn, "sasl_quiet", 1, 1);
1863-
#if RUBY_VERSION_CODE < 170
1868+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
18641869
rb_define_singleton_method (rb_cLDAP_Conn, "new", rb_ldap_class_new, -1);
18651870
#endif
1866-
#if RUBY_VERSION_CODE >= 173
1871+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10703
18671872
rb_define_alloc_func (rb_cLDAP_Conn, rb_ldap_conn_s_allocate);
18681873
#else
18691874
rb_define_singleton_method (rb_cLDAP_Conn, "allocate",

entry.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
VALUE rb_cLDAP_Entry;
1010

11-
#if RUBY_VERSION_CODE >= 190
11+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
1212
static void
1313
rb_ldap_entry_mark(RB_LDAPENTRY_DATA *edata)
1414
{
@@ -88,11 +88,11 @@ rb_ldap_entry_new (LDAP * ldap, LDAPMessage * msg)
8888
{
8989
VALUE val;
9090
RB_LDAPENTRY_DATA *edata;
91-
#if RUBY_VERSION_CODE >= 190
91+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
9292
char *c_dn;
9393
#endif
9494

95-
#if RUBY_VERSION_CODE >= 190
95+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
9696
val = Data_Make_Struct (rb_cLDAP_Entry, RB_LDAPENTRY_DATA,
9797
rb_ldap_entry_mark, rb_ldap_entry_free, edata);
9898
#else
@@ -102,7 +102,7 @@ rb_ldap_entry_new (LDAP * ldap, LDAPMessage * msg)
102102
edata->ldap = ldap;
103103
edata->msg = msg;
104104

105-
#if RUBY_VERSION_CODE >= 190
105+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
106106
/* get dn */
107107
c_dn = ldap_get_dn(ldap, msg);
108108
if (c_dn) {
@@ -128,14 +128,14 @@ VALUE
128128
rb_ldap_entry_get_dn (VALUE self)
129129
{
130130
RB_LDAPENTRY_DATA *edata;
131-
#if RUBY_VERSION_CODE < 190
131+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
132132
char *cdn;
133133
VALUE dn;
134134
#endif
135135

136136
GET_LDAPENTRY_DATA (self, edata);
137137

138-
#if RUBY_VERSION_CODE < 190
138+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
139139
cdn = ldap_get_dn (edata->ldap, edata->msg);
140140
if (cdn)
141141
{
@@ -166,7 +166,7 @@ VALUE
166166
rb_ldap_entry_get_values (VALUE self, VALUE attr)
167167
{
168168
RB_LDAPENTRY_DATA *edata;
169-
#if RUBY_VERSION_CODE < 190
169+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
170170
char *c_attr;
171171
struct berval **c_vals;
172172
int i;
@@ -175,7 +175,7 @@ rb_ldap_entry_get_values (VALUE self, VALUE attr)
175175
#endif
176176

177177
GET_LDAPENTRY_DATA (self, edata);
178-
#if RUBY_VERSION_CODE < 190
178+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
179179
c_attr = StringValueCStr (attr);
180180

181181
c_vals = ldap_get_values_len (edata->ldap, edata->msg, c_attr);
@@ -213,7 +213,7 @@ VALUE
213213
rb_ldap_entry_get_attributes (VALUE self)
214214
{
215215
RB_LDAPENTRY_DATA *edata;
216-
#if RUBY_VERSION_CODE < 190
216+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
217217
VALUE vals;
218218
char *attr;
219219
BerElement *ber = NULL;
@@ -223,7 +223,7 @@ rb_ldap_entry_get_attributes (VALUE self)
223223

224224
GET_LDAPENTRY_DATA (self, edata);
225225

226-
#if RUBY_VERSION_CODE < 190
226+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
227227
vals = rb_ary_new ();
228228
for (attr = ldap_first_attribute (edata->ldap, edata->msg, &ber);
229229
attr != NULL;
@@ -259,7 +259,7 @@ rb_ldap_entry_get_attributes (VALUE self)
259259
VALUE
260260
rb_ldap_entry_to_hash (VALUE self)
261261
{
262-
#if RUBY_VERSION_CODE < 190
262+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
263263
VALUE attrs = rb_ldap_entry_get_attributes (self);
264264
VALUE hash = rb_hash_new ();
265265
VALUE attr, vals;
@@ -269,7 +269,7 @@ rb_ldap_entry_to_hash (VALUE self)
269269
VALUE hash, dn_ary;
270270
#endif
271271

272-
#if RUBY_VERSION_CODE < 190
272+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
273273
Check_Type (attrs, T_ARRAY);
274274
rb_hash_aset (hash, rb_tainted_str_new2 ("dn"),
275275
rb_ary_new3 (1, rb_ldap_entry_get_dn (self)));
@@ -305,7 +305,7 @@ rb_ldap_entry_inspect (VALUE self)
305305
str = rb_str_new (0, strlen (c) + 10 + 16 + 1); /* 10:tags 16:addr 1:nul */
306306
sprintf (RSTRING_PTR (str), "#<%s:0x%lx\n", c, self);
307307

308-
#if RUBY_VERSION_CODE < 190
308+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
309309
RSTRING(str)->len = strlen (RSTRING_PTR (str));
310310
#else
311311
rb_str_set_len(str, strlen (RSTRING_PTR (str)));

extconf.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ def ldap_with_config(arg, default = nil)
257257

258258
$defs << "-DRUBY_VERSION_CODE=#{RUBY_VERSION.gsub(/\D/, '')}"
259259

260+
def rb_ldap_rb_ver_code
261+
( _major, _minor, _teeny ) = RUBY_VERSION.split(/\D/)
262+
_rvc = _major.to_i * 10000 + _minor.to_i * 100 + _teeny.to_i
263+
end
264+
$defs << "-DRB_LDAP_RVC=#{rb_ldap_rb_ver_code}"
265+
260266
create_makefile("ldap")
261267

262268

misc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ rb_ldap_control_s_allocate (VALUE klass)
131131
return Data_Wrap_Struct (klass, 0, rb_ldap_control_free, ctl);
132132
}
133133

134-
#if RUBY_VERSION_CODE < 170
134+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
135135
static VALUE
136136
rb_ldap_control_s_new (int argc, VALUE argv[], VALUE klass)
137137
{
@@ -479,11 +479,11 @@ Init_ldap_misc ()
479479

480480
#ifdef HAVE_LDAPCONTROL
481481
rb_cLDAP_Control = rb_define_class_under (rb_mLDAP, "Control", rb_cObject);
482-
#if RUBY_VERSION_CODE < 170
482+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
483483
rb_define_singleton_method (rb_cLDAP_Control, "new",
484484
rb_ldap_control_s_new, -1);
485485
#endif
486-
#if RUBY_VERSION_CODE >= 173
486+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10703
487487
rb_define_alloc_func (rb_cLDAP_Control, rb_ldap_control_s_allocate);
488488
#else
489489
rb_define_singleton_method (rb_cLDAP_Control, "allocate",

mod.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ rb_ldap_mod_inspect (VALUE self)
283283
str = rb_str_new (0, strlen (c) + 10 + 16 + 1); /* 10:tags 16:addr 1:nul */
284284
sprintf (RSTRING_PTR (str), "#<%s:0x%lx ", c, self);
285285

286-
#if RUBY_VERSION_CODE < 190
286+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
287287
RSTRING(str)->len = strlen (RSTRING_PTR (str));
288288
#else
289289
rb_str_set_len(str, strlen (RSTRING_PTR (str)));
@@ -336,10 +336,10 @@ void
336336
Init_ldap_mod ()
337337
{
338338
rb_cLDAP_Mod = rb_define_class_under (rb_mLDAP, "Mod", rb_cObject);
339-
#if RUBY_VERSION_CODE < 170
339+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
340340
rb_define_singleton_method (rb_cLDAP_Mod, "new", rb_ldap_class_new, -1);
341341
#endif
342-
#if RUBY_VERSION_CODE >= 173
342+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10703
343343
rb_define_alloc_func (rb_cLDAP_Mod, rb_ldap_mod_s_allocate);
344344
#else
345345
rb_define_singleton_method (rb_cLDAP_Mod, "allocate",

rbldap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef struct rb_ldapentry_data
5555
{
5656
LDAP *ldap;
5757
LDAPMessage *msg;
58-
#if RUBY_VERSION_CODE >= 190
58+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
5959
VALUE dn;
6060
VALUE attr;
6161
#endif
@@ -173,7 +173,7 @@ VALUE rb_ldap_mod_vals (VALUE);
173173
}; \
174174
}
175175

176-
#if RUBY_VERSION_CODE < 190
176+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
177177
#define GET_LDAPENTRY_DATA(obj,ptr) { \
178178
Data_Get_Struct(obj, struct rb_ldapentry_data, ptr); \
179179
if( ! ptr->msg ){ \
@@ -206,7 +206,7 @@ VALUE rb_ldap_mod_vals (VALUE);
206206

207207
#endif
208208

209-
#if RUBY_VERSION_CODE >= 270
209+
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 20700
210210
# if defined rb_tainted_str_new
211211
# undef rb_tainted_str_new
212212
# endif

0 commit comments

Comments
 (0)