From c1722d407938754292a6989242db9effb74bf3b6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Jun 2016 02:13:20 +0900 Subject: [PATCH 1/6] Use $CPPFLAGS Use $CPPFLAGS for preprocessor flags, instead of $CFLAGS. --- ext/shadow/extconf.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/shadow/extconf.rb b/ext/shadow/extconf.rb index 3e74834..d7b8f6b 100644 --- a/ext/shadow/extconf.rb +++ b/ext/shadow/extconf.rb @@ -6,7 +6,7 @@ require 'mkmf' -$CFLAGS = RUBY_VERSION =~ /1\.8/ ? '-DRUBY18' : '' +$CPPFLAGS = RUBY_VERSION =~ /1\.8/ ? '-DRUBY18' : '' if( ! (ok = have_library("shadow","getspent")) ) ok = have_func("getspent") @@ -20,7 +20,7 @@ if ok if ! have_func("sgetspent") - $CFLAGS += '-DSOLARIS' + $CPPFLAGS += '-DSOLARIS' end create_makefile("shadow") end From 50286ccb8f60e4eed356eef393ba9d5f7227a7f1 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Jun 2016 02:31:02 +0900 Subject: [PATCH 2/6] Use macro for the feature Use macro `HAVE_SGETSPENT`, which doesn't mean none-Solaris. --- ext/shadow/extconf.rb | 4 +--- ext/shadow/shadow.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ext/shadow/extconf.rb b/ext/shadow/extconf.rb index d7b8f6b..a6da35d 100644 --- a/ext/shadow/extconf.rb +++ b/ext/shadow/extconf.rb @@ -19,8 +19,6 @@ ok &= have_func("ulckpwdf") if ok - if ! have_func("sgetspent") - $CPPFLAGS += '-DSOLARIS' - end + have_func("sgetspent") create_makefile("shadow") end diff --git a/ext/shadow/shadow.c b/ext/shadow/shadow.c index 63fdd18..10158ed 100644 --- a/ext/shadow/shadow.c +++ b/ext/shadow/shadow.c @@ -46,7 +46,7 @@ rb_shadow_endspent(VALUE self) }; -#ifndef SOLARIS +#ifdef HAVE_SGETSPENT static VALUE rb_shadow_sgetspent(VALUE self, VALUE str) { @@ -280,7 +280,7 @@ Init_shadow() rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0); rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0); -#ifndef SOLARIS +#ifdef HAVE_SGETSPENT rb_define_module_function(rb_mPasswd,"sgetspent",rb_shadow_sgetspent,1); #endif rb_define_module_function(rb_mPasswd,"fgetspent",rb_shadow_fgetspent,1); From 089cd33727c7a43b06b1b4def2fb53d9039273c8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Jun 2016 02:40:15 +0900 Subject: [PATCH 3/6] Use dedicated macros Use the macro for each headers defined in ruby.h since ruby 1.9. Use `GetReadFile()` or `rb_io_stdio_file()` to obtain open `FILE`. `IO` objects may not have `stdio_file`. --- ext/shadow/extconf.rb | 2 -- ext/shadow/shadow.c | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ext/shadow/extconf.rb b/ext/shadow/extconf.rb index a6da35d..730acf3 100644 --- a/ext/shadow/extconf.rb +++ b/ext/shadow/extconf.rb @@ -6,8 +6,6 @@ require 'mkmf' -$CPPFLAGS = RUBY_VERSION =~ /1\.8/ ? '-DRUBY18' : '' - if( ! (ok = have_library("shadow","getspent")) ) ok = have_func("getspent") end diff --git a/ext/shadow/shadow.c b/ext/shadow/shadow.c index 10158ed..5b63629 100644 --- a/ext/shadow/shadow.c +++ b/ext/shadow/shadow.c @@ -10,16 +10,16 @@ #include #include "ruby.h" -#ifdef RUBY18 +#ifndef HAVE_RUBY_IO_H #include "rubyio.h" #else #include #endif -#ifdef RUBY18 -#define file_ptr(x) (x)->f +#ifdef GetReadFile +#define file_ptr(x) GetReadFile(x) #else -#define file_ptr(x) (x)->stdio_file +#define file_ptr(x) rb_io_stdio_file(x) #endif static VALUE rb_mShadow; From 6b744dfea4499758ba5a0df8610b0dcaf77c7435 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Jun 2016 02:48:24 +0900 Subject: [PATCH 4/6] Use `rb_block_given_p` `rb_iterator_p()` is deprecated since 2000. --- ext/shadow/shadow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/shadow/shadow.c b/ext/shadow/shadow.c index 5b63629..3e17d9f 100644 --- a/ext/shadow/shadow.c +++ b/ext/shadow/shadow.c @@ -209,7 +209,7 @@ rb_shadow_lock(VALUE self) { int result; - if( rb_iterator_p() ){ + if( rb_block_given_p() ){ result = lckpwdf(); if( result == -1 ){ rb_raise(rb_eFileLock,"password file was locked"); From 965ec792719f110931086ac4ad1075b35d3965fc Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Jun 2016 02:53:08 +0900 Subject: [PATCH 5/6] Remove extra semicolons --- ext/shadow/shadow.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ext/shadow/shadow.c b/ext/shadow/shadow.c index 3e17d9f..afef157 100644 --- a/ext/shadow/shadow.c +++ b/ext/shadow/shadow.c @@ -35,7 +35,7 @@ rb_shadow_setspent(VALUE self) { setspent(); return Qnil; -}; +} static VALUE @@ -43,7 +43,7 @@ rb_shadow_endspent(VALUE self) { endspent(); return Qnil; -}; +} #ifdef HAVE_SGETSPENT @@ -74,7 +74,7 @@ rb_shadow_sgetspent(VALUE self, VALUE str) 0); free(entry); return result; -}; +} #endif static VALUE @@ -103,7 +103,7 @@ rb_shadow_fgetspent(VALUE self, VALUE file) INT2FIX(entry->sp_flag), 0); return result; -}; +} static VALUE rb_shadow_getspent(VALUE self) @@ -128,7 +128,7 @@ rb_shadow_getspent(VALUE self) INT2FIX(entry->sp_flag), 0); return result; -}; +} static VALUE rb_shadow_getspnam(VALUE self, VALUE name) @@ -156,7 +156,7 @@ rb_shadow_getspnam(VALUE self, VALUE name) INT2FIX(entry->sp_flag), 0); return result; -}; +} static VALUE @@ -188,7 +188,7 @@ rb_shadow_putspent(VALUE self, VALUE entry, VALUE file) rb_raise(rb_eStandardError,"can't change password"); return Qtrue; -}; +} static VALUE @@ -200,7 +200,7 @@ rb_shadow_lckpwdf(VALUE self) rb_raise(rb_eFileLock,"password file was locked"); else return Qtrue; -}; +} static int in_lock; @@ -219,13 +219,13 @@ rb_shadow_lock(VALUE self) rb_yield(Qnil); in_lock--; ulckpwdf(); - }; + } return Qtrue; } else{ return rb_shadow_lckpwdf(self); - }; -}; + } +} static VALUE @@ -233,16 +233,16 @@ rb_shadow_ulckpwdf(VALUE self) { if( in_lock ){ rb_raise(rb_eFileLock,"you call unlock method in lock iterator."); - }; + } ulckpwdf(); return Qtrue; -}; +} static VALUE rb_shadow_unlock(VALUE self) { return rb_shadow_ulckpwdf(self); -}; +} static VALUE rb_shadow_lock_p(VALUE self) @@ -256,8 +256,8 @@ rb_shadow_lock_p(VALUE self) else{ ulckpwdf(); return Qfalse; - }; -}; + } +} void @@ -292,4 +292,4 @@ Init_shadow() rb_define_module_function(rb_mPasswd,"ulckpwdf",rb_shadow_ulckpwdf,0); rb_define_module_function(rb_mPasswd,"unlock",rb_shadow_unlock,0); rb_define_module_function(rb_mPasswd,"lock?",rb_shadow_lock_p,0); -}; +} From e0d35bfd04407dcf23ba2c8c15aee46be7f80a7b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Jun 2016 02:53:54 +0900 Subject: [PATCH 6/6] Protoize No arguments declaration is old K&R style. ANSI style needs `void`. --- ext/shadow/shadow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/shadow/shadow.c b/ext/shadow/shadow.c index afef157..56faab0 100644 --- a/ext/shadow/shadow.c +++ b/ext/shadow/shadow.c @@ -261,7 +261,7 @@ rb_shadow_lock_p(VALUE self) void -Init_shadow() +Init_shadow(void) { rb_sPasswdEntry = rb_struct_define("PasswdEntry", "sp_namp","sp_pwdp","sp_lstchg",