ruby-changes:22801
From: shirosaki <ko1@a...>
Date: Wed, 29 Feb 2012 00:51:43 +0900 (JST)
Subject: [ruby-changes:22801] shirosaki:r34849 (trunk): * Makefile.in (PLATFORM_DIR): add a variable for `win32` directory.
shirosaki 2012-02-29 00:51:25 +0900 (Wed, 29 Feb 2012) New Revision: 34849 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34849 Log: * Makefile.in (PLATFORM_DIR): add a variable for `win32` directory. * Makefile.in (clean-platform): add new target. It cleans `win32` directory. * common.mk (clean): add a dependency for `win32` directory. * common.mk (distclean): ditto. * common.mk (distclean-platform): add new target. It cleans `win32` directory. * common.mk ($(PLATFORM_D)): add new target to make `win32` directory. * common.mk (win32/win32.$(OBJEXT)): move win32.o into `win32` directory. * common.mk (win32/file.$(OBJEXT)): add new target for win32/file.c. * configure.in: move win32.o into `win32` directory and add win32/file.o to MISSING. * file.c (file_load_ok, rb_file_load_ok): replace static file_load_ok() with public rb_file_load_ok(). It's to link Windows implementation in win32/file.c. * file.c (rb_find_file_ext_safe): ditto. * file.c (rb_find_file_safe): ditto. * win32/file.c (rb_file_load_ok): new file. Add Windows specific optimized implementation of rb_file_load_ok(). We created a separated file to avoid too many #ifdef macro which is unreadable. * win32/Makefile.sub (PLATFORM_DIR): add a variable for `win32` directory. * win32/Makefile.sub (MISSING): move win32.obj into `win32` directory and add win32/file.obj to MISSING. * win32/Makefile.sub (MAKEDIRS): replace MINIRUBY with BASERUBY. It's because miniruby doesn't exist when making `win32` directory. * win32/Makefile.sub (clean-platform): add new target to clean `win32` directory. * win32/Makefile.sub ({$(srcdir)}.c{}.obj): make it not match win32/file.c to build properly. * win32/Makefile.sub (win32/win32.$(OBJEXT)): move win32.obj into `win32` directory. Patch created with Luis Lavena. [ruby-core:42480] [Feature #5999] Added files: trunk/win32/file.c Modified files: trunk/ChangeLog trunk/Makefile.in trunk/common.mk trunk/configure.in trunk/file.c trunk/win32/Makefile.sub Index: configure.in =================================================================== --- configure.in (revision 34848) +++ configure.in (revision 34849) @@ -2620,7 +2620,8 @@ fi EXPORT_PREFIX=' ' DLDFLAGS="${DLDFLAGS}"' $(DEFFILE)' - AC_LIBOBJ([win32]) + AC_LIBOBJ([win32/win32]) + AC_LIBOBJ([win32/file]) COMMON_LIBS=m # COMMON_MACROS="WIN32_LEAN_AND_MEAN=" COMMON_HEADERS="winsock2.h windows.h" Index: ChangeLog =================================================================== --- ChangeLog (revision 34848) +++ ChangeLog (revision 34849) @@ -1,3 +1,47 @@ +Tue Feb 28 23:20:01 2012 Hiroshi Shirosaki <h.shirosaki@g...> + + * Makefile.in (PLATFORM_DIR): add a variable for `win32` directory. + * Makefile.in (clean-platform): add new target. + It cleans `win32` directory. + + * common.mk (clean): add a dependency for `win32` directory. + * common.mk (distclean): ditto. + * common.mk (distclean-platform): add new target. + It cleans `win32` directory. + * common.mk ($(PLATFORM_D)): add new target to make `win32` directory. + * common.mk (win32/win32.$(OBJEXT)): move win32.o into `win32` + directory. + * common.mk (win32/file.$(OBJEXT)): add new target for win32/file.c. + + * configure.in: move win32.o into `win32` directory and add + win32/file.o to MISSING. + + * file.c (file_load_ok, rb_file_load_ok): replace static + file_load_ok() with public rb_file_load_ok(). + It's to link Windows implementation in win32/file.c. + * file.c (rb_find_file_ext_safe): ditto. + * file.c (rb_find_file_safe): ditto. + + * win32/file.c (rb_file_load_ok): new file. Add Windows specific + optimized implementation of rb_file_load_ok(). We created a + separated file to avoid too many #ifdef macro which is unreadable. + + * win32/Makefile.sub (PLATFORM_DIR): add a variable for `win32` + directory. + * win32/Makefile.sub (MISSING): move win32.obj into `win32` + directory and add win32/file.obj to MISSING. + * win32/Makefile.sub (MAKEDIRS): replace MINIRUBY with BASERUBY. + It's because miniruby doesn't exist when making `win32` directory. + * win32/Makefile.sub (clean-platform): add new target to clean `win32` + directory. + * win32/Makefile.sub ({$(srcdir)}.c{}.obj): make it not match + win32/file.c to build properly. + * win32/Makefile.sub (win32/win32.$(OBJEXT)): move win32.obj into + `win32` directory. + + Patch created with Luis Lavena. + [ruby-core:42480] [Feature #5999] + Tue Feb 28 20:27:25 2012 Tadayoshi Funaba <tadf@d...> * ext/date/date_core.c: [ruby-core:42998] Index: common.mk =================================================================== --- common.mk (revision 34848) +++ common.mk (revision 34849) @@ -24,6 +24,7 @@ RBCONFIG = ./.rbconfig.time LIBRUBY_EXTS = ./.libruby-with-ext.time REVISION_H = ./.revision.time +PLATFORM_D = ./$(PLATFORM_DIR)/.time RDOCOUT = $(EXTOUT)/rdoc CAPIOUT = doc/capi ID_H_TARGET = -id.h- @@ -424,7 +425,7 @@ clear-installed-list: PHONY @> $(INSTALLED_LIST) set MAKE="$(MAKE)" -clean: clean-ext clean-local clean-enc clean-golf clean-rdoc clean-capi clean-extout +clean: clean-ext clean-local clean-enc clean-golf clean-rdoc clean-capi clean-extout clean-platform clean-local:: PHONY @$(RM) $(OBJS) $(MINIOBJS) $(MAINOBJ) $(LIBRUBY_A) $(LIBRUBY_SO) $(LIBRUBY) $(LIBRUBY_ALIASES) @$(RM) $(PROGRAM) $(WPROGRAM) miniruby$(EXEEXT) dmyext.$(OBJEXT) $(ARCHFILE) .*.time @@ -434,10 +435,11 @@ @$(RM) $(GORUBY)$(EXEEXT) $(GOLFOBJS) clean-rdoc: PHONY clean-capi: PHONY +clean-platform: PHONY clean-extout: PHONY clean-docs: clean-rdoc clean-capi -distclean: distclean-ext distclean-local distclean-enc distclean-golf distclean-extout +distclean: distclean-ext distclean-local distclean-enc distclean-golf distclean-extout distclean-platform distclean-local:: clean-local @$(RM) $(MKFILES) yasmdata.rb *.inc @$(RM) config.cache config.status config.status.lineno $(PRELUDES) @@ -448,6 +450,7 @@ distclean-rdoc: PHONY distclean-capi: PHONY distclean-extout: clean-extout +distclean-platform: clean-platform realclean:: realclean-ext realclean-local realclean-enc realclean-golf realclean-extout realclean-local:: distclean-local @@ -572,8 +575,13 @@ ia64.$(OBJEXT): {$(VPATH)}ia64.s $(CC) $(CFLAGS) -c $< -win32.$(OBJEXT): {$(VPATH)}win32.c $(RUBY_H_INCLUDES) +$(PLATFORM_D): + $(Q) $(MAKEDIRS) $(PLATFORM_DIR) + @exit > $@ +win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c $(RUBY_H_INCLUDES) $(PLATFORM_D) +win32/file.$(OBJEXT): {$(VPATH)}win32/file.c $(RUBY_H_INCLUDES) $(PLATFORM_D) + ### RUBY_H_INCLUDES = {$(VPATH)}ruby.h {$(VPATH)}config.h {$(VPATH)}defines.h \ Index: win32/file.c =================================================================== --- win32/file.c (revision 0) +++ win32/file.c (revision 34849) @@ -0,0 +1,25 @@ +#include "ruby/ruby.h" +#include <winbase.h> + +int +rb_file_load_ok(const char *path) +{ + int ret = 1; + DWORD attr = GetFileAttributes(path); + if (attr == INVALID_FILE_ATTRIBUTES || + attr & FILE_ATTRIBUTE_DIRECTORY) { + ret = 0; + } + else { + HANDLE h = CreateFile(path, GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h != INVALID_HANDLE_VALUE) { + CloseHandle(h); + } + else { + ret = 0; + } + } + return ret; +} Index: win32/Makefile.sub =================================================================== --- win32/Makefile.sub (revision 34848) +++ win32/Makefile.sub (revision 34849) @@ -122,6 +122,9 @@ !ifdef NTVER ARCHDEFS = -D_WIN32_WINNT=$(NTVER) $(ARCHDEFS) !endif +!if !defined(PLATFORM_DIR) +PLATFORM_DIR = win32 +!endif arch = $(ARCH)-$(PLATFORM) sitearch = $(ARCH)-$(RT) @@ -225,7 +228,7 @@ LIBS = unicows.lib $(LIBS) !endif !if !defined(MISSING) -MISSING = acosh.obj cbrt.obj crypt.obj erf.obj ffs.obj langinfo.obj lgamma_r.obj strlcat.obj strlcpy.obj tgamma.obj win32.obj setproctitle.obj +MISSING = acosh.obj cbrt.obj crypt.obj erf.obj ffs.obj langinfo.obj lgamma_r.obj strlcat.obj strlcpy.obj tgamma.obj win32/win32.obj win32/file.obj setproctitle.obj !endif ARFLAGS = -machine:$(MACHINE) -out: @@ -286,7 +289,7 @@ DEFAULT_PRELUDES = $(YES_GEM_PRELUDE) !endif -MAKEDIRS = $(MINIRUBY) -run -e mkdir -- -p +MAKEDIRS = $(BASERUBY) -run -e mkdir -- -p !if !defined(STACK) !if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64" @@ -919,6 +922,10 @@ clean-capi distclean-capi realclean-capi: -$(Q)$(RMALL) $(CAPIOUT:/=\) +clean-platform: + $(Q)$(RM) $(PLATFORM_DIR)\.time + -$(Q)$(RMDIR) $(PLATFORM_DIR:/=\) + clean-ext distclean-ext realclean-ext:: !if "$(EXTS)" != "" @for %I in ($(EXTS)) \ @@ -992,7 +999,7 @@ {$(win_srcdir)/sys}.c.obj: $(ECHO) compiling $(<:\=/) $(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c -Tc$(<:\=/) -{$(srcdir)}.c.obj: +{$(srcdir)}.c{}.obj: $(ECHO) compiling $(<:\=/) $(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c -Tc$(<:\=/) .c.obj: @@ -1039,7 +1046,7 @@ $(OBJS): {$(hdrdir)/ruby}win32.h -dir.$(OBJEXT) win32.$(OBJEXT): {$(srcdir)}win32/dir.h +dir.$(OBJEXT) win32/win32.$(OBJEXT): {$(srcdir)}win32/dir.h ext/extinit.obj: ext/extinit.c $(SETUP) $(ECHO) compiling ext/extinit.c Index: Makefile.in =================================================================== --- Makefile.in (revision 34848) +++ Makefile.in (revision 34849) @@ -12,6 +12,7 @@ srcdir = @srcdir@ top_srcdir = $(srcdir) hdrdir = $(srcdir)/include +PLATFORM_DIR = win32 CC = @CC@ CPP = @CPP@ @@ -346,6 +347,9 @@ @echo $(@:-capi=ing) capi $(Q)$(RMALL) $(CAPIOUT) +clean-platform: + @$(RM) $(PLATFORM_DIR)/.time + -$(Q) $(RMDIR) $(PLATFORM_DIR) 2> /dev/null || true ext/extinit.$(OBJEXT): ext/extinit.c $(SETUP) $(ECHO) compiling $@ Index: file.c =================================================================== --- file.c (revision 34848) +++ file.c (revision 34849) @@ -5144,8 +5144,9 @@ return 1; } -static int -file_load_ok(const char *path) +#ifndef _WIN32 +int +rb_file_load_ok(const char *path) { int ret = 1; int fd = rb_cloexec_open(path, O_RDONLY, 0); @@ -5162,13 +5163,8 @@ (void)close(fd); return ret; } +#endif -int -rb_file_load_ok(const char *path) -{ - return file_load_ok(path); -} - static int is_explicit_relative(const char *path) { @@ -5219,7 +5215,7 @@ fnlen = RSTRING_LEN(fname); for (i=0; ext[i]; i++) { rb_str_cat2(fname, ext[i]); - if (file_load_ok(RSTRING_PTR(fname))) { + if (rb_file_load_ok(RSTRING_PTR(fname))) { *filep = copy_path_class(fname, *filep); return (int)(i+1); } @@ -5247,7 +5243,7 @@ RB_GC_GUARD(str) = rb_get_path_check(str, safe_level); if (RSTRING_LEN(str) == 0) continue; file_expand_path(fname, str, 0, tmp); - if (file_load_ok(RSTRING_PTR(tmp))) { + if (rb_file_load_ok(RSTRING_PTR(tmp))) { *filep = copy_path_class(tmp, *filep); return (int)(j+1); } @@ -5286,7 +5282,7 @@ if (safe_level >= 1 && !fpath_check(path)) { rb_raise(rb_eSecurityError, "loading from unsafe path %s", f); } - if (!file_load_ok(f)) return 0; + if (!rb_file_load_ok(f)) return 0; if (!expanded) path = copy_path_class(file_expand_path_1(path), path); return path; @@ -5307,7 +5303,7 @@ if (RSTRING_LEN(str) > 0) { file_expand_path(path, str, 0, tmp); f = RSTRING_PTR(tmp); - if (file_load_ok(f)) goto found; + if (rb_file_load_ok(f)) goto found; } } return 0; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/