diff options
Diffstat (limited to 'unix')
38 files changed, 5430 insertions, 3887 deletions
diff --git a/unix/Makefile.in b/unix/Makefile.in index ded4c6b..b3507ba 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -81,6 +81,9 @@ HTML_INSTALL_DIR = $(INSTALL_ROOT)$(HTML_DIR) # Directory in which to install the configuration file tclConfig.sh CONFIG_INSTALL_DIR = $(INSTALL_ROOT)$(libdir) +# Directory in which to install bundled packages: +PACKAGE_DIR = @PACKAGE_DIR@ + # Package search path. TCL_PACKAGE_PATH = @TCL_PACKAGE_PATH@ @@ -92,7 +95,7 @@ CFLAGS_WARNING = @CFLAGS_WARNING@ # The default switches for optimization or debugging CFLAGS_DEBUG = @CFLAGS_DEBUG@ -CFLAGS_OPTIMIZE = @CFLAGS_OPTIMIZE@ +CFLAGS_OPTIMIZE = -DNDEBUG @CFLAGS_OPTIMIZE@ # To change the compiler switches, for example to change from optimization to # debugging symbols, change the following line: @@ -150,16 +153,21 @@ SHELL = @MAKEFILE_SHELL@ INSTALL_STRIP_PROGRAM = -s INSTALL_STRIP_LIBRARY = -S -x -INSTALL = @srcdir@/../unix/install-sh -c +INSTALL = $(SHELL) $(UNIX_DIR)/install-sh -c INSTALL_PROGRAM = ${INSTALL} INSTALL_LIBRARY = ${INSTALL} INSTALL_DATA = ${INSTALL} -m 644 - -# TCL_EXE is the name of a tclsh executable that is available *BEFORE* running -# make for the first time. Certain build targets (make genstubs) need it to be -# available on the PATH. This executable should *NOT* be required just to do a -# normal build although it can be required to run make dist. -TCL_EXE = tclsh@EXEEXT@ +INSTALL_DATA_DIR = ${INSTALL} -d -m 755 + +# NATIVE_TCLSH is the name of a tclsh executable that is available *BEFORE* +# running make for the first time. Certain build targets (make genstubs) need +# it to be available on the PATH. This executable should *NOT* be required +# just to do a normal build although it can be required to run make dist. +# Do not use SHELL_ENV for NATIVE_TCLSH unless it is the tclsh being built. +EXE_SUFFIX = @EXEEXT@ +TCL_EXE = tclsh${EXE_SUFFIX} +TCLTEST_EXE = tcltest${EXE_SUFFIX} +NATIVE_TCLSH = @TCLSH_PROG@ # The symbols below provide support for dynamic loading and shared libraries. # See configure.in for a description of what the symbols mean. The values of @@ -168,12 +176,11 @@ TCL_EXE = tclsh@EXEEXT@ STLIB_LD = @STLIB_LD@ SHLIB_LD = @SHLIB_LD@ -SHLIB_CFLAGS = @SHLIB_CFLAGS@ +SHLIB_CFLAGS = @SHLIB_CFLAGS@ -DBUILD_tcl SHLIB_LD_LIBS = @SHLIB_LD_LIBS@ TCL_SHLIB_LD_EXTRAS = @TCL_SHLIB_LD_EXTRAS@ SHLIB_SUFFIX = @SHLIB_SUFFIX@ -#SHLIB_SUFFIX = DLTEST_TARGETS = dltest.marker @@ -216,7 +223,7 @@ AR = @AR@ RANLIB = @RANLIB@ DTRACE = @DTRACE@ SRC_DIR = @srcdir@ -TOP_DIR = $(SRC_DIR)/.. +TOP_DIR = @TCL_SRC_DIR@ BUILD_DIR = @builddir@ GENERIC_DIR = $(TOP_DIR)/generic TOMMATH_DIR = $(TOP_DIR)/libtommath @@ -224,11 +231,15 @@ COMPAT_DIR = $(TOP_DIR)/compat TOOL_DIR = $(TOP_DIR)/tools UNIX_DIR = $(TOP_DIR)/unix MAC_OSX_DIR = $(TOP_DIR)/macosx +PKGS_DIR = $(TOP_DIR)/pkgs # Must be absolute because of the cd dltest $(DLTEST_DIR)/configure below. DLTEST_DIR = @TCL_SRC_DIR@/unix/dltest # Must be absolute to so the corresponding tcltest's tcl_library is absolute. TCL_BUILDTIME_LIBRARY = @TCL_SRC_DIR@/library +ZLIB_DIR = @ZLIB_DIR@ +ZLIB_INCLUDE = @ZLIB_INCLUDE@ + CC = @CC@ #CC = purify -best-effort @CC@ -DPURIFY @@ -247,6 +258,10 @@ INSTALL_TZDATA = @INSTALL_TZDATA@ #-------------------------------------------------------------------------- GDB = gdb +TRACE = strace +TRACE_OPTS = +VALGRIND = valgrind +VALGRINDARGS = --tool=memcheck --num-callers=8 --leak-resolution=high --leak-check=yes --show-reachable=yes -v #-------------------------------------------------------------------------- # The information below should be usable as is. The configure script won't @@ -276,11 +291,13 @@ XTTEST_OBJS = xtTestInit.o tclTest.o tclTestObj.o tclTestProcBodyObj.o \ GENERIC_OBJS = regcomp.o regexec.o regfree.o regerror.o tclAlloc.o \ tclAsync.o tclBasic.o tclBinary.o tclCkalloc.o tclClock.o \ - tclCmdAH.o tclCmdIL.o tclCmdMZ.o tclCompCmds.o tclCompExpr.o \ - tclCompile.o tclConfig.o tclDate.o tclDictObj.o tclEncoding.o \ + tclCmdAH.o tclCmdIL.o tclCmdMZ.o tclCompCmds.o tclCompCmdsSZ.o \ + tclCompExpr.o tclCompile.o tclConfig.o tclDate.o tclDictObj.o \ + tclEncoding.o tclEnsemble.o \ tclEnv.o tclEvent.o tclExecute.o tclFCmd.o tclFileName.o tclGet.o \ tclHash.o tclHistory.o tclIndexObj.o tclInterp.o tclIO.o tclIOCmd.o \ - tclIORChan.o tclIOGT.o tclIOSock.o tclIOUtil.o tclLink.o tclListObj.o \ + tclIORChan.o tclIORTrans.o tclIOGT.o tclIOSock.o tclIOUtil.o \ + tclLink.o tclListObj.o \ tclLiteral.o tclLoad.o tclMain.o tclNamesp.o tclNotify.o \ tclObj.o tclPanic.o tclParse.o tclPathObj.o tclPipe.o \ tclPkg.o tclPkgConfig.o tclPosixStr.o \ @@ -288,8 +305,12 @@ GENERIC_OBJS = regcomp.o regexec.o regfree.o regerror.o tclAlloc.o \ tclResolve.o tclResult.o tclScan.o tclStringObj.o \ tclStrToD.o tclThread.o \ tclThreadAlloc.o tclThreadJoin.o tclThreadStorage.o tclStubInit.o \ - tclStubLib.o tclTimer.o tclTrace.o tclUtf.o tclUtil.o tclVar.o \ - tclTomMathInterface.o + tclTimer.o tclTrace.o tclUtf.o tclUtil.o tclVar.o tclZlib.o \ + tclTomMathInterface.o \ + tclAssembly.o + +OO_OBJS = tclOO.o tclOOBasic.o tclOOCall.o tclOODefineCmds.o tclOOInfo.o \ + tclOOMethod.o tclOOStubInit.o TOMMATH_OBJS = bncore.o bn_reverse.o bn_fast_s_mp_mul_digs.o \ bn_fast_s_mp_sqr.o bn_mp_add.o bn_mp_and.o \ @@ -306,14 +327,14 @@ TOMMATH_OBJS = bncore.o bn_reverse.o bn_fast_s_mp_mul_digs.o \ bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_neg.o bn_mp_or.o \ bn_mp_radix_size.o bn_mp_radix_smap.o \ bn_mp_read_radix.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \ - bn_mp_shrink.o \ + bn_mp_shrink.o \ bn_mp_sqr.o bn_mp_sqrt.o bn_mp_sub.o bn_mp_sub_d.o \ bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o \ bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix_n.o \ bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_s_mp_add.o \ bn_s_mp_mul_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o -STUB_LIB_OBJS = tclStubLib.o ${COMPAT_OBJS} +STUB_LIB_OBJS = tclStubLib.o tclTomMathStubLib.o tclOOStubLib.o ${COMPAT_OBJS} UNIX_OBJS = tclUnixChan.o tclUnixEvent.o tclUnixFCmd.o \ tclUnixFile.o tclUnixPipe.o tclUnixSock.o \ @@ -326,14 +347,18 @@ MAC_OSX_OBJS = tclMacOSXBundle.o tclMacOSXFCmd.o tclMacOSXNotify.o DTRACE_OBJ = tclDTrace.o +ZLIB_OBJS = Zadler32.o Zcompress.o Zcrc32.o Zdeflate.o Zinfback.o \ + Zinffast.o Zinflate.o Zinftrees.o Ztrees.o Zuncompr.o Zzutil.o + TCL_OBJS = ${GENERIC_OBJS} ${UNIX_OBJS} ${NOTIFY_OBJS} ${COMPAT_OBJS} \ - @DL_OBJS@ @PLAT_OBJS@ + ${OO_OBJS} @DL_OBJS@ @PLAT_OBJS@ -OBJS = ${TCL_OBJS} ${TOMMATH_OBJS} @DTRACE_OBJ@ +OBJS = ${TCL_OBJS} ${TOMMATH_OBJS} @DTRACE_OBJ@ @ZLIB_OBJS@ TCL_DECLS = \ $(GENERIC_DIR)/tcl.decls \ $(GENERIC_DIR)/tclInt.decls \ + $(GENERIC_DIR)/tclOO.decls \ $(GENERIC_DIR)/tclTomMath.decls GENERIC_HDRS = \ @@ -344,6 +369,10 @@ GENERIC_HDRS = \ $(GENERIC_DIR)/tclIntPlatDecls.h \ $(GENERIC_DIR)/tclTomMath.h \ $(GENERIC_DIR)/tclTomMathDecls.h \ + $(GENERIC_DIR)/tclOO.h \ + $(GENERIC_DIR)/tclOODecls.h \ + $(GENERIC_DIR)/tclOOInt.h \ + $(GENERIC_DIR)/tclOOIntDecls.h \ $(GENERIC_DIR)/tclPatch.h \ $(GENERIC_DIR)/tclPlatDecls.h \ $(GENERIC_DIR)/tclPort.h \ @@ -355,6 +384,7 @@ GENERIC_SRCS = \ $(GENERIC_DIR)/regfree.c \ $(GENERIC_DIR)/regerror.c \ $(GENERIC_DIR)/tclAlloc.c \ + $(GENERIC_DIR)/tclAssembly.c \ $(GENERIC_DIR)/tclAsync.c \ $(GENERIC_DIR)/tclBasic.c \ $(GENERIC_DIR)/tclBinary.c \ @@ -364,12 +394,14 @@ GENERIC_SRCS = \ $(GENERIC_DIR)/tclCmdIL.c \ $(GENERIC_DIR)/tclCmdMZ.c \ $(GENERIC_DIR)/tclCompCmds.c \ + $(GENERIC_DIR)/tclCompCmdsSZ.c \ $(GENERIC_DIR)/tclCompExpr.c \ $(GENERIC_DIR)/tclCompile.c \ $(GENERIC_DIR)/tclConfig.c \ $(GENERIC_DIR)/tclDate.c \ $(GENERIC_DIR)/tclDictObj.c \ $(GENERIC_DIR)/tclEncoding.c \ + $(GENERIC_DIR)/tclEnsemble.c \ $(GENERIC_DIR)/tclEnv.c \ $(GENERIC_DIR)/tclEvent.c \ $(GENERIC_DIR)/tclExecute.c \ @@ -386,6 +418,7 @@ GENERIC_SRCS = \ $(GENERIC_DIR)/tclIOSock.c \ $(GENERIC_DIR)/tclIOUtil.c \ $(GENERIC_DIR)/tclIORChan.c \ + $(GENERIC_DIR)/tclIORTrans.c \ $(GENERIC_DIR)/tclLink.c \ $(GENERIC_DIR)/tclListObj.c \ $(GENERIC_DIR)/tclLiteral.c \ @@ -394,7 +427,7 @@ GENERIC_SRCS = \ $(GENERIC_DIR)/tclNamesp.c \ $(GENERIC_DIR)/tclNotify.c \ $(GENERIC_DIR)/tclObj.c \ - $(GENERIC_DIR)/tclParse.c \ + $(GENERIC_DIR)/tclParse.c \ $(GENERIC_DIR)/tclPathObj.c \ $(GENERIC_DIR)/tclPipe.c \ $(GENERIC_DIR)/tclPkg.c \ @@ -407,7 +440,6 @@ GENERIC_SRCS = \ $(GENERIC_DIR)/tclResult.c \ $(GENERIC_DIR)/tclScan.c \ $(GENERIC_DIR)/tclStubInit.c \ - $(GENERIC_DIR)/tclStubLib.c \ $(GENERIC_DIR)/tclStringObj.c \ $(GENERIC_DIR)/tclStrToD.c \ $(GENERIC_DIR)/tclTest.c \ @@ -420,10 +452,23 @@ GENERIC_SRCS = \ $(GENERIC_DIR)/tclTimer.c \ $(GENERIC_DIR)/tclTrace.c \ $(GENERIC_DIR)/tclUtil.c \ - $(GENERIC_DIR)/tclVar.c + $(GENERIC_DIR)/tclVar.c \ + $(GENERIC_DIR)/tclAssembly.c \ + $(GENERIC_DIR)/tclZlib.c + +OO_SRCS = \ + $(GENERIC_DIR)/tclOO.c \ + $(GENERIC_DIR)/tclOOBasic.c \ + $(GENERIC_DIR)/tclOOCall.c \ + $(GENERIC_DIR)/tclOODefineCmds.c \ + $(GENERIC_DIR)/tclOOInfo.c \ + $(GENERIC_DIR)/tclOOMethod.c \ + $(GENERIC_DIR)/tclOOStubInit.c STUB_SRCS = \ - $(GENERIC_DIR)/tclStubLib.c + $(GENERIC_DIR)/tclStubLib.c \ + $(GENERIC_DIR)/tclTomMathStubLib.c \ + $(GENERIC_DIR)/tclOOStubLib.o TOMMATH_SRCS = \ $(TOMMATH_DIR)/bncore.c \ @@ -531,14 +576,31 @@ DTRACE_HDR = tclDTrace.h DTRACE_SRC = $(GENERIC_DIR)/tclDTrace.d +ZLIB_SRCS = \ + $(ZLIB_DIR)/adler32.c \ + $(ZLIB_DIR)/compress.c \ + $(ZLIB_DIR)/crc32.c \ + $(ZLIB_DIR)/deflate.c \ + $(ZLIB_DIR)/infback.c \ + $(ZLIB_DIR)/inffast.c \ + $(ZLIB_DIR)/inflate.c \ + $(ZLIB_DIR)/inftrees.c \ + $(ZLIB_DIR)/trees.c \ + $(ZLIB_DIR)/uncompr.c \ + $(ZLIB_DIR)/zutil.c + # Note: don't include DL_SRCS or MAC_OSX_SRCS in SRCS: most of those files # won't compile on the current machine, and they will cause problems for # things like "make depend". SRCS = $(GENERIC_SRCS) $(TOMMATH_SRCS) $(UNIX_SRCS) $(NOTIFY_SRCS) \ - $(STUB_SRCS) @PLAT_SRCS@ + $(OO_SRCS) $(STUB_SRCS) @PLAT_SRCS@ @ZLIB_SRCS@ -all: binaries libraries doc +#-------------------------------------------------------------------------- +# Start of rules +#-------------------------------------------------------------------------- + +all: binaries libraries doc packages binaries: ${LIB_FILE} $(STUB_LIB_FILE) ${TCL_EXE} @@ -566,22 +628,63 @@ tclLibObjs: # This targets actually build the objects needed for the lib in the above case objs: ${OBJS} - ${TCL_EXE}: ${TCLSH_OBJS} ${TCL_LIB_FILE} - ${CC} ${CFLAGS} ${LDFLAGS} ${TCLSH_OBJS} @TCL_BUILD_LIB_SPEC@ ${LIBS} @EXTRA_TCLSH_LIBS@ \ + ${CC} ${CFLAGS} ${LDFLAGS} ${TCLSH_OBJS} \ + @TCL_BUILD_LIB_SPEC@ ${LIBS} @EXTRA_TCLSH_LIBS@ \ ${CC_SEARCH_FLAGS} -o ${TCL_EXE} +# Must be empty so it doesn't conflict with rule for ${TCL_EXE} above +${NATIVE_TCLSH}: + +Makefile: $(UNIX_DIR)/Makefile.in $(DLTEST_DIR)/Makefile.in + $(SHELL) config.status +#tclConfig.h: $(UNIX_DIR)/tclConfig.h.in +# $(SHELL) config.status + +clean: clean-packages + rm -f *.a *.o libtcl* core errs *~ \#* TAGS *.E a.out \ + errors ${TCL_EXE} ${TCLTEST_EXE} lib.exp Tcl @DTRACE_HDR@ + cd dltest ; $(MAKE) clean + +distclean: distclean-packages clean + rm -rf Makefile config.status config.cache config.log tclConfig.sh \ + tclConfig.h *.plist Tcl.framework tcl.pc + cd dltest ; $(MAKE) distclean + +depend: + makedepend -- $(DEPEND_SWITCHES) -- $(SRCS) + +#-------------------------------------------------------------------------- +# The following target outputs the name of the top-level source directory for +# Tcl (it is used by Tk's configure script, for example). The .NO_PARALLEL +# line is needed to avoid problems under Sun's "pmake". Note: this target is +# now obsolete (use the autoconf variable TCL_SRC_DIR from tclConfig.sh +# instead). +#-------------------------------------------------------------------------- + +.NO_PARALLEL: topDirName +topDirName: + @cd $(TOP_DIR); pwd + +#-------------------------------------------------------------------------- +# Rules for testing +#-------------------------------------------------------------------------- + # Resetting the LIB_RUNTIME_DIR below is required so that the generated # tcltest executable gets the build directory burned into its ld search path. # This keeps tcltest from picking up an already installed version of the Tcl # library. +SHELL_ENV = @LD_LIBRARY_PATH_VAR@=`pwd`:${@LD_LIBRARY_PATH_VAR@} \ + TCLLIBPATH="@abs_builddir@/pkgs" \ + TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}" -tcltest@EXEEXT@: ${TCLTEST_OBJS} ${TCL_LIB_FILE} ${BUILD_DLTEST} +${TCLTEST_EXE}: ${TCLTEST_OBJS} ${TCL_LIB_FILE} ${TCL_STUB_LIB_FILE} ${BUILD_DLTEST} $(MAKE) tcltest-real LIB_RUNTIME_DIR="`pwd`" tcltest-real: - ${CC} ${CFLAGS} ${LDFLAGS} ${TCLTEST_OBJS} @TCL_BUILD_LIB_SPEC@ ${LIBS} @EXTRA_TCLSH_LIBS@ \ - ${CC_SEARCH_FLAGS} -o tcltest@EXEEXT@ + ${CC} ${CFLAGS} ${LDFLAGS} ${TCLTEST_OBJS} \ + @TCL_BUILD_LIB_SPEC@ ${TCL_STUB_LIB_FILE} ${LIBS} @EXTRA_TCLSH_LIBS@ \ + ${CC_SEARCH_FLAGS} -o ${TCLTEST_EXE} # Note, in the targets below TCL_LIBRARY needs to be set or else "make test" # won't work in the case where the compilation directory isn't the same as the @@ -591,108 +694,72 @@ tcltest-real: # tcltest, ie: # % make test TESTFLAGS="-verbose bps -file fileName.test" -test: tcltest@EXEEXT@ - @LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - ./tcltest@EXEEXT@ $(TOP_DIR)/tests/all.tcl $(TESTFLAGS) +test: test-tcl test-packages -gdb-test: tcltest@EXEEXT@ - @echo "set env @LD_LIBRARY_PATH_VAR@=\"`pwd`:$${@LD_LIBRARY_PATH_VAR@}\"" > gdb.run +test-tcl: ${TCLTEST_EXE} + $(SHELL_ENV) ./${TCLTEST_EXE} $(TOP_DIR)/tests/all.tcl $(TESTFLAGS) + +gdb-test: ${TCLTEST_EXE} + @echo "set env @LD_LIBRARY_PATH_VAR@=`pwd`:$${@LD_LIBRARY_PATH_VAR@}" > gdb.run @echo "set env TCL_LIBRARY=${TCL_BUILDTIME_LIBRARY}" >> gdb.run @echo "set args $(TOP_DIR)/tests/all.tcl $(TESTFLAGS) -singleproc 1" >> gdb.run - $(GDB) ./tcltest@EXEEXT@ --command=gdb.run + $(GDB) ./${TCLTEST_EXE} --command=gdb.run rm gdb.run # Useful target to launch a built tcltest with the proper path,... -runtest: tcltest@EXEEXT@ - @LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - ./tcltest@EXEEXT@ +runtest: ${TCLTEST_EXE} + $(SHELL_ENV) ./${TCLTEST_EXE} # Useful target for running the test suite with an unwritable current # directory... -ro-test: tcltest@EXEEXT@ - @LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - echo 'exec chmod -w .;package require tcltest;tcltest::temporaryDirectory /tmp;source ../tests/all.tcl;exec chmod +w .' | ./tcltest@EXEEXT@ +ro-test: ${TCLTEST_EXE} + echo 'exec chmod -w .;package require tcltest;tcltest::temporaryDirectory /tmp;source ../tests/all.tcl;exec chmod +w .' | $(SHELL_ENV) ./${TCLTEST_EXE} + +# The following target generates the shared libraries in dltest/ that are used +# for testing; they are included as part of the "tcltest" target (via the +# BUILD_DLTEST variable) if dynamic loading is supported on this platform. The +# Makefile in the dltest subdirectory creates the dltest.marker file in this +# directory after a successful build. + +dltest.marker: ${STUB_LIB_FILE} + cd dltest ; $(MAKE) + +#-------------------------------------------------------------------------- +# Rules for running a shell before installation +#-------------------------------------------------------------------------- # This target can be used to run tclsh from the build directory # via `make shell SCRIPT=/tmp/foo.tcl` shell: ${TCL_EXE} - @LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - ./${TCL_EXE} $(SCRIPT) + $(SHELL_ENV) ./${TCL_EXE} $(SCRIPT) # This target can be used to run tclsh inside either gdb or insight gdb: ${TCL_EXE} - @echo "set env @LD_LIBRARY_PATH_VAR@=\"`pwd`:$${@LD_LIBRARY_PATH_VAR@}\"" > gdb.run - @echo "set env TCL_LIBRARY=${TCL_BUILDTIME_LIBRARY}" >> gdb.run - $(GDB) ./${TCL_EXE} --command=gdb.run - rm gdb.run - -VALGRINDARGS=--tool=memcheck --num-callers=8 --leak-resolution=high --leak-check=yes --show-reachable=yes -v + $(SHELL_ENV) $(GDB) ./${TCL_EXE} -valgrind: ${TCL_EXE} tcltest@EXEEXT@ - @LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - valgrind $(VALGRINDARGS) ./tcltest@EXEEXT@ $(TOP_DIR)/tests/all.tcl -singleproc 1 $(TESTFLAGS) +valgrind: ${TCL_EXE} ${TCLTEST_EXE} + $(SHELL_ENV) $(VALGRIND) $(VALGRINDARGS) ./${TCLTEST_EXE} $(TOP_DIR)/tests/all.tcl -singleproc 1 $(TESTFLAGS) valgrindshell: ${TCL_EXE} - @LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - valgrind $(VALGRINDARGS) ./${TCL_EXE} $(SCRIPT) + $(SHELL_ENV) $(VALGRIND) $(VALGRINDARGS) ./${TCL_EXE} $(SCRIPT) -# The following target outputs the name of the top-level source directory for -# Tcl (it is used by Tk's configure script, for example). The .NO_PARALLEL -# line is needed to avoid problems under Sun's "pmake". Note: this target is -# now obsolete (use the autoconf variable TCL_SRC_DIR from tclConfig.sh -# instead). +trace-shell: ${TCL_EXE} + $(SHELL_ENV) ${TRACE} $(TRACE_OPTS) ./${TCL_EXE} $(SCRIPT) -.NO_PARALLEL: topDirName -topDirName: - @cd $(TOP_DIR); pwd - -# The following target generates the file generic/tclDate.c from the yacc -# grammar found in generic/tclGetDate.y. This is only run by hand as yacc is -# not available in all environments. The name of the .c file is different than -# the name of the .y file so that make doesn't try to automatically regenerate -# the .c file. - -gendate: - bison --output-file=$(GENERIC_DIR)/tclDate.c \ - --no-lines \ - --name-prefix=TclDate \ - $(GENERIC_DIR)/tclGetDate.y - -# yacc -l $(GENERIC_DIR)/tclGetDate.y -# sed -e 's/yy/TclDate/g' -e '/^#include <values.h>/d' \ -# -e 's?SCCSID?RCS: @(#) ?' \ -# -e '/#ifdef __STDC__/,/#endif/d' -e '/TclDateerrlab:/d' \ -# -e '/TclDatenewstate:/d' -e '/#pragma/d' \ -# -e '/#include <inttypes.h>/d' -e 's/const /CONST /g' \ -# -e '/#define YYNEW/s/malloc/TclDateAlloc/g' \ -# -e '/#define YYENLARGE/,/realloc/s/realloc/TclDateRealloc/g' \ -# <y.tab.c >$(GENERIC_DIR)/tclDate.c -# rm y.tab.c - -# The following target generates the file generic/tclTomMath.h. It needs to be -# run (and the results checked) after updating to a new release of libtommath. - -gentommath_h: - $(TCL_EXE) "$(TOOL_DIR)/fix_tommath_h.tcl" \ - "$(TOMMATH_DIR)/tommath.h" \ - > "$(GENERIC_DIR)/tclTomMath.h" +trace-test: ${TCLTEST_EXE} + $(SHELL_ENV) ${TRACE} $(TRACE_OPTS) ./${TCLTEST_EXE} $(TOP_DIR)/tests/all.tcl -singleproc 1 $(TESTFLAGS) -# The following target generates the shared libraries in dltest/ that are used -# for testing; they are included as part of the "tcltest" target (via the -# BUILD_DLTEST variable) if dynamic loading is supported on this platform. The -# Makefile in the dltest subdirectory creates the dltest.marker file in this -# directory after a successful build. - -dltest.marker: ${STUB_LIB_FILE} - cd dltest ; $(MAKE) +#-------------------------------------------------------------------------- +# Installation rules +#-------------------------------------------------------------------------- -INSTALL_TARGETS = install-binaries install-libraries install-doc @EXTRA_INSTALL@ +INSTALL_BASE_TARGETS = install-binaries install-libraries install-msgs $(INSTALL_TZDATA) +INSTALL_DOC_TARGETS = install-doc +INSTALL_PACKAGE_TARGETS = install-packages +INSTALL_DEV_TARGETS = install-headers +INSTALL_EXTRA_TARGETS = @EXTRA_INSTALL@ +INSTALL_TARGETS = $(INSTALL_BASE_TARGETS) $(INSTALL_DOC_TARGETS) $(INSTALL_DEV_TARGETS) \ + $(INSTALL_PACKAGE_TARGETS) $(INSTALL_EXTRA_TARGETS) install: $(INSTALL_TARGETS) @@ -711,71 +778,60 @@ install-binaries: binaries do \ if [ ! -d "$$i" ] ; then \ echo "Making directory $$i"; \ - mkdir -p "$$i"; \ - chmod 755 "$$i"; \ + $(INSTALL_DATA_DIR) "$$i"; \ else true; \ fi; \ done; - @if test ! -x $(SRC_DIR)/../unix/install-sh; then \ - chmod +x $(SRC_DIR)/../unix/install-sh; \ - fi - @echo "Installing $(LIB_FILE) to $(LIB_INSTALL_DIR)/" + @echo "Installing $(LIB_FILE) to @DLL_INSTALL_DIR@/" @@INSTALL_LIB@ - @chmod 555 "$(LIB_INSTALL_DIR)"/$(LIB_FILE) - @echo "Installing ${TCL_EXE} as $(BIN_INSTALL_DIR)/tclsh$(VERSION)@EXEEXT@" - @$(INSTALL_PROGRAM) ${TCL_EXE} "$(BIN_INSTALL_DIR)"/tclsh$(VERSION)@EXEEXT@ + @chmod 555 "@DLL_INSTALL_DIR@"/$(LIB_FILE) + @echo "Installing ${TCL_EXE} as $(BIN_INSTALL_DIR)/tclsh$(VERSION)${EXE_SUFFIX}" + @$(INSTALL_PROGRAM) ${TCL_EXE} "$(BIN_INSTALL_DIR)"/tclsh$(VERSION)${EXE_SUFFIX} @echo "Installing tclConfig.sh to $(CONFIG_INSTALL_DIR)/" @$(INSTALL_DATA) tclConfig.sh "$(CONFIG_INSTALL_DIR)"/tclConfig.sh + @echo "Installing tclooConfig.sh to $(CONFIG_INSTALL_DIR)/" + @$(INSTALL_DATA) $(UNIX_DIR)/tclooConfig.sh \ + "$(CONFIG_INSTALL_DIR)"/tclooConfig.sh @if test "$(STUB_LIB_FILE)" != "" ; then \ echo "Installing $(STUB_LIB_FILE) to $(LIB_INSTALL_DIR)/"; \ @INSTALL_STUB_LIB@ ; \ fi @EXTRA_INSTALL_BINARIES@ + @echo "Installing pkg-config file to $(LIB_INSTALL_DIR)/pkgconfig/" + @$(INSTALL_DATA_DIR) $(LIB_INSTALL_DIR)/pkgconfig + @$(INSTALL_DATA) tcl.pc $(LIB_INSTALL_DIR)/pkgconfig/tcl.pc -install-libraries: libraries $(INSTALL_TZDATA) install-msgs - @for i in "$(INCLUDE_INSTALL_DIR)" "$(SCRIPT_INSTALL_DIR)"; \ +install-libraries: libraries + @for i in "$(SCRIPT_INSTALL_DIR)"; \ do \ if [ ! -d "$$i" ] ; then \ echo "Making directory $$i"; \ - mkdir -p "$$i"; \ - chmod 755 "$$i"; \ + $(INSTALL_DATA_DIR) "$$i"; \ else true; \ fi; \ done; - @for i in opt0.4 http1.0 encoding ../tcl8 ../tcl8/8.3 ../tcl8/8.4 ../tcl8/8.4/platform ../tcl8/8.5; \ + @for i in opt0.4 http1.0 encoding ../tcl8 ../tcl8/8.3 ../tcl8/8.4 ../tcl8/8.4/platform ../tcl8/8.5 ../tcl8/8.6; \ do \ if [ ! -d "$(SCRIPT_INSTALL_DIR)"/$$i ] ; then \ echo "Making directory $(SCRIPT_INSTALL_DIR)/$$i"; \ - mkdir -p "$(SCRIPT_INSTALL_DIR)"/$$i; \ - chmod 755 "$(SCRIPT_INSTALL_DIR)"/$$i; \ + $(INSTALL_DATA_DIR) "$(SCRIPT_INSTALL_DIR)"/$$i; \ else true; \ fi; \ done; - @if test ! -x $(SRC_DIR)/../unix/install-sh; then \ - chmod +x $(SRC_DIR)/../unix/install-sh; \ - fi - @echo "Installing header files"; - @for i in $(GENERIC_DIR)/tcl.h $(GENERIC_DIR)/tclDecls.h \ - $(GENERIC_DIR)/tclPlatDecls.h \ - $(GENERIC_DIR)/tclTomMath.h \ - $(GENERIC_DIR)/tclTomMathDecls.h ; \ - do \ - $(INSTALL_DATA) $$i "$(INCLUDE_INSTALL_DIR)"; \ - done; - @echo "Installing library files to $(SCRIPT_INSTALL_DIR)"; + @echo "Installing library files to $(SCRIPT_INSTALL_DIR)/"; @for i in $(TOP_DIR)/library/*.tcl $(TOP_DIR)/library/tclIndex \ $(UNIX_DIR)/tclAppInit.c @LDAIX_SRC@ @DTRACE_SRC@; \ do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"; \ done; - @echo "Installing library http1.0 directory"; + @echo "Installing package http1.0 files to $(SCRIPT_INSTALL_DIR)/http1.0/"; @for i in $(TOP_DIR)/library/http1.0/*.tcl ; \ do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/http1.0; \ done; - @echo "Installing package http 2.7.6 as a Tcl Module"; - @$(INSTALL_DATA) $(TOP_DIR)/library/http/http.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.4/http-2.7.6.tm; - @echo "Installing library opt0.4 directory"; + @echo "Installing package http 2.8.2 as a Tcl Module"; + @$(INSTALL_DATA) $(TOP_DIR)/library/http/http.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.6/http-2.8.2.tm; + @echo "Installing package opt0.4 files to $(SCRIPT_INSTALL_DIR)/opt0.4/"; @for i in $(TOP_DIR)/library/opt/*.tcl ; \ do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/opt0.4; \ @@ -790,7 +846,7 @@ install-libraries: libraries $(INSTALL_TZDATA) install-msgs @echo "Installing package platform::shell 1.1.4 as a Tcl Module"; @$(INSTALL_DATA) $(TOP_DIR)/library/platform/shell.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.4/platform/shell-1.1.4.tm; - @echo "Installing library encoding directory"; + @echo "Installing library encoding files to $(SCRIPT_INSTALL_DIR)/encoding/"; @for i in $(TOP_DIR)/library/encoding/*.enc ; do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/encoding; \ done; @@ -800,27 +856,31 @@ install-libraries: libraries $(INSTALL_TZDATA) install-msgs "$(SCRIPT_INSTALL_DIR)"/tm.tcl; \ fi -install-tzdata: ${TCL_EXE} +install-tzdata: ${NATIVE_TCLSH} @echo "Installing time zone data" - @@LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - ./${TCL_EXE} $(TOOL_DIR)/installData.tcl \ + @${NATIVE_TCLSH} $(TOOL_DIR)/installData.tcl \ $(TOP_DIR)/library/tzdata "$(SCRIPT_INSTALL_DIR)"/tzdata -install-msgs: ${TCL_EXE} - @echo "Installing message catalogs" - @@LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - ./${TCL_EXE} $(TOOL_DIR)/installData.tcl \ - $(TOP_DIR)/library/msgs "$(SCRIPT_INSTALL_DIR)"/msgs +install-msgs: + @for i in msgs; \ + do \ + if [ ! -d "$(SCRIPT_INSTALL_DIR)"/$$i ] ; then \ + echo "Making directory $(SCRIPT_INSTALL_DIR)/$$i"; \ + $(INSTALL_DATA_DIR) "$(SCRIPT_INSTALL_DIR)"/$$i; \ + else true; \ + fi; \ + done; + @echo "Installing message catalog files to $(SCRIPT_INSTALL_DIR)/msgs/" + @for i in $(TOP_DIR)/library/msgs/*.msg ; do \ + $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/msgs; \ + done; install-doc: doc @for i in "$(MAN_INSTALL_DIR)" "$(MAN1_INSTALL_DIR)" "$(MAN3_INSTALL_DIR)" "$(MANN_INSTALL_DIR)" ; \ do \ if [ ! -d "$$i" ] ; then \ echo "Making directory $$i"; \ - mkdir -p "$$i"; \ - chmod 755 "$$i"; \ + $(INSTALL_DATA_DIR) "$$i"; \ else true; \ fi; \ done; @@ -839,23 +899,39 @@ install-doc: doc $(SHELL) $(UNIX_DIR)/installManPage $(MAN_FLAGS) $$i "$(MANN_INSTALL_DIR)"; \ done +install-headers: + @for i in "$(INCLUDE_INSTALL_DIR)"; \ + do \ + if [ ! -d "$$i" ] ; then \ + echo "Making directory $$i"; \ + $(INSTALL_DATA_DIR) "$$i"; \ + else true; \ + fi; \ + done; + @echo "Installing header files to $(INCLUDE_INSTALL_DIR)/"; + @for i in $(GENERIC_DIR)/tcl.h $(GENERIC_DIR)/tclDecls.h \ + $(GENERIC_DIR)/tclOO.h $(GENERIC_DIR)/tclOODecls.h \ + $(GENERIC_DIR)/tclPlatDecls.h \ + $(GENERIC_DIR)/tclTomMath.h \ + $(GENERIC_DIR)/tclTomMathDecls.h ; \ + do \ + $(INSTALL_DATA) $$i "$(INCLUDE_INSTALL_DIR)"; \ + done; + # Optional target to install private headers -install-private-headers: libraries +install-private-headers: @for i in "$(PRIVATE_INCLUDE_INSTALL_DIR)"; \ do \ if [ ! -d "$$i" ] ; then \ echo "Making directory $$i"; \ - mkdir -p "$$i"; \ - chmod 755 "$$i"; \ + $(INSTALL_DATA_DIR) "$$i"; \ else true; \ fi; \ done; - @if test ! -x $(SRC_DIR)/../unix/install-sh; then \ - chmod +x $(SRC_DIR)/../unix/install-sh; \ - fi - @echo "Installing private header files"; + @echo "Installing private header files to $(PRIVATE_INCLUDE_INSTALL_DIR)/"; @for i in $(GENERIC_DIR)/tclInt.h $(GENERIC_DIR)/tclIntDecls.h \ $(GENERIC_DIR)/tclIntPlatDecls.h $(GENERIC_DIR)/tclPort.h \ + $(GENERIC_DIR)/tclOOInt.h $(GENERIC_DIR)/tclOOIntDecls.h \ $(UNIX_DIR)/tclUnixPort.h; \ do \ $(INSTALL_DATA) $$i "$(PRIVATE_INCLUDE_INSTALL_DIR)"; \ @@ -864,23 +940,9 @@ install-private-headers: libraries $(INSTALL_DATA) tclConfig.h "$(PRIVATE_INCLUDE_INSTALL_DIR)"; \ fi; -Makefile: $(UNIX_DIR)/Makefile.in $(DLTEST_DIR)/Makefile.in - $(SHELL) config.status -#tclConfig.h: $(UNIX_DIR)/tclConfig.h.in -# $(SHELL) config.status - -clean: - rm -f *.a *.o libtcl* core errs *~ \#* TAGS *.E a.out \ - errors ${TCL_EXE} tcltest@EXEEXT@ lib.exp Tcl @DTRACE_HDR@ - cd dltest ; $(MAKE) clean - -distclean: clean - rm -rf Makefile config.status config.cache config.log tclConfig.sh \ - $(PACKAGE).* prototype tclConfig.h *.plist Tcl.framework - cd dltest ; $(MAKE) distclean - -depend: - makedepend -- $(DEPEND_SWITCHES) -- $(SRCS) +#-------------------------------------------------------------------------- +# Rules for how to compile C files +#-------------------------------------------------------------------------- # Test binaries. The rules for tclTestInit.o and xtTestInit.o are complicated # because they are compiled from tclAppInit.c. Can't use the "-o" option @@ -928,6 +990,7 @@ COMPILEHDR=$(GENERIC_DIR)/tclCompile.h FSHDR=$(GENERIC_DIR)/tclFileSystem.h IOHDR=$(GENERIC_DIR)/tclIO.h MATHHDRS=$(GENERIC_DIR)/tommath.h $(GENERIC_DIR)/tclTomMath.h +NREHDR=$(GENERIC_DIR)/tclInt.h regcomp.o: $(REGHDRS) $(GENERIC_DIR)/regcomp.c $(GENERIC_DIR)/regc_lex.c \ $(GENERIC_DIR)/regc_color.c $(GENERIC_DIR)/regc_locale.c \ @@ -949,10 +1012,13 @@ tclAppInit.o: $(UNIX_DIR)/tclAppInit.c tclAlloc.o: $(GENERIC_DIR)/tclAlloc.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclAlloc.c +tclAssembly.o: $(GENERIC_DIR)/tclAssembly.c $(COMPILEHDR) + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclAssembly.c + tclAsync.o: $(GENERIC_DIR)/tclAsync.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclAsync.c -tclBasic.o: $(GENERIC_DIR)/tclBasic.c $(COMPILEHDR) $(MATHHDRS) +tclBasic.o: $(GENERIC_DIR)/tclBasic.c $(COMPILEHDR) $(MATHHDRS) $(NREHDR) $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclBasic.c tclBinary.o: $(GENERIC_DIR)/tclBinary.c @@ -979,6 +1045,9 @@ tclDate.o: $(GENERIC_DIR)/tclDate.c tclCompCmds.o: $(GENERIC_DIR)/tclCompCmds.c $(COMPILEHDR) $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclCompCmds.c +tclCompCmdsSZ.o: $(GENERIC_DIR)/tclCompCmdsSZ.c $(COMPILEHDR) + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclCompCmdsSZ.c + tclCompExpr.o: $(GENERIC_DIR)/tclCompExpr.c $(COMPILEHDR) $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclCompExpr.c @@ -994,13 +1063,16 @@ tclDictObj.o: $(GENERIC_DIR)/tclDictObj.c $(MATHHDRS) tclEncoding.o: $(GENERIC_DIR)/tclEncoding.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclEncoding.c +tclEnsemble.o: $(GENERIC_DIR)/tclEnsemble.c $(COMPILEHDR) + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclEnsemble.c + tclEnv.o: $(GENERIC_DIR)/tclEnv.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclEnv.c tclEvent.o: $(GENERIC_DIR)/tclEvent.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclEvent.c -tclExecute.o: $(GENERIC_DIR)/tclExecute.c $(COMPILEHDR) $(MATHHDRS) +tclExecute.o: $(GENERIC_DIR)/tclExecute.c $(COMPILEHDR) $(MATHHDRS) $(NREHDR) $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclExecute.c tclFCmd.o: $(GENERIC_DIR)/tclFCmd.c @@ -1042,6 +1114,9 @@ tclIOUtil.o: $(GENERIC_DIR)/tclIOUtil.c $(FSHDR) tclIORChan.o: $(GENERIC_DIR)/tclIORChan.c $(IOHDR) $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclIORChan.c +tclIORTrans.o: $(GENERIC_DIR)/tclIORTrans.c $(IOHDR) + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclIORTrans.c + tclLink.o: $(GENERIC_DIR)/tclLink.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclLink.c @@ -1084,12 +1159,33 @@ tclLoadShl.o: $(UNIX_DIR)/tclLoadShl.c tclMain.o: $(GENERIC_DIR)/tclMain.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclMain.c -tclNamesp.o: $(GENERIC_DIR)/tclNamesp.c +tclNamesp.o: $(GENERIC_DIR)/tclNamesp.c $(COMPILEHDR) $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclNamesp.c tclNotify.o: $(GENERIC_DIR)/tclNotify.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclNotify.c +tclOO.o: $(GENERIC_DIR)/tclOO.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclOO.c + +tclOOBasic.o: $(GENERIC_DIR)/tclOOBasic.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclOOBasic.c + +tclOOCall.o: $(GENERIC_DIR)/tclOOCall.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclOOCall.c + +tclOODefineCmds.o: $(GENERIC_DIR)/tclOODefineCmds.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclOODefineCmds.c + +tclOOInfo.o: $(GENERIC_DIR)/tclOOInfo.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclOOInfo.c + +tclOOMethod.o: $(GENERIC_DIR)/tclOOMethod.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclOOMethod.c + +tclOOStubInit.o: $(GENERIC_DIR)/tclOOStubInit.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclOOStubInit.c + tclParse.o: $(GENERIC_DIR)/tclParse.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclParse.c @@ -1135,7 +1231,7 @@ tclPosixStr.o: $(GENERIC_DIR)/tclPosixStr.c tclPreserve.o: $(GENERIC_DIR)/tclPreserve.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclPreserve.c -tclProc.o: $(GENERIC_DIR)/tclProc.c $(COMPILEHDR) +tclProc.o: $(GENERIC_DIR)/tclProc.c $(COMPILEHDR) $(NREHDR) $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclProc.c tclRegexp.o: $(GENERIC_DIR)/tclRegexp.c $(TCLREHDRS) @@ -1171,6 +1267,9 @@ tclUtf.o: $(GENERIC_DIR)/tclUtf.c $(GENERIC_DIR)/tclUniData.c tclVar.o: $(GENERIC_DIR)/tclVar.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclVar.c +tclZlib.o: $(GENERIC_DIR)/tclZlib.c + $(CC) -c $(ZLIB_INCLUDE) $(CC_SWITCHES) $(GENERIC_DIR)/tclZlib.c + tclTest.o: $(GENERIC_DIR)/tclTest.c $(IOHDR) $(TCLREHDRS) $(CC) -c $(APP_CC_SWITCHES) $(GENERIC_DIR)/tclTest.c @@ -1451,14 +1550,15 @@ $(DTRACE_HDR): $(DTRACE_SRC) $(DTRACE_OBJ): $(DTRACE_SRC) $(TCL_OBJS) $(DTRACE) -G $(DTRACE_SWITCHES) -o $@ -s $(DTRACE_SRC) $(TCL_OBJS) +#-------------------------------------------------------------------------- # The following targets are not completely general. They are provide purely # for documentation purposes so people who are interested in the Xt based # notifier can modify them to suit their own installation. +#-------------------------------------------------------------------------- -xttest: ${XTTEST_OBJS} ${GENERIC_OBJS} ${UNIX_OBJS} ${COMPAT_OBJS} \ - @DL_OBJS@ ${BUILD_DLTEST} - ${CC} ${XTTEST_OBJS} ${GENERIC_OBJS} ${UNIX_OBJS} ${COMPAT_OBJS} \ - @DL_OBJS@ @TCL_BUILD_LIB_SPEC@ ${LIBS} \ +xttest: ${XTTEST_OBJS} ${TCL_LIB_FILE} ${TCL_STUB_LIB_FILE} ${BUILD_DLTEST} + ${CC} ${CFLAGS} ${LDFLAGS} ${XTTEST_OBJS} \ + @TCL_BUILD_LIB_SPEC@ ${TCL_STUB_LIB_FILE} ${LIBS} @EXTRA_TCLSH_LIBS@ \ ${CC_SEARCH_FLAGS} -L/usr/openwin/lib -lXt -o xttest tclXtNotify.o: $(UNIX_DIR)/tclXtNotify.c @@ -1469,10 +1569,12 @@ tclXtTest.o: $(UNIX_DIR)/tclXtTest.c $(CC) -c $(APP_CC_SWITCHES) -I/usr/openwin/include \ $(UNIX_DIR)/tclXtTest.c +#-------------------------------------------------------------------------- # Compat binaries, these must be compiled for use in a shared library even # though they may be placed in a static executable or library. Since they are # included in both the tcl library and the stub library, they need to be # relocatable. +#-------------------------------------------------------------------------- fixstrtod.o: $(COMPAT_DIR)/fixstrtod.c $(CC) -c $(STUB_CC_SWITCHES) $(COMPAT_DIR)/fixstrtod.c @@ -1480,6 +1582,9 @@ fixstrtod.o: $(COMPAT_DIR)/fixstrtod.c opendir.o: $(COMPAT_DIR)/opendir.c $(CC) -c $(STUB_CC_SWITCHES) $(COMPAT_DIR)/opendir.c +mkstemp.o: $(COMPAT_DIR)/mkstemp.c + $(CC) -c $(STUB_CC_SWITCHES) $(COMPAT_DIR)/mkstemp.c + memcmp.o: $(COMPAT_DIR)/memcmp.c $(CC) -c $(STUB_CC_SWITCHES) $(COMPAT_DIR)/memcmp.c @@ -1501,15 +1606,190 @@ strtoul.o: $(COMPAT_DIR)/strtoul.c waitpid.o: $(COMPAT_DIR)/waitpid.c $(CC) -c $(STUB_CC_SWITCHES) $(COMPAT_DIR)/waitpid.c +fake-rfc2553.o: $(COMPAT_DIR)/fake-rfc2553.c + $(CC) -c $(STUB_CC_SWITCHES) $(COMPAT_DIR)/fake-rfc2553.c + +# For building zlib, only used in some build configurations +Zadler32.o: $(ZLIB_DIR)/adler32.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/adler32.c +Zcompress.o: $(ZLIB_DIR)/compress.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/compress.c +Zcrc32.o: $(ZLIB_DIR)/crc32.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/crc32.c +Zdeflate.o: $(ZLIB_DIR)/deflate.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/deflate.c +Zinfback.o: $(ZLIB_DIR)/infback.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/infback.c +Zinffast.o: $(ZLIB_DIR)/inffast.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/inffast.c +Zinflate.o: $(ZLIB_DIR)/inflate.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/inflate.c +Zinftrees.o: $(ZLIB_DIR)/inftrees.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/inftrees.c +Ztrees.o: $(ZLIB_DIR)/trees.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/trees.c +Zuncompr.o: $(ZLIB_DIR)/uncompr.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/uncompr.c +Zzutil.o: $(ZLIB_DIR)/zutil.c + $(CC) -c -o $@ $(CC_SWITCHES) -I$(ZLIB_DIR) $(ZLIB_DIR)/zutil.c + +#-------------------------------------------------------------------------- # Stub library binaries, these must be compiled for use in a shared library # even though they will be placed in a static archive +#-------------------------------------------------------------------------- tclStubLib.o: $(GENERIC_DIR)/tclStubLib.c $(CC) -c $(STUB_CC_SWITCHES) $(GENERIC_DIR)/tclStubLib.c +tclTomMathStubLib.o: $(GENERIC_DIR)/tclTomMathStubLib.c + $(CC) -c $(STUB_CC_SWITCHES) $(GENERIC_DIR)/tclTomMathStubLib.c + +tclOOStubLib.o: $(GENERIC_DIR)/tclOOStubLib.c + $(CC) -c $(STUB_CC_SWITCHES) $(GENERIC_DIR)/tclOOStubLib.c + .c.o: $(CC) -c $(CC_SWITCHES) $< +#-------------------------------------------------------------------------- +# Bundled Package targets +#-------------------------------------------------------------------------- + +# Propagate configure args like --enable-64bit to package configure +PKG_CFG_ARGS = @PKG_CFG_ARGS@ +# If PKG_DIR is changed to a different relative depth to the build dir, need +# to adapt the ../.. relative paths below and at the top of configure.in (we +# cannot use absolute paths due to issues in nested configure when path to +# build dir contains spaces). +PKG_DIR = ./pkgs + +configure-packages: + @for i in $(PKGS_DIR)/*; do \ + if [ -d $$i ]; then \ + if [ -x $$i/configure ]; then \ + pkg=`basename $$i`; \ + echo "Configuring package '$$pkg'"; \ + mkdir -p $(PKG_DIR)/$$pkg; \ + if [ ! -f $(PKG_DIR)/$$pkg/Makefile ]; then \ + ( cd $(PKG_DIR)/$$pkg; \ + $$i/configure --with-tcl=../.. \ + --with-tclinclude=$(GENERIC_DIR) \ + $(PKG_CFG_ARGS) --libdir=$(PACKAGE_DIR) \ + --enable-shared --enable-threads; ) || exit $$?; \ + fi; \ + fi; \ + fi; \ + done + +packages: configure-packages ${STUB_LIB_FILE} + @for i in $(PKGS_DIR)/*; do \ + if [ -d $$i ]; then \ + pkg=`basename $$i`; \ + if [ -f $(PKG_DIR)/$$pkg/Makefile ]; then \ + echo "Building package '$$pkg'"; \ + ( cd $(PKG_DIR)/$$pkg; $(MAKE) --no-print-directory; ) || exit $$?; \ + fi; \ + fi; \ + done + +install-packages: packages + @for i in $(PKGS_DIR)/*; do \ + if [ -d $$i ]; then \ + pkg=`basename $$i`; \ + if [ -f $(PKG_DIR)/$$pkg/Makefile ]; then \ + echo "Installing package '$$pkg'"; \ + ( cd $(PKG_DIR)/$$pkg; $(MAKE) --no-print-directory install \ + "DESTDIR=$(INSTALL_ROOT)"; ) || exit $$?; \ + fi; \ + fi; \ + done + +test-packages: tcltest packages + @for i in $(PKGS_DIR)/*; do \ + if [ -d $$i ]; then \ + pkg=`basename $$i`; \ + if [ -f $(PKG_DIR)/$$pkg/Makefile ]; then \ + echo ""; \ + echo ""; \ + echo "Testing package '$$pkg'"; \ + ( cd $(PKG_DIR)/$$pkg; $(MAKE) --no-print-directory \ + "@LD_LIBRARY_PATH_VAR@=../..:$${@LD_LIBRARY_PATH_VAR@}" \ + "TCL_LIBRARY=${TCL_BUILDTIME_LIBRARY}" \ + "TCLLIBPATH=../../pkgs" test \ + "TCLSH_PROG=../../${TCLTEST_EXE}"; ) \ + fi; \ + fi; \ + done + +clean-packages: + @for i in $(PKGS_DIR)/*; do \ + if [ -d $$i ]; then \ + pkg=`basename $$i`; \ + if [ -f $(PKG_DIR)/$$pkg/Makefile ]; then \ + ( cd $(PKG_DIR)/$$pkg; $(MAKE) --no-print-directory clean; ) \ + fi; \ + fi; \ + done + +distclean-packages: + @for i in $(PKGS_DIR)/*; do \ + if [ -d $$i ]; then \ + pkg=`basename $$i`; \ + if [ -f $(PKG_DIR)/$$pkg/Makefile ]; then \ + ( cd $(PKG_DIR)/$$pkg; $(MAKE) --no-print-directory distclean; ) \ + fi; \ + rm -rf $(PKG_DIR)/$$pkg; \ + fi; \ + done; \ + rm -rf $(PKG_DIR) + +dist-packages: configure-packages + @rm -rf $(DISTROOT)/pkgs; \ + mkdir -p $(DISTROOT)/pkgs; \ + for i in $(PKGS_DIR)/*; do \ + if [ -d $$i ]; then \ + pkg=`basename $$i`; \ + if [ -f $(PKG_DIR)/$$pkg/Makefile ]; then \ + ( cd $(PKG_DIR)/$$pkg; $(MAKE) --no-print-directory dist \ + "DIST_ROOT=$(DISTROOT)/pkgs"; ) || exit $$?; \ + fi; \ + fi; \ + done + +#-------------------------------------------------------------------------- +# Maintainer-only targets +#-------------------------------------------------------------------------- + +# The following target generates the file generic/tclDate.c from the yacc +# grammar found in generic/tclGetDate.y. This is only run by hand as yacc is +# not available in all environments. The name of the .c file is different than +# the name of the .y file so that make doesn't try to automatically regenerate +# the .c file. + +gendate: + bison --output-file=$(GENERIC_DIR)/tclDate.c \ + --no-lines \ + --name-prefix=TclDate \ + $(GENERIC_DIR)/tclGetDate.y + +# yacc -l $(GENERIC_DIR)/tclGetDate.y +# sed -e 's/yy/TclDate/g' -e '/^#include <values.h>/d' \ +# -e 's?SCCSID?RCS: @(#) ?' \ +# -e '/#ifdef __STDC__/,/#endif/d' -e '/TclDateerrlab:/d' \ +# -e '/TclDatenewstate:/d' -e '/#pragma/d' \ +# -e '/#include <inttypes.h>/d' -e 's/const /CONST /g' \ +# -e '/#define YYNEW/s/malloc/TclDateAlloc/g' \ +# -e '/#define YYENLARGE/,/realloc/s/realloc/TclDateRealloc/g' \ +# <y.tab.c >$(GENERIC_DIR)/tclDate.c +# rm y.tab.c + +# The following target generates the file generic/tclTomMath.h. It needs to be +# run (and the results checked) after updating to a new release of libtommath. + +gentommath_h: + $(NATIVE_TCLSH) "$(TOOL_DIR)/fix_tommath_h.tcl" \ + "$(TOMMATH_DIR)/tommath.h" \ + > "$(GENERIC_DIR)/tclTomMath.h" + # # Target to regenerate header files and stub files from the *.decls tables. # @@ -1520,10 +1800,17 @@ $(GENERIC_DIR)/tclStubInit.c: $(GENERIC_DIR)/tcl.decls \ @echo "Developers may want to run \"make genstubs\" to regenerate." @echo "This warning can be safely ignored, do not report as a bug!" +$(GENERIC_DIR)/tclOOStubInit.c: $(GENERIC_DIR)/tclOO.decls + @echo "Warning: tclOOStubInit.c may be out of date." + @echo "Developers may want to run \"make genstubs\" to regenerate." + @echo "This warning can be safely ignored, do not report as a bug!" + genstubs: - $(TCL_EXE) $(TOOL_DIR)/genStubs.tcl $(GENERIC_DIR) \ + $(NATIVE_TCLSH) $(TOOL_DIR)/genStubs.tcl $(GENERIC_DIR) \ $(GENERIC_DIR)/tcl.decls $(GENERIC_DIR)/tclInt.decls \ $(GENERIC_DIR)/tclTomMath.decls + $(NATIVE_TCLSH) $(TOOL_DIR)/genStubs.tcl $(GENERIC_DIR) \ + $(GENERIC_DIR)/tclOO.decls # # Target to check that all exported functions have an entry in the stubs @@ -1576,6 +1863,10 @@ checkexports: $(TCL_LIB_FILE) | awk '$$2 ~ /^[TDBCS]$$/ { sub("^_", "", $$3); print $$3 }' \ | sort -n | grep -E -v '^[Tt]cl' || true +#-------------------------------------------------------------------------- +# Distribution building rules +#-------------------------------------------------------------------------- + # # Target to create a Tcl RPM for Linux. Requires that you be on a Linux # system. @@ -1609,7 +1900,7 @@ $(MAC_OSX_DIR)/configure: $(MAC_OSX_DIR)/configure.ac $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in: $(MAC_OSX_DIR)/configure cd $(MAC_OSX_DIR); autoheader; touch $@ -dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(MAC_OSX_DIR)/configure genstubs +dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(UNIX_DIR)/tcl.pc.in $(MAC_OSX_DIR)/configure genstubs dist-packages ${NATIVE_TCLSH} rm -rf $(DISTDIR) mkdir -p $(DISTDIR)/unix cp -p $(UNIX_DIR)/*.[ch] $(DISTDIR)/unix @@ -1617,10 +1908,11 @@ dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(MAC_OSX_DIR)/configure chmod 664 $(DISTDIR)/unix/Makefile.in cp $(UNIX_DIR)/configure $(UNIX_DIR)/configure.in \ $(UNIX_DIR)/tcl.m4 $(UNIX_DIR)/aclocal.m4 \ - $(UNIX_DIR)/tclConfig.sh.in $(UNIX_DIR)/install-sh \ + $(UNIX_DIR)/tclConfig.sh.in $(UNIX_DIR)/tclooConfig.sh \ + $(UNIX_DIR)/install-sh \ $(UNIX_DIR)/README $(UNIX_DIR)/ldAix $(UNIX_DIR)/tcl.spec \ $(UNIX_DIR)/installManPage $(UNIX_DIR)/tclConfig.h.in \ - $(DISTDIR)/unix + $(UNIX_DIR)/tcl.pc.in $(DISTDIR)/unix chmod 775 $(DISTDIR)/unix/configure $(DISTDIR)/unix/configure.in chmod 775 $(DISTDIR)/unix/ldAix chmod +x $(DISTDIR)/unix/install-sh @@ -1654,6 +1946,11 @@ dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(MAC_OSX_DIR)/configure mkdir $(DISTDIR)/compat cp -p $(TOP_DIR)/license.terms $(COMPAT_DIR)/*.[ch] \ $(COMPAT_DIR)/README $(DISTDIR)/compat + mkdir $(DISTDIR)/compat/zlib + ( cd $(COMPAT_DIR)/zlib; \ + find . -name CVS -prune -o -type f -print ) \ + | ( cd $(COMPAT_DIR)/zlib ; xargs tar cf - ) \ + | ( cd $(DISTDIR)/compat/zlib ; tar xfp - ) mkdir $(DISTDIR)/tests cp -p $(TOP_DIR)/license.terms $(DISTDIR)/tests cp -p $(TOP_DIR)/tests/*.test $(TOP_DIR)/tests/README \ @@ -1662,23 +1959,23 @@ dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(MAC_OSX_DIR)/configure mkdir $(DISTDIR)/win cp $(TOP_DIR)/win/Makefile.in $(DISTDIR)/win cp $(TOP_DIR)/win/configure.in $(TOP_DIR)/win/configure \ - $(TOP_DIR)/win/tclConfig.sh.in \ + $(TOP_DIR)/win/tclConfig.sh.in $(TOP_DIR)/win/tclooConfig.sh \ $(TOP_DIR)/win/tcl.m4 $(TOP_DIR)/win/aclocal.m4 \ $(DISTDIR)/win cp -p $(TOP_DIR)/win/*.[ch] $(TOP_DIR)/win/*.ico $(TOP_DIR)/win/*.rc \ $(DISTDIR)/win cp -p $(TOP_DIR)/win/*.bat $(DISTDIR)/win - $(TCL_EXE) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/*.bat + $(NATIVE_TCLSH) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/*.bat cp -p $(TOP_DIR)/win/makefile.* $(DISTDIR)/win - $(TCL_EXE) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/makefile.* + $(NATIVE_TCLSH) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/makefile.* cp -p $(TOP_DIR)/win/rules.vc $(DISTDIR)/win - $(TCL_EXE) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/rules.vc + $(NATIVE_TCLSH) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/rules.vc cp -p $(TOP_DIR)/win/coffbase.txt $(DISTDIR)/win - $(TCL_EXE) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/coffbase.txt + $(NATIVE_TCLSH) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/coffbase.txt cp -p $(TOP_DIR)/win/tcl.hpj.in $(DISTDIR)/win - $(TCL_EXE) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/tcl.hpj.in + $(NATIVE_TCLSH) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/tcl.hpj.in cp -p $(TOP_DIR)/win/tcl.ds* $(DISTDIR)/win - $(TCL_EXE) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/tcl.ds* + $(NATIVE_TCLSH) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/win/tcl.ds* cp -p $(TOP_DIR)/win/README $(DISTDIR)/win cp -p $(TOP_DIR)/license.terms $(DISTDIR)/win mkdir $(DISTDIR)/macosx @@ -1687,12 +1984,14 @@ dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(MAC_OSX_DIR)/configure $(MAC_OSX_DIR)/*.ac $(MAC_OSX_DIR)/*.xcconfig \ $(MAC_OSX_DIR)/configure $(DISTDIR)/macosx cp -p $(TOP_DIR)/license.terms $(DISTDIR)/macosx - mkdir $(DISTDIR)/macosx/Tcl.pbproj - cp -p $(MAC_OSX_DIR)/Tcl.pbproj/*.pbx* $(DISTDIR)/macosx/Tcl.pbproj mkdir $(DISTDIR)/macosx/Tcl.xcode - cp -p $(MAC_OSX_DIR)/Tcl.xcode/*.pbx* $(DISTDIR)/macosx/Tcl.xcode + cp -p $(MAC_OSX_DIR)/Tcl.xcode/project.pbxproj \ + $(MAC_OSX_DIR)/Tcl.xcode/default.pbxuser \ + $(DISTDIR)/macosx/Tcl.xcode mkdir $(DISTDIR)/macosx/Tcl.xcodeproj - cp -p $(TOP_DIR)/macosx/Tcl.xcodeproj/*.pbx* $(DISTDIR)/macosx/Tcl.xcodeproj + cp -p $(MAC_OSX_DIR)/Tcl.xcodeproj/project.pbxproj \ + $(MAC_OSX_DIR)/Tcl.xcodeproj/default.pbxuser \ + $(DISTDIR)/macosx/Tcl.xcodeproj mkdir $(DISTDIR)/unix/dltest cp -p $(UNIX_DIR)/dltest/*.c $(UNIX_DIR)/dltest/Makefile.in \ $(UNIX_DIR)/dltest/README \ @@ -1704,116 +2003,64 @@ dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(MAC_OSX_DIR)/configure $(TOOL_DIR)/tcl.wse.in $(TOOL_DIR)/*.bmp \ $(TOOL_DIR)/tcl.hpj.in \ $(DISTDIR)/tools - $(TCL_EXE) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/tools/tcl.hpj.in \ + $(NATIVE_TCLSH) $(TOOL_DIR)/eolFix.tcl -crlf $(DISTDIR)/tools/tcl.hpj.in \ $(DISTDIR)/tools/tcl.wse.in mkdir $(DISTDIR)/libtommath cp -p $(TOMMATH_SRCS) $(TOMMATH_DIR)/*.h \ $(DISTDIR)/libtommath + mkdir $(DISTDIR)/pkgs + cp $(TOP_DIR)/pkgs/README $(DISTDIR)/pkgs + for i in `ls $(DISTROOT)/pkgs/*.tar.gz 2> /dev/null`; do \ + tar -C $(DISTDIR)/pkgs -xzf "$$i"; \ + done alldist: dist rm -f $(DISTROOT)/$(DISTNAME)-src.tar.gz $(DISTROOT)/$(ZIPNAME) cd $(DISTROOT); tar cf $(DISTNAME)-src.tar $(DISTNAME); \ gzip -9 $(DISTNAME)-src.tar; zip -qr8 $(ZIPNAME) $(DISTNAME) -# +#-------------------------------------------------------------------------- # This target creates the HTML folder for Tcl & Tk and places it in # DISTDIR/html. It uses the tcltk-man2html.tcl tool from the Tcl group's tool # workspace. It depends on the Tcl & Tk being in directories called tcl8.* & # tk8.* up two directories from the TOOL_DIR. # +# Note that for platforms where this is important, it is more common to use a +# build of this HTML documentation that has already been placed online. As +# such, this rule is not guaranteed to work well on all systems; it only needs +# to function on those of the Tcl/Tk maintainers. +#-------------------------------------------------------------------------- -html: ${TCL_EXE} +html: ${NATIVE_TCLSH} $(BUILD_HTML) @EXTRA_BUILD_HTML@ -html-tcl: ${TCL_EXE} +html-tcl: ${NATIVE_TCLSH} $(BUILD_HTML) --tcl @EXTRA_BUILD_HTML@ -html-tk: ${TCL_EXE} +html-tk: ${NATIVE_TCLSH} $(BUILD_HTML) --tk @EXTRA_BUILD_HTML@ BUILD_HTML = \ - @@LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \ - TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \ - ./${TCL_EXE} $(TOOL_DIR)/tcltk-man2html.tcl --htmldir="$(HTML_INSTALL_DIR)" \ + @${NATIVE_TCLSH} $(TOOL_DIR)/tcltk-man2html.tcl \ + --htmldir="$(HTML_INSTALL_DIR)" \ --srcdir=$(TOP_DIR)/.. $(BUILD_HTML_FLAGS) -# -# Targets to build Solaris package of the distribution for the current -# architecture. To build stream packages for both sun4 and i86pc -# architectures: -# -# On the sun4 machine, execute the following: -# make distclean; ./configure -# make DISTDIR=<distdir> package -# -# Once the build is complete, execute the following on the i86pc machine: -# make DISTDIR=<distdir> package-quick -# -# <distdir> is the absolute path to a directory where the build should take -# place. These steps will generate the $(PACKAGE).sun4 and $(PACKAGE).i86pc -# stream packages. It is important that the packages be built in this fashion -# in order to ensure that the architecture independent files are exactly the -# same, including timestamps, in both packages. -# - -PACKAGE=SCRPtcl - -package: dist package-config package-common package-binaries package-generate -package-quick: package-config package-binaries package-generate - -# -# Configure for the current architecture in the dist directory. -# -package-config: - mkdir -p $(DISTDIR)/unix/`arch` - cd $(DISTDIR)/unix/`arch`; \ - ../configure --prefix=/opt/$(PACKAGE)/$(VERSION) \ - --exec_prefix=/opt/$(PACKAGE)/$(VERSION)/`arch` \ - --enable-shared - mkdir -p $(DISTDIR)/$(PACKAGE)/$(VERSION) - mkdir -p $(DISTDIR)/$(PACKAGE)/$(VERSION)/`arch` - -# -# Build and install the architecture independent files in the dist directory. -# - -package-common: - cd $(DISTDIR)/unix/`arch`;\ - $(MAKE); \ - $(MAKE) prefix=$(DISTDIR)/$(PACKAGE)/$(VERSION) \ - exec_prefix=$(DISTDIR)/$(PACKAGE)/$(VERSION)/`arch` \ - install-libraries install-man - mkdir -p $(DISTDIR)/$(PACKAGE)/$(VERSION)/bin - sed -e "s/TCLVERSION/$(VERSION)/g" < $(UNIX_DIR)/tclsh.sh \ - > $(DISTDIR)/$(PACKAGE)/$(VERSION)/bin/tclsh$(VERSION) - chmod 755 $(DISTDIR)/$(PACKAGE)/$(VERSION)/bin/tclsh$(VERSION) - -# -# Build and install the architecture specific files in the dist directory. -# - -package-binaries: - cd $(DISTDIR)/unix/`arch`; \ - $(MAKE); \ - $(MAKE) install-binaries prefix=$(DISTDIR)/$(PACKAGE)/$(VERSION) \ - exec_prefix=$(DISTDIR)/$(PACKAGE)/$(VERSION)/`arch` - -# -# Generate a package from the installed files in the dist directory for the -# current architecture. -# +#-------------------------------------------------------------------------- +# The list of all the targets that do not correspond to real files. This stops +# 'make' from getting confused when someone makes an error in a rule. +#-------------------------------------------------------------------------- -package-generate: - pkgproto $(DISTDIR)/$(PACKAGE)/$(VERSION)/bin=bin \ - $(DISTDIR)/$(PACKAGE)/$(VERSION)/include=include \ - $(DISTDIR)/$(PACKAGE)/$(VERSION)/lib=lib \ - $(DISTDIR)/$(PACKAGE)/$(VERSION)/man=man \ - $(DISTDIR)/$(PACKAGE)/$(VERSION)/`arch`=`arch` \ - | $(TCL_EXE) $(UNIX_DIR)/mkProto.tcl \ - $(VERSION) $(UNIX_DIR) > prototype - pkgmk -o -d . -f prototype -a `arch` - pkgtrans -s . $(PACKAGE).`arch` $(PACKAGE) - rm -rf $(PACKAGE) +.PHONY: all binaries libraries objs doc html html-tcl html-tk test runtest +.PHONY: install install-strip install-binaries install-libraries +.PHONY: install-headers install-private-headers install-doc +.PHONY: clean distclean depend genstubs checkstubs checkexports checkuchar +.PHONY: shell gdb valgrind valgrindshell dist alldist rpm +.PHONY: tclLibObjs tcltest-real test-tcl gdb-test ro-test trace-test xttest +.PHONY: topDirName gendate gentommath_h trace-shell checkdoc +.PHONY: install-tzdata install-msgs +.PHONY: packages configure-packages test-packages clean-packages +.PHONY: dist-packages distclean-packages install-packages +#-------------------------------------------------------------------------- # DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/unix/configure b/unix/configure index aa792a7..72d704d 100755 --- a/unix/configure +++ b/unix/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for tcl 8.5. +# Generated by GNU Autoconf 2.59 for tcl 8.6. # # Copyright (C) 2003 Free Software Foundation, Inc. # This configure script is free software; the Free Software Foundation @@ -267,8 +267,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='tcl' PACKAGE_TARNAME='tcl' -PACKAGE_VERSION='8.5' -PACKAGE_STRING='tcl 8.5' +PACKAGE_VERSION='8.6' +PACKAGE_STRING='tcl 8.6' PACKAGE_BUGREPORT='' # Factoring default headers for most tests. @@ -308,7 +308,7 @@ ac_includes_default="\ # include <unistd.h> #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAN_FLAGS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP TCL_THREADS RANLIB ac_ct_RANLIB AR ac_ct_AR TCL_LIBS DL_LIBS DL_OBJS PLAT_OBJS PLAT_SRCS LDAIX_SRC CFLAGS_DEBUG CFLAGS_OPTIMIZE CFLAGS_WARNING LDFLAGS_DEBUG LDFLAGS_OPTIMIZE CC_SEARCH_FLAGS LD_SEARCH_FLAGS STLIB_LD SHLIB_LD TCL_SHLIB_LD_EXTRAS TK_SHLIB_LD_EXTRAS SHLIB_LD_LIBS SHLIB_CFLAGS SHLIB_SUFFIX MAKE_LIB MAKE_STUB_LIB INSTALL_LIB INSTALL_STUB_LIB CFLAGS_DEFAULT LDFLAGS_DEFAULT LIBOBJS DTRACE TCL_VERSION TCL_MAJOR_VERSION TCL_MINOR_VERSION TCL_PATCH_LEVEL TCL_YEAR TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC TCL_STUB_LIB_PATH TCL_INCLUDE_SPEC TCL_BUILD_STUB_LIB_SPEC TCL_BUILD_STUB_LIB_PATH TCL_SRC_DIR CFG_TCL_SHARED_LIB_SUFFIX CFG_TCL_UNSHARED_LIB_SUFFIX TCL_SHARED_BUILD LD_LIBRARY_PATH_VAR TCL_BUILD_LIB_SPEC TCL_LIB_VERSIONS_OK TCL_SHARED_LIB_SUFFIX TCL_UNSHARED_LIB_SUFFIX TCL_HAS_LONGLONG INSTALL_TZDATA DTRACE_SRC DTRACE_HDR DTRACE_OBJ MAKEFILE_SHELL BUILD_DLTEST TCL_PACKAGE_PATH TCL_MODULE_PATH TCL_LIBRARY PRIVATE_INCLUDE_DIR HTML_DIR EXTRA_CC_SWITCHES EXTRA_APP_CC_SWITCHES EXTRA_INSTALL EXTRA_INSTALL_BINARIES EXTRA_BUILD_HTML EXTRA_TCLSH_LIBS DLTEST_LD DLTEST_SUFFIX' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAN_FLAGS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP TCL_THREADS TCLSH_PROG ZLIB_DIR ZLIB_OBJS ZLIB_SRCS ZLIB_INCLUDE RANLIB ac_ct_RANLIB AR ac_ct_AR LIBOBJS TCL_LIBS DL_LIBS DL_OBJS PLAT_OBJS PLAT_SRCS LDAIX_SRC CFLAGS_DEBUG CFLAGS_OPTIMIZE CFLAGS_WARNING LDFLAGS_DEBUG LDFLAGS_OPTIMIZE CC_SEARCH_FLAGS LD_SEARCH_FLAGS STLIB_LD SHLIB_LD TCL_SHLIB_LD_EXTRAS TK_SHLIB_LD_EXTRAS SHLIB_LD_LIBS SHLIB_CFLAGS SHLIB_SUFFIX MAKE_LIB MAKE_STUB_LIB INSTALL_LIB DLL_INSTALL_DIR INSTALL_STUB_LIB CFLAGS_DEFAULT LDFLAGS_DEFAULT DTRACE TCL_VERSION TCL_MAJOR_VERSION TCL_MINOR_VERSION TCL_PATCH_LEVEL TCL_YEAR PKG_CFG_ARGS TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC TCL_STUB_LIB_PATH TCL_INCLUDE_SPEC TCL_BUILD_STUB_LIB_SPEC TCL_BUILD_STUB_LIB_PATH TCL_SRC_DIR CFG_TCL_SHARED_LIB_SUFFIX CFG_TCL_UNSHARED_LIB_SUFFIX TCL_SHARED_BUILD LD_LIBRARY_PATH_VAR TCL_BUILD_LIB_SPEC TCL_LIB_VERSIONS_OK TCL_SHARED_LIB_SUFFIX TCL_UNSHARED_LIB_SUFFIX TCL_HAS_LONGLONG INSTALL_TZDATA DTRACE_SRC DTRACE_HDR DTRACE_OBJ MAKEFILE_SHELL BUILD_DLTEST TCL_PACKAGE_PATH TCL_MODULE_PATH TCL_LIBRARY PRIVATE_INCLUDE_DIR HTML_DIR PACKAGE_DIR EXTRA_CC_SWITCHES EXTRA_APP_CC_SWITCHES EXTRA_INSTALL EXTRA_INSTALL_BINARIES EXTRA_BUILD_HTML EXTRA_TCLSH_LIBS DLTEST_LD DLTEST_SUFFIX' ac_subst_files='' # Initialize some variables set by options. @@ -777,7 +777,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures tcl 8.5 to adapt to many kinds of systems. +\`configure' configures tcl 8.6 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -834,7 +834,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of tcl 8.5:";; + short | recursive ) echo "Configuration of tcl 8.6:";; esac cat <<\_ACEOF @@ -848,7 +848,7 @@ Optional Features: use STRING as a suffix to manpage file names (default: no, tcl if enabled without specifying STRING) - --enable-threads build with threads (default: off) + --enable-threads build with threads (default: on) --enable-shared build and link with shared libraries (default: on) --enable-64bit enable 64bit support (default: off) --enable-64bit-vis enable 64bit Sparc VIS support (default: off) @@ -978,7 +978,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -tcl configure 8.5 +tcl configure 8.6 generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -992,7 +992,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by tcl $as_me 8.5, which was +It was created by tcl $as_me 8.6, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -1332,13 +1332,27 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -TCL_VERSION=8.5 +TCL_VERSION=8.6 TCL_MAJOR_VERSION=8 -TCL_MINOR_VERSION=5 -TCL_PATCH_LEVEL=".10" +TCL_MINOR_VERSION=6 +TCL_PATCH_LEVEL="b2" VERSION=${TCL_VERSION} #------------------------------------------------------------------------ +# Setup configure arguments for bundled packages +#------------------------------------------------------------------------ + +PKG_CFG_ARGS="$ac_configure_args ${PKG_CFG_ARGS}" + +if test -r "$cache_file" -a -f "$cache_file"; then + case $cache_file in + [\\/]* | ?:[\\/]* ) pkg_cache_file=$cache_file ;; + *) pkg_cache_file=../../$cache_file ;; + esac + PKG_CFG_ARGS="${PKG_CFG_ARGS} --cache-file=$pkg_cache_file" +fi + +#------------------------------------------------------------------------ # Handle the --prefix=... option #------------------------------------------------------------------------ @@ -4301,6 +4315,12 @@ done +#-------------------------------------------------------------------- +# Determines the correct executable file extension (.exe) +#-------------------------------------------------------------------- + + + #------------------------------------------------------------------------ # If we're using GCC, see if the compiler understands -pipe. If so, use it. # It makes compiling go faster. (This is only a performance feature.) @@ -4378,7 +4398,7 @@ if test "${enable_threads+set}" = set; then enableval="$enable_threads" tcl_ok=$enableval else - tcl_ok=no + tcl_ok=yes fi; if test "${TCL_THREADS}" = 1; then @@ -4793,9 +4813,6 @@ echo "$as_me: WARNING: Don't know how to find pthread lib on your system - you m # Does the pthread-implementation provide # 'pthread_attr_setstacksize' ? - ac_saved_libs=$LIBS - LIBS="$LIBS $THREADS_LIBS" - for ac_func in pthread_attr_setstacksize do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` @@ -4897,385 +4914,6 @@ _ACEOF fi done - echo "$as_me:$LINENO: checking for pthread_attr_get_np" >&5 -echo $ECHO_N "checking for pthread_attr_get_np... $ECHO_C" >&6 -if test "${ac_cv_func_pthread_attr_get_np+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define pthread_attr_get_np to an innocuous variant, in case <limits.h> declares pthread_attr_get_np. - For example, HP-UX 11i <limits.h> declares gettimeofday. */ -#define pthread_attr_get_np innocuous_pthread_attr_get_np - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char pthread_attr_get_np (); below. - Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - <limits.h> exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif - -#undef pthread_attr_get_np - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -{ -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char pthread_attr_get_np (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_pthread_attr_get_np) || defined (__stub___pthread_attr_get_np) -choke me -#else -char (*f) () = pthread_attr_get_np; -#endif -#ifdef __cplusplus -} -#endif - -int -main () -{ -return f != pthread_attr_get_np; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_pthread_attr_get_np=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_func_pthread_attr_get_np=no -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_func_pthread_attr_get_np" >&5 -echo "${ECHO_T}$ac_cv_func_pthread_attr_get_np" >&6 -if test $ac_cv_func_pthread_attr_get_np = yes; then - tcl_ok=yes -else - tcl_ok=no -fi - - if test $tcl_ok = yes ; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_PTHREAD_ATTR_GET_NP 1 -_ACEOF - - echo "$as_me:$LINENO: checking for pthread_attr_get_np declaration" >&5 -echo $ECHO_N "checking for pthread_attr_get_np declaration... $ECHO_C" >&6 -if test "${tcl_cv_grep_pthread_attr_get_np+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <pthread.h> - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "pthread_attr_get_np" >/dev/null 2>&1; then - tcl_cv_grep_pthread_attr_get_np=present -else - tcl_cv_grep_pthread_attr_get_np=missing -fi -rm -f conftest* - -fi -echo "$as_me:$LINENO: result: $tcl_cv_grep_pthread_attr_get_np" >&5 -echo "${ECHO_T}$tcl_cv_grep_pthread_attr_get_np" >&6 - if test $tcl_cv_grep_pthread_attr_get_np = missing ; then - -cat >>confdefs.h <<\_ACEOF -#define ATTRGETNP_NOT_DECLARED 1 -_ACEOF - - fi - else - echo "$as_me:$LINENO: checking for pthread_getattr_np" >&5 -echo $ECHO_N "checking for pthread_getattr_np... $ECHO_C" >&6 -if test "${ac_cv_func_pthread_getattr_np+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define pthread_getattr_np to an innocuous variant, in case <limits.h> declares pthread_getattr_np. - For example, HP-UX 11i <limits.h> declares gettimeofday. */ -#define pthread_getattr_np innocuous_pthread_getattr_np - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char pthread_getattr_np (); below. - Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - <limits.h> exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif - -#undef pthread_getattr_np - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -{ -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char pthread_getattr_np (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_pthread_getattr_np) || defined (__stub___pthread_getattr_np) -choke me -#else -char (*f) () = pthread_getattr_np; -#endif -#ifdef __cplusplus -} -#endif - -int -main () -{ -return f != pthread_getattr_np; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_pthread_getattr_np=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_func_pthread_getattr_np=no -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_func_pthread_getattr_np" >&5 -echo "${ECHO_T}$ac_cv_func_pthread_getattr_np" >&6 -if test $ac_cv_func_pthread_getattr_np = yes; then - tcl_ok=yes -else - tcl_ok=no -fi - - if test $tcl_ok = yes ; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_PTHREAD_GETATTR_NP 1 -_ACEOF - - echo "$as_me:$LINENO: checking for pthread_getattr_np declaration" >&5 -echo $ECHO_N "checking for pthread_getattr_np declaration... $ECHO_C" >&6 -if test "${tcl_cv_grep_pthread_getattr_np+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <pthread.h> - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "pthread_getattr_np" >/dev/null 2>&1; then - tcl_cv_grep_pthread_getattr_np=present -else - tcl_cv_grep_pthread_getattr_np=missing -fi -rm -f conftest* - -fi -echo "$as_me:$LINENO: result: $tcl_cv_grep_pthread_getattr_np" >&5 -echo "${ECHO_T}$tcl_cv_grep_pthread_getattr_np" >&6 - if test $tcl_cv_grep_pthread_getattr_np = missing ; then - -cat >>confdefs.h <<\_ACEOF -#define GETATTRNP_NOT_DECLARED 1 -_ACEOF - - fi - fi - fi - if test $tcl_ok = no; then - # Darwin thread stacksize API - -for ac_func in pthread_get_stacksize_np -do -as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$as_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func. - For example, HP-UX 11i <limits.h> declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - <limits.h> exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif - -#undef $ac_func - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -{ -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -char (*f) () = $ac_func; -#endif -#ifdef __cplusplus -} -#endif - -int -main () -{ -return f != $ac_func; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_var=no" -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 -if test `eval echo '${'$as_ac_var'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - fi - LIBS=$ac_saved_libs else TCL_THREADS=0 fi @@ -5296,8 +4934,8 @@ echo "${ECHO_T}yes (threaded core)" >&6 echo "${ECHO_T}yes" >&6 fi else - echo "$as_me:$LINENO: result: no (default)" >&5 -echo "${ECHO_T}no (default)" >&6 + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 fi @@ -6301,6 +5939,417 @@ _ACEOF #-------------------------------------------------------------------- +# Look for a native installed tclsh binary (if available) +# If one cannot be found then use the binary we build (fails for +# cross compiling). This is used for NATIVE_TCLSH in Makefile. +#-------------------------------------------------------------------- + + + echo "$as_me:$LINENO: checking for tclsh" >&5 +echo $ECHO_N "checking for tclsh... $ECHO_C" >&6 + if test "${ac_cv_path_tclsh+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + search_path=`echo ${PATH} | sed -e 's/:/ /g'` + for dir in $search_path ; do + for j in `ls -r $dir/tclsh[8-9]* 2> /dev/null` \ + `ls -r $dir/tclsh* 2> /dev/null` ; do + if test x"$ac_cv_path_tclsh" = x ; then + if test -f "$j" ; then + ac_cv_path_tclsh=$j + break + fi + fi + done + done + +fi + + + if test -f "$ac_cv_path_tclsh" ; then + TCLSH_PROG="$ac_cv_path_tclsh" + echo "$as_me:$LINENO: result: $TCLSH_PROG" >&5 +echo "${ECHO_T}$TCLSH_PROG" >&6 + else + # It is not an error if an installed version of Tcl can't be located. + TCLSH_PROG="" + echo "$as_me:$LINENO: result: No tclsh found on PATH" >&5 +echo "${ECHO_T}No tclsh found on PATH" >&6 + fi + + +if test "$TCLSH_PROG" = ""; then + TCLSH_PROG='./${TCL_EXE}' +fi + +#------------------------------------------------------------------------ +# Add stuff for zlib +#------------------------------------------------------------------------ + +zlib_ok=yes +if test "${ac_cv_header_zlib_h+set}" = set; then + echo "$as_me:$LINENO: checking for zlib.h" >&5 +echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6 +if test "${ac_cv_header_zlib_h+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5 +echo "${ECHO_T}$ac_cv_header_zlib_h" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking zlib.h usability" >&5 +echo $ECHO_N "checking zlib.h usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <zlib.h> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking zlib.h presence" >&5 +echo $ECHO_N "checking zlib.h presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <zlib.h> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: zlib.h: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: zlib.h: present but cannot be compiled" >&5 +echo "$as_me: WARNING: zlib.h: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: zlib.h: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: zlib.h: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: zlib.h: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: zlib.h: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: zlib.h: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: zlib.h: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: zlib.h: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: zlib.h: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: zlib.h: in the future, the compiler will take precedence" >&2;} + ( + cat <<\_ASBOX +## ------------------------------ ## +## Report this to the tcl lists. ## +## ------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for zlib.h" >&5 +echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6 +if test "${ac_cv_header_zlib_h+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_header_zlib_h=$ac_header_preproc +fi +echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5 +echo "${ECHO_T}$ac_cv_header_zlib_h" >&6 + +fi +if test $ac_cv_header_zlib_h = yes; then + + echo "$as_me:$LINENO: checking for gz_header" >&5 +echo $ECHO_N "checking for gz_header... $ECHO_C" >&6 +if test "${ac_cv_type_gz_header+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <zlib.h> + +int +main () +{ +if ((gz_header *) 0) + return 0; +if (sizeof (gz_header)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_gz_header=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_gz_header=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_gz_header" >&5 +echo "${ECHO_T}$ac_cv_type_gz_header" >&6 +if test $ac_cv_type_gz_header = yes; then + : +else + zlib_ok=no +fi + +else + + zlib_ok=no +fi + + +if test $zlib_ok = yes; then + + echo "$as_me:$LINENO: checking for library containing deflateSetHeader" >&5 +echo $ECHO_N "checking for library containing deflateSetHeader... $ECHO_C" >&6 +if test "${ac_cv_search_deflateSetHeader+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_func_search_save_LIBS=$LIBS +ac_cv_search_deflateSetHeader=no +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char deflateSetHeader (); +int +main () +{ +deflateSetHeader (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_deflateSetHeader="none required" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +if test "$ac_cv_search_deflateSetHeader" = no; then + for ac_lib in z; do + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char deflateSetHeader (); +int +main () +{ +deflateSetHeader (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_deflateSetHeader="-l$ac_lib" +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + done +fi +LIBS=$ac_func_search_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_search_deflateSetHeader" >&5 +echo "${ECHO_T}$ac_cv_search_deflateSetHeader" >&6 +if test "$ac_cv_search_deflateSetHeader" != no; then + test "$ac_cv_search_deflateSetHeader" = "none required" || LIBS="$ac_cv_search_deflateSetHeader $LIBS" + +else + + zlib_ok=no + +fi + +fi + +if test $zlib_ok = no; then + + ZLIB_DIR=\${COMPAT_DIR}/zlib + + ZLIB_OBJS=\${ZLIB_OBJS} + + ZLIB_SRCS=\${ZLIB_SRCS} + + ZLIB_INCLUDE=-I\${ZLIB_DIR} + + +fi + + +cat >>confdefs.h <<\_ACEOF +#define HAVE_ZLIB 1 +_ACEOF + + +#-------------------------------------------------------------------- # The statements below define a collection of compile flags. This # macro depends on the value of SHARED_BUILD, and should be called # after SC_ENABLE_SHARED checks the configure switches. @@ -6430,6 +6479,80 @@ if test "${tcl_cv_cc_visibility_hidden+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else + if test "$SHARED_BUILD" = 1; then + + hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -fvisibility=hidden -Werror" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#if !defined(__GNUC__) || __GNUC__ < 4 +#error visibility hidden is not supported for this compiler +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + tcl_cv_cc_visibility_hidden=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +tcl_cv_cc_visibility_hidden=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS=$hold_cflags + +else + + tcl_cv_cc_visibility_hidden=no + +fi + + +fi +echo "$as_me:$LINENO: result: $tcl_cv_cc_visibility_hidden" >&5 +echo "${ECHO_T}$tcl_cv_cc_visibility_hidden" >&6 + if test $tcl_cv_cc_visibility_hidden = yes; then + + CFLAGS="$CFLAGS -fvisibility=hidden" + +cat >>confdefs.h <<\_ACEOF +#define MODULE_SCOPE extern +_ACEOF + + +else + hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror" cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ @@ -6480,10 +6603,7 @@ fi rm -f conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext CFLAGS=$hold_cflags -fi -echo "$as_me:$LINENO: result: $tcl_cv_cc_visibility_hidden" >&5 -echo "${ECHO_T}$tcl_cv_cc_visibility_hidden" >&6 - if test $tcl_cv_cc_visibility_hidden = yes; then + if test $tcl_cv_cc_visibility_hidden = yes; then cat >>confdefs.h <<\_ACEOF @@ -6494,6 +6614,9 @@ _ACEOF fi +fi + + # Step 0.d: Disable -rpath support? echo "$as_me:$LINENO: checking if rpath support is requested" >&5 @@ -6620,10 +6743,6 @@ fi # Require ranlib early so we can override it in special cases below. - if test x"${SHLIB_VERSION}" = x; then - SHLIB_VERSION="1.0" -fi - @@ -6642,13 +6761,16 @@ fi ECHO_VERSION='`echo ${VERSION}`' TCL_LIB_VERSIONS_OK=ok CFLAGS_DEBUG=-g - CFLAGS_OPTIMIZE=-O if test "$GCC" = yes; then + CFLAGS_OPTIMIZE=-O2 CFLAGS_WARNING="-Wall" else - CFLAGS_WARNING="" + + CFLAGS_OPTIMIZE=-O + CFLAGS_WARNING="" + fi if test -n "$ac_tool_prefix"; then @@ -6735,6 +6857,10 @@ fi PLAT_OBJS="" PLAT_SRCS="" LDAIX_SRC="" + if test x"${SHLIB_VERSION}" = x; then + SHLIB_VERSION="1.0" +fi + case $system in AIX-*) if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"; then @@ -7134,6 +7260,10 @@ fi SHLIB_LD='${CC} -shared' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} +else + + CFLAGS="$CFLAGS -z" + fi @@ -7266,6 +7396,14 @@ fi SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" + case $LIBOBJS in + "mkstemp.$ac_objext" | \ + *" mkstemp.$ac_objext" | \ + "mkstemp.$ac_objext "* | \ + *" mkstemp.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext" ;; +esac + if test $doRpath = yes; then CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' @@ -7279,6 +7417,14 @@ fi SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" + case $LIBOBJS in + "mkstemp.$ac_objext" | \ + *" mkstemp.$ac_objext" | \ + "mkstemp.$ac_objext "* | \ + *" mkstemp.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext" ;; +esac + if test $doRpath = yes; then CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' @@ -7312,6 +7458,14 @@ fi SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" + case $LIBOBJS in + "mkstemp.$ac_objext" | \ + *" mkstemp.$ac_objext" | \ + "mkstemp.$ac_objext "* | \ + *" mkstemp.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext" ;; +esac + if test $doRpath = yes; then CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' @@ -8013,6 +8167,7 @@ cat >>confdefs.h <<\_ACEOF #define MODULE_SCOPE __private_extern__ _ACEOF + tcl_cv_cc_visibility_hidden=yes fi @@ -8885,6 +9040,22 @@ fi fi + if test "$tcl_cv_cc_visibility_hidden" != yes; then + + +cat >>confdefs.h <<\_ACEOF +#define MODULE_SCOPE extern +_ACEOF + + +cat >>confdefs.h <<\_ACEOF +#define NO_VIZ +_ACEOF + + +fi + + if test "$SHARED_LIB_SUFFIX" = ""; then SHARED_LIB_SUFFIX='${VERSION}${SHLIB_SUFFIX}' @@ -8895,12 +9066,23 @@ fi UNSHARED_LIB_SUFFIX='${VERSION}.a' fi + DLL_INSTALL_DIR="\$(LIB_INSTALL_DIR)" if test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""; then LIB_SUFFIX=${SHARED_LIB_SUFFIX} MAKE_LIB='${SHLIB_LD} -o $@ ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}' - INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)"/$(LIB_FILE)' + if test "${SHLIB_SUFFIX}" = ".dll"; then + + INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)"/$(LIB_FILE)' + DLL_INSTALL_DIR="\$(BIN_INSTALL_DIR)" + +else + + INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)"/$(LIB_FILE)' + +fi + else @@ -8987,6 +9169,7 @@ _ACEOF + echo "$as_me:$LINENO: checking for build with symbols" >&5 echo $ECHO_N "checking for build with symbols... $ECHO_C" >&6 # Check whether --enable-symbols or --disable-symbols was given. @@ -10179,7 +10362,8 @@ done -for ac_func in opendir strtol waitpid + +for ac_func in mkstemp opendir strtol waitpid do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -10798,9 +10982,18 @@ _ACEOF fi -echo "$as_me:$LINENO: checking for getaddrinfo" >&5 -echo $ECHO_N "checking for getaddrinfo... $ECHO_C" >&6 -if test "${ac_cv_func_getaddrinfo+set}" = set; then + + NEED_FAKE_RFC2553=0 + + + + +for ac_func in getnameinfo getaddrinfo freeaddrinfo gai_strerror +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then echo $ECHO_N "(cached) $ECHO_C" >&6 else cat >conftest.$ac_ext <<_ACEOF @@ -10809,12 +11002,12 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -/* Define getaddrinfo to an innocuous variant, in case <limits.h> declares getaddrinfo. +/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func. For example, HP-UX 11i <limits.h> declares gettimeofday. */ -#define getaddrinfo innocuous_getaddrinfo +#define $ac_func innocuous_$ac_func /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char getaddrinfo (); below. + which can conflict with char $ac_func (); below. Prefer <limits.h> to <assert.h> if __STDC__ is defined, since <limits.h> exists even on freestanding compilers. */ @@ -10824,7 +11017,7 @@ cat >>conftest.$ac_ext <<_ACEOF # include <assert.h> #endif -#undef getaddrinfo +#undef $ac_func /* Override any gcc2 internal prototype to avoid an error. */ #ifdef __cplusplus @@ -10833,14 +11026,14 @@ extern "C" #endif /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ -char getaddrinfo (); +char $ac_func (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ -#if defined (__stub_getaddrinfo) || defined (__stub___getaddrinfo) +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) choke me #else -char (*f) () = getaddrinfo; +char (*f) () = $ac_func; #endif #ifdef __cplusplus } @@ -10849,7 +11042,7 @@ char (*f) () = getaddrinfo; int main () { -return f != getaddrinfo; +return f != $ac_func; ; return 0; } @@ -10876,44 +11069,269 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; }; then - ac_cv_func_getaddrinfo=yes + eval "$as_ac_var=yes" else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -ac_cv_func_getaddrinfo=no +eval "$as_ac_var=no" fi rm -f conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi -echo "$as_me:$LINENO: result: $ac_cv_func_getaddrinfo" >&5 -echo "${ECHO_T}$ac_cv_func_getaddrinfo" >&6 -if test $ac_cv_func_getaddrinfo = yes; then +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF - echo "$as_me:$LINENO: checking for working getaddrinfo" >&5 -echo $ECHO_N "checking for working getaddrinfo... $ECHO_C" >&6 -if test "${tcl_cv_api_getaddrinfo+set}" = set; then +else + NEED_FAKE_RFC2553=1 +fi +done + + echo "$as_me:$LINENO: checking for struct addrinfo" >&5 +echo $ECHO_N "checking for struct addrinfo... $ECHO_C" >&6 +if test "${ac_cv_type_struct_addrinfo+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ - cat >conftest.$ac_ext <<_ACEOF +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> + + +int +main () +{ +if ((struct addrinfo *) 0) + return 0; +if (sizeof (struct addrinfo)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_struct_addrinfo=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_struct_addrinfo=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_struct_addrinfo" >&5 +echo "${ECHO_T}$ac_cv_type_struct_addrinfo" >&6 +if test $ac_cv_type_struct_addrinfo = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_ADDRINFO 1 +_ACEOF + + +else + NEED_FAKE_RFC2553=1 +fi +echo "$as_me:$LINENO: checking for struct in6_addr" >&5 +echo $ECHO_N "checking for struct in6_addr... $ECHO_C" >&6 +if test "${ac_cv_type_struct_in6_addr+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ - #include <netdb.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> + + +int +main () +{ +if ((struct in6_addr *) 0) + return 0; +if (sizeof (struct in6_addr)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_struct_in6_addr=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_struct_in6_addr=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_struct_in6_addr" >&5 +echo "${ECHO_T}$ac_cv_type_struct_in6_addr" >&6 +if test $ac_cv_type_struct_in6_addr = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_IN6_ADDR 1 +_ACEOF + + +else + NEED_FAKE_RFC2553=1 +fi +echo "$as_me:$LINENO: checking for struct sockaddr_in6" >&5 +echo $ECHO_N "checking for struct sockaddr_in6... $ECHO_C" >&6 +if test "${ac_cv_type_struct_sockaddr_in6+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> + int main () { +if ((struct sockaddr_in6 *) 0) + return 0; +if (sizeof (struct sockaddr_in6)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_struct_sockaddr_in6=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 - const char *name, *port; - struct addrinfo *aiPtr, hints; - (void)getaddrinfo(name,port, &hints, &aiPtr); - (void)freeaddrinfo(aiPtr); +ac_cv_type_struct_sockaddr_in6=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_struct_sockaddr_in6" >&5 +echo "${ECHO_T}$ac_cv_type_struct_sockaddr_in6" >&6 +if test $ac_cv_type_struct_sockaddr_in6 = yes; then +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_SOCKADDR_IN6 1 +_ACEOF + + +else + NEED_FAKE_RFC2553=1 +fi +echo "$as_me:$LINENO: checking for struct sockaddr_storage" >&5 +echo $ECHO_N "checking for struct sockaddr_storage... $ECHO_C" >&6 +if test "${ac_cv_type_struct_sockaddr_storage+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> + + +int +main () +{ +if ((struct sockaddr_storage *) 0) + return 0; +if (sizeof (struct sockaddr_storage)) + return 0; ; return 0; } @@ -10940,25 +11358,132 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; }; then - tcl_cv_api_getaddrinfo=yes + ac_cv_type_struct_sockaddr_storage=yes else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -tcl_cv_getaddrinfo=no +ac_cv_type_struct_sockaddr_storage=no fi rm -f conftest.err conftest.$ac_objext conftest.$ac_ext fi -echo "$as_me:$LINENO: result: $tcl_cv_api_getaddrinfo" >&5 -echo "${ECHO_T}$tcl_cv_api_getaddrinfo" >&6 - tcl_ok=$tcl_cv_api_getaddrinfo - if test "$tcl_ok" = yes; then +echo "$as_me:$LINENO: result: $ac_cv_type_struct_sockaddr_storage" >&5 +echo "${ECHO_T}$ac_cv_type_struct_sockaddr_storage" >&6 +if test $ac_cv_type_struct_sockaddr_storage = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 +_ACEOF + + +else + NEED_FAKE_RFC2553=1 +fi + +if test "x$NEED_FAKE_RFC2553" = "x1"; then cat >>confdefs.h <<\_ACEOF -#define HAVE_GETADDRINFO 1 +#define NEED_FAKE_RFC2553 1 _ACEOF - fi + case $LIBOBJS in + "fake-rfc2553.$ac_objext" | \ + *" fake-rfc2553.$ac_objext" | \ + "fake-rfc2553.$ac_objext "* | \ + *" fake-rfc2553.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS fake-rfc2553.$ac_objext" ;; +esac + + echo "$as_me:$LINENO: checking for strlcpy" >&5 +echo $ECHO_N "checking for strlcpy... $ECHO_C" >&6 +if test "${ac_cv_func_strlcpy+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define strlcpy to an innocuous variant, in case <limits.h> declares strlcpy. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define strlcpy innocuous_strlcpy + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char strlcpy (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif + +#undef strlcpy + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char strlcpy (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_strlcpy) || defined (__stub___strlcpy) +choke me +#else +char (*f) () = strlcpy; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != strlcpy; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_strlcpy=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_strlcpy=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_strlcpy" >&5 +echo "${ECHO_T}$ac_cv_func_strlcpy" >&6 fi @@ -14113,8 +14638,8 @@ fi #-------------------------------------------------------------------- -# Some system have no memcmp or it does not work with 8 bit -# data, this checks it and add memcmp.o to LIBOBJS if needed +# Some system have no memcmp or it does not work with 8 bit data, this +# checks it and add memcmp.o to LIBOBJS if needed #-------------------------------------------------------------------- echo "$as_me:$LINENO: checking for working memcmp" >&5 @@ -14200,9 +14725,9 @@ esac #-------------------------------------------------------------------- -# Some system like SunOS 4 and other BSD like systems -# have no memmove (we assume they have bcopy instead). -# {The replacement define is in compat/string.h} +# Some system like SunOS 4 and other BSD like systems have no memmove +# (we assume they have bcopy instead). {The replacement define is in +# compat/string.h} #-------------------------------------------------------------------- echo "$as_me:$LINENO: checking for memmove" >&5 @@ -14313,8 +14838,8 @@ fi #-------------------------------------------------------------------- -# On some systems strstr is broken: it returns a pointer even -# even if the original string is empty. +# On some systems strstr is broken: it returns a pointer even even if +# the original string is empty. #-------------------------------------------------------------------- @@ -16703,11 +17228,12 @@ echo "${ECHO_T}$langinfo_ok" >&6 #-------------------------------------------------------------------- -# Check for support of chflags function +# Check for support of chflags and mkstemps functions #-------------------------------------------------------------------- -for ac_func in chflags + +for ac_func in chflags mkstemps do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -17920,7 +18446,7 @@ else fi #-------------------------------------------------------------------- -# Check for support of fts functions (readdir replacement) +# Check for support of fts functions (readdir replacement) #-------------------------------------------------------------------- echo "$as_me:$LINENO: checking for fts" >&5 @@ -17995,10 +18521,9 @@ _ACEOF fi #-------------------------------------------------------------------- -# The statements below check for systems where POSIX-style -# non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented. -# On these systems (mostly older ones), use the old BSD-style -# FIONBIO approach instead. +# The statements below check for systems where POSIX-style non-blocking +# I/O (O_NONBLOCK) doesn't work or is unimplemented. On these systems +# (mostly older ones), use the old BSD-style FIONBIO approach instead. #-------------------------------------------------------------------- @@ -18338,11 +18863,6 @@ echo "${ECHO_T}$tcl_cv_sys_version" >&6 echo "$as_me:$LINENO: checking FIONBIO vs. O_NONBLOCK for nonblocking I/O" >&5 echo $ECHO_N "checking FIONBIO vs. O_NONBLOCK for nonblocking I/O... $ECHO_C" >&6 case $system in - # There used to be code here to use FIONBIO under AIX. However, it - # was reported that FIONBIO doesn't work under AIX 3.2.5. Since - # using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO - # code (JO, 5/31/97). - OSF*) cat >>confdefs.h <<\_ACEOF @@ -18684,79 +19204,6 @@ echo "$as_me:$LINENO: result: $tcl_ok" >&5 echo "${ECHO_T}$tcl_ok" >&6 #-------------------------------------------------------------------- -# Does the C stack grow upwards or downwards? Or cross-compiling? -#-------------------------------------------------------------------- - -echo "$as_me:$LINENO: checking if the C stack grows upwards in memory" >&5 -echo $ECHO_N "checking if the C stack grows upwards in memory... $ECHO_C" >&6 -if test "${tcl_cv_stack_grows_up+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - - if test "$cross_compiling" = yes; then - tcl_cv_stack_grows_up=unknown -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - int StackGrowsUp(int *parent) { - int here; - volatile int result; - if (parent) - result = (&here < parent); - else - result = StackGrowsUp(&here); - return result; - } - int main (int argc, char *argv[]) { - return StackGrowsUp(0); - } - -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - tcl_cv_stack_grows_up=yes -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -tcl_cv_stack_grows_up=no -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -echo "$as_me:$LINENO: result: $tcl_cv_stack_grows_up" >&5 -echo "${ECHO_T}$tcl_cv_stack_grows_up" >&6 -if test $tcl_cv_stack_grows_up = unknown; then - -cat >>confdefs.h <<\_ACEOF -#define TCL_CROSS_COMPILE 1 -_ACEOF - -elif test $tcl_cv_stack_grows_up = yes; then - -cat >>confdefs.h <<\_ACEOF -#define TCL_STACK_GROWS_UP 1 -_ACEOF - -fi - -#-------------------------------------------------------------------- # The statements below define a collection of symbols related to # building libtcl as a shared library instead of a static library. #-------------------------------------------------------------------- @@ -18842,6 +19289,12 @@ _ACEOF ac_config_commands="$ac_config_commands Tcl.framework" LD_LIBRARY_PATH_VAR="DYLD_FRAMEWORK_PATH" + # default install directory for bundled packages + if test "${libdir}" = '${exec_prefix}/lib' -o "`basename ${libdir}`" = 'Frameworks'; then + PACKAGE_DIR="/Library/Tcl" + else + PACKAGE_DIR="$libdir" + fi if test "${libdir}" = '${exec_prefix}/lib'; then # override libdir default libdir="/Library/Frameworks" @@ -18868,6 +19321,8 @@ _ACEOF else # libdir must be a fully qualified path and not ${exec_prefix}/lib eval libdir="$libdir" + # default install directory for bundled packages + PACKAGE_DIR="$libdir" if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then TCL_LIB_FLAG="-ltcl${TCL_VERSION}" else @@ -18989,7 +19444,9 @@ TCL_SHARED_BUILD=${SHARED_BUILD} - ac_config_files="$ac_config_files Makefile:../unix/Makefile.in dltest/Makefile:../unix/dltest/Makefile.in tclConfig.sh:../unix/tclConfig.sh.in" + + + ac_config_files="$ac_config_files Makefile:../unix/Makefile.in dltest/Makefile:../unix/dltest/Makefile.in tclConfig.sh:../unix/tclConfig.sh.in tcl.pc:../unix/tcl.pc.in" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -19371,7 +19828,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by tcl $as_me 8.5, which was +This file was extended by tcl $as_me 8.6, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -19429,7 +19886,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -tcl config.status 8.5 +tcl config.status 8.6 configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" @@ -19543,6 +20000,7 @@ do "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile:../unix/Makefile.in" ;; "dltest/Makefile" ) CONFIG_FILES="$CONFIG_FILES dltest/Makefile:../unix/dltest/Makefile.in" ;; "tclConfig.sh" ) CONFIG_FILES="$CONFIG_FILES tclConfig.sh:../unix/tclConfig.sh.in" ;; + "tcl.pc" ) CONFIG_FILES="$CONFIG_FILES tcl.pc:../unix/tcl.pc.in" ;; "Tcl.framework" ) CONFIG_COMMANDS="$CONFIG_COMMANDS Tcl.framework" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} @@ -19639,10 +20097,16 @@ s,@OBJEXT@,$OBJEXT,;t t s,@CPP@,$CPP,;t t s,@EGREP@,$EGREP,;t t s,@TCL_THREADS@,$TCL_THREADS,;t t +s,@TCLSH_PROG@,$TCLSH_PROG,;t t +s,@ZLIB_DIR@,$ZLIB_DIR,;t t +s,@ZLIB_OBJS@,$ZLIB_OBJS,;t t +s,@ZLIB_SRCS@,$ZLIB_SRCS,;t t +s,@ZLIB_INCLUDE@,$ZLIB_INCLUDE,;t t s,@RANLIB@,$RANLIB,;t t s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t s,@AR@,$AR,;t t s,@ac_ct_AR@,$ac_ct_AR,;t t +s,@LIBOBJS@,$LIBOBJS,;t t s,@TCL_LIBS@,$TCL_LIBS,;t t s,@DL_LIBS@,$DL_LIBS,;t t s,@DL_OBJS@,$DL_OBJS,;t t @@ -19666,16 +20130,17 @@ s,@SHLIB_SUFFIX@,$SHLIB_SUFFIX,;t t s,@MAKE_LIB@,$MAKE_LIB,;t t s,@MAKE_STUB_LIB@,$MAKE_STUB_LIB,;t t s,@INSTALL_LIB@,$INSTALL_LIB,;t t +s,@DLL_INSTALL_DIR@,$DLL_INSTALL_DIR,;t t s,@INSTALL_STUB_LIB@,$INSTALL_STUB_LIB,;t t s,@CFLAGS_DEFAULT@,$CFLAGS_DEFAULT,;t t s,@LDFLAGS_DEFAULT@,$LDFLAGS_DEFAULT,;t t -s,@LIBOBJS@,$LIBOBJS,;t t s,@DTRACE@,$DTRACE,;t t s,@TCL_VERSION@,$TCL_VERSION,;t t s,@TCL_MAJOR_VERSION@,$TCL_MAJOR_VERSION,;t t s,@TCL_MINOR_VERSION@,$TCL_MINOR_VERSION,;t t s,@TCL_PATCH_LEVEL@,$TCL_PATCH_LEVEL,;t t s,@TCL_YEAR@,$TCL_YEAR,;t t +s,@PKG_CFG_ARGS@,$PKG_CFG_ARGS,;t t s,@TCL_LIB_FILE@,$TCL_LIB_FILE,;t t s,@TCL_LIB_FLAG@,$TCL_LIB_FLAG,;t t s,@TCL_LIB_SPEC@,$TCL_LIB_SPEC,;t t @@ -19707,6 +20172,7 @@ s,@TCL_MODULE_PATH@,$TCL_MODULE_PATH,;t t s,@TCL_LIBRARY@,$TCL_LIBRARY,;t t s,@PRIVATE_INCLUDE_DIR@,$PRIVATE_INCLUDE_DIR,;t t s,@HTML_DIR@,$HTML_DIR,;t t +s,@PACKAGE_DIR@,$PACKAGE_DIR,;t t s,@EXTRA_CC_SWITCHES@,$EXTRA_CC_SWITCHES,;t t s,@EXTRA_APP_CC_SWITCHES@,$EXTRA_APP_CC_SWITCHES,;t t s,@EXTRA_INSTALL@,$EXTRA_INSTALL,;t t @@ -20102,3 +20568,4 @@ if test "$no_create" != yes; then $ac_cs_success || { (exit 1); exit 1; } fi + diff --git a/unix/configure.in b/unix/configure.in index 3394369..35eb3e5 100644 --- a/unix/configure.in +++ b/unix/configure.in @@ -3,7 +3,7 @@ dnl This file is an input file used by the GNU "autoconf" program to dnl generate the file "configure", which is run during Tcl installation dnl to configure the system for the local environment. -AC_INIT([tcl],[8.5]) +AC_INIT([tcl],[8.6]) AC_PREREQ(2.59) dnl This is only used when included from macosx/configure.ac @@ -22,13 +22,27 @@ m4_ifdef([SC_USE_CONFIG_HEADERS], [ #endif /* _TCLCONFIG */]) ]) -TCL_VERSION=8.5 +TCL_VERSION=8.6 TCL_MAJOR_VERSION=8 -TCL_MINOR_VERSION=5 -TCL_PATCH_LEVEL=".10" +TCL_MINOR_VERSION=6 +TCL_PATCH_LEVEL="b2" VERSION=${TCL_VERSION} #------------------------------------------------------------------------ +# Setup configure arguments for bundled packages +#------------------------------------------------------------------------ + +PKG_CFG_ARGS="$ac_configure_args ${PKG_CFG_ARGS}" + +if test -r "$cache_file" -a -f "$cache_file"; then + case $cache_file in + [[\\/]]* | ?:[[\\/]]* ) pkg_cache_file=$cache_file ;; + *) pkg_cache_file=../../$cache_file ;; + esac + PKG_CFG_ARGS="${PKG_CFG_ARGS} --cache-file=$pkg_cache_file" +fi + +#------------------------------------------------------------------------ # Handle the --prefix=... option #------------------------------------------------------------------------ @@ -72,6 +86,12 @@ AC_C_INLINE SC_MISSING_POSIX_HEADERS +#-------------------------------------------------------------------- +# Determines the correct executable file extension (.exe) +#-------------------------------------------------------------------- + +AC_EXEEXT + #------------------------------------------------------------------------ # If we're using GCC, see if the compiler understands -pipe. If so, use it. # It makes compiling go faster. (This is only a performance feature.) @@ -112,6 +132,37 @@ LIBS="$LIBS$THREADS_LIBS" SC_ENABLE_SHARED #-------------------------------------------------------------------- +# Look for a native installed tclsh binary (if available) +# If one cannot be found then use the binary we build (fails for +# cross compiling). This is used for NATIVE_TCLSH in Makefile. +#-------------------------------------------------------------------- + +SC_PROG_TCLSH +if test "$TCLSH_PROG" = ""; then + TCLSH_PROG='./${TCL_EXE}' +fi + +#------------------------------------------------------------------------ +# Add stuff for zlib +#------------------------------------------------------------------------ + +zlib_ok=yes +AC_CHECK_HEADER([zlib.h],[ + AC_CHECK_TYPE([gz_header],[],[zlib_ok=no],[#include <zlib.h>])],[ + zlib_ok=no]) +AS_IF([test $zlib_ok = yes], [ + AC_SEARCH_LIBS([deflateSetHeader],[z],[],[ + zlib_ok=no + ])]) +AS_IF([test $zlib_ok = no], [ + AC_SUBST(ZLIB_DIR,[\${COMPAT_DIR}/zlib]) + AC_SUBST(ZLIB_OBJS,[\${ZLIB_OBJS}]) + AC_SUBST(ZLIB_SRCS,[\${ZLIB_SRCS}]) + AC_SUBST(ZLIB_INCLUDE,[-I\${ZLIB_DIR}]) +]) +AC_DEFINE(HAVE_ZLIB, 1, [Is there an installed zlib?]) + +#-------------------------------------------------------------------- # The statements below define a collection of compile flags. This # macro depends on the value of SHARED_BUILD, and should be called # after SC_ENABLE_SHARED checks the configure switches. @@ -149,7 +200,7 @@ AC_CHECK_FUNCS(getcwd, , [AC_DEFINE(USEGETWD, 1, [Is getcwd Posix-compliant?])]) # Nb: if getcwd uses popen and pwd(1) (like SunOS 4) we should really # define USEGETWD even if the posix getcwd exists. Add a test ? -AC_REPLACE_FUNCS(opendir strtol waitpid) +AC_REPLACE_FUNCS(mkstemp opendir strtol waitpid) AC_CHECK_FUNC(strerror, , [AC_DEFINE(NO_STRERROR, 1, [Do we have strerror()])]) AC_CHECK_FUNC(getwd, , [AC_DEFINE(NO_GETWD, 1, [Do we have getwd()])]) AC_CHECK_FUNC(wait3, , [AC_DEFINE(NO_WAIT3, 1, [Do we have wait3()])]) @@ -163,7 +214,7 @@ if test "`uname -s`" = "Darwin" && test "${TCL_THREADS}" = 1 && \ fi AC_CHECK_FUNC(realpath, , [AC_DEFINE(NO_REALPATH, 1, [Do we have realpath()])]) -SC_TCL_GETADDRINFO +SC_TCL_IPV6 #-------------------------------------------------------------------- # Look for thread-safe variants of some library functions. @@ -252,16 +303,16 @@ AC_CHECK_TYPES([blkcnt_t]) AC_CHECK_FUNC(fstatfs, , [AC_DEFINE(NO_FSTATFS, 1, [Do we have fstatfs()?])]) #-------------------------------------------------------------------- -# Some system have no memcmp or it does not work with 8 bit -# data, this checks it and add memcmp.o to LIBOBJS if needed +# Some system have no memcmp or it does not work with 8 bit data, this +# checks it and add memcmp.o to LIBOBJS if needed #-------------------------------------------------------------------- AC_FUNC_MEMCMP #-------------------------------------------------------------------- -# Some system like SunOS 4 and other BSD like systems -# have no memmove (we assume they have bcopy instead). -# {The replacement define is in compat/string.h} +# Some system like SunOS 4 and other BSD like systems have no memmove +# (we assume they have bcopy instead). {The replacement define is in +# compat/string.h} #-------------------------------------------------------------------- AC_CHECK_FUNC(memmove, , [ @@ -269,8 +320,8 @@ AC_CHECK_FUNC(memmove, , [ AC_DEFINE(NO_STRING_H, 1, [Do we have <string.h>?]) ]) #-------------------------------------------------------------------- -# On some systems strstr is broken: it returns a pointer even -# even if the original string is empty. +# On some systems strstr is broken: it returns a pointer even even if +# the original string is empty. #-------------------------------------------------------------------- SC_TCL_CHECK_BROKEN_FUNC(strstr, [ @@ -486,10 +537,10 @@ fi SC_ENABLE_LANGINFO #-------------------------------------------------------------------- -# Check for support of chflags function +# Check for support of chflags and mkstemps functions #-------------------------------------------------------------------- -AC_CHECK_FUNCS(chflags) +AC_CHECK_FUNCS(chflags mkstemps) #-------------------------------------------------------------------- # Check for support of isnan() function or macro @@ -571,7 +622,7 @@ else fi #-------------------------------------------------------------------- -# Check for support of fts functions (readdir replacement) +# Check for support of fts functions (readdir replacement) #-------------------------------------------------------------------- AC_CACHE_CHECK([for fts], tcl_cv_api_fts, [ @@ -589,10 +640,9 @@ if test $tcl_cv_api_fts = yes; then fi #-------------------------------------------------------------------- -# The statements below check for systems where POSIX-style -# non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented. -# On these systems (mostly older ones), use the old BSD-style -# FIONBIO approach instead. +# The statements below check for systems where POSIX-style non-blocking +# I/O (O_NONBLOCK) doesn't work or is unimplemented. On these systems +# (mostly older ones), use the old BSD-style FIONBIO approach instead. #-------------------------------------------------------------------- SC_BLOCKING_STYLE @@ -698,32 +748,6 @@ fi AC_MSG_RESULT([$tcl_ok]) #-------------------------------------------------------------------- -# Does the C stack grow upwards or downwards? Or cross-compiling? -#-------------------------------------------------------------------- - -AC_CACHE_CHECK([if the C stack grows upwards in memory], tcl_cv_stack_grows_up, [ - AC_TRY_RUN([ - int StackGrowsUp(int *parent) { - int here; - volatile int result; - if (parent) - result = (&here < parent); - else - result = StackGrowsUp(&here); - return result; - } - int main (int argc, char *argv[]) { - return StackGrowsUp(0); - } - ], tcl_cv_stack_grows_up=yes, tcl_cv_stack_grows_up=no, - tcl_cv_stack_grows_up=unknown)]) -if test $tcl_cv_stack_grows_up = unknown; then - AC_DEFINE(TCL_CROSS_COMPILE, 1, [Are we cross-compiling?]) -elif test $tcl_cv_stack_grows_up = yes; then - AC_DEFINE(TCL_STACK_GROWS_UP, 1, [The C stack grows upwards in memory.]) -fi - -#-------------------------------------------------------------------- # The statements below define a collection of symbols related to # building libtcl as a shared library instead of a static library. #-------------------------------------------------------------------- @@ -771,6 +795,12 @@ if test "$FRAMEWORK_BUILD" = "1" ; then unset n f v ], VERSION=${TCL_VERSION}) LD_LIBRARY_PATH_VAR="DYLD_FRAMEWORK_PATH" + # default install directory for bundled packages + if test "${libdir}" = '${exec_prefix}/lib' -o "`basename ${libdir}`" = 'Frameworks'; then + PACKAGE_DIR="/Library/Tcl" + else + PACKAGE_DIR="$libdir" + fi if test "${libdir}" = '${exec_prefix}/lib'; then # override libdir default libdir="/Library/Frameworks" @@ -797,6 +827,8 @@ if test "$FRAMEWORK_BUILD" = "1" ; then else # libdir must be a fully qualified path and not ${exec_prefix}/lib eval libdir="$libdir" + # default install directory for bundled packages + PACKAGE_DIR="$libdir" if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then TCL_LIB_FLAG="-ltcl${TCL_VERSION}" else @@ -865,6 +897,7 @@ AC_SUBST(TCL_MAJOR_VERSION) AC_SUBST(TCL_MINOR_VERSION) AC_SUBST(TCL_PATCH_LEVEL) AC_SUBST(TCL_YEAR) +AC_SUBST(PKG_CFG_ARGS) AC_SUBST(TCL_LIB_FILE) AC_SUBST(TCL_LIB_FLAG) @@ -906,6 +939,7 @@ AC_SUBST(TCL_MODULE_PATH) AC_SUBST(TCL_LIBRARY) AC_SUBST(PRIVATE_INCLUDE_DIR) AC_SUBST(HTML_DIR) +AC_SUBST(PACKAGE_DIR) AC_SUBST(EXTRA_CC_SWITCHES) AC_SUBST(EXTRA_APP_CC_SWITCHES) @@ -924,5 +958,10 @@ AC_CONFIG_FILES([ Makefile:../unix/Makefile.in dltest/Makefile:../unix/dltest/Makefile.in tclConfig.sh:../unix/tclConfig.sh.in + tcl.pc:../unix/tcl.pc.in ]) AC_OUTPUT + +dnl Local Variables: +dnl mode: autoconf +dnl End: diff --git a/unix/dltest/pkga.c b/unix/dltest/pkga.c index f001cdf..c4d3f32 100644 --- a/unix/dltest/pkga.c +++ b/unix/dltest/pkga.c @@ -10,16 +10,25 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#undef STATIC_BUILD #include "tcl.h" /* + * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the + * Pkga_Init declaration is in the source file itself, which is only + * accessed when we are building a library. + */ +#undef TCL_STORAGE_CLASS +#define TCL_STORAGE_CLASS DLLEXPORT + +/* * Prototypes for procedures defined later in this file: */ static int Pkga_EqObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Pkga_QuoteObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* *---------------------------------------------------------------------- @@ -44,10 +53,10 @@ Pkga_EqObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { int result; - CONST char *str1, *str2; + const char *str1, *str2; int len1, len2; if (objc != 3) { @@ -88,7 +97,7 @@ Pkga_QuoteObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument strings. */ + Tcl_Obj *const objv[]) /* Argument strings. */ { if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "value"); @@ -115,7 +124,7 @@ Pkga_QuoteObjCmd( *---------------------------------------------------------------------- */ -int +EXTERN int Pkga_Init( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -129,9 +138,8 @@ Pkga_Init( if (code != TCL_OK) { return code; } - Tcl_CreateObjCommand(interp, "pkga_eq", Pkga_EqObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); - Tcl_CreateObjCommand(interp, "pkga_quote", Pkga_QuoteObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkga_eq", Pkga_EqObjCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "pkga_quote", Pkga_QuoteObjCmd, NULL, + NULL); return TCL_OK; } diff --git a/unix/dltest/pkgb.c b/unix/dltest/pkgb.c index 51c1bd9..fe0d365 100644 --- a/unix/dltest/pkgb.c +++ b/unix/dltest/pkgb.c @@ -11,16 +11,25 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#undef STATIC_BUILD #include "tcl.h" /* + * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the + * Pkgb_Init declaration is in the source file itself, which is only + * accessed when we are building a library. + */ +#undef TCL_STORAGE_CLASS +#define TCL_STORAGE_CLASS DLLEXPORT + +/* * Prototypes for procedures defined later in this file: */ static int Pkgb_SubObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Pkgb_UnsafeObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* *---------------------------------------------------------------------- @@ -44,7 +53,7 @@ Pkgb_SubObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { int first, second; @@ -82,7 +91,7 @@ Pkgb_UnsafeObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); return TCL_OK; @@ -105,7 +114,7 @@ Pkgb_UnsafeObjCmd( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgb_Init( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -119,10 +128,9 @@ Pkgb_Init( if (code != TCL_OK) { return code; } - Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); - Tcl_CreateObjCommand(interp, "pkgb_unsafe", Pkgb_UnsafeObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "pkgb_unsafe", Pkgb_UnsafeObjCmd, NULL, + NULL); return TCL_OK; } @@ -143,7 +151,7 @@ Pkgb_Init( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgb_SafeInit( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -157,7 +165,6 @@ Pkgb_SafeInit( if (code != TCL_OK) { return code; } - Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, (ClientData) 0, - (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, NULL, NULL); return TCL_OK; } diff --git a/unix/dltest/pkgc.c b/unix/dltest/pkgc.c index 6ad5ab4..557f21b 100644 --- a/unix/dltest/pkgc.c +++ b/unix/dltest/pkgc.c @@ -11,16 +11,25 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#undef STATIC_BUILD #include "tcl.h" /* + * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the + * Pkgc_Init declaration is in the source file itself, which is only + * accessed when we are building a library. + */ +#undef TCL_STORAGE_CLASS +#define TCL_STORAGE_CLASS DLLEXPORT + +/* * Prototypes for procedures defined later in this file: */ static int Pkgc_SubObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Pkgc_UnsafeObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* *---------------------------------------------------------------------- @@ -44,7 +53,7 @@ Pkgc_SubObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { int first, second; @@ -82,7 +91,7 @@ Pkgc_UnsafeObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); return TCL_OK; @@ -105,7 +114,7 @@ Pkgc_UnsafeObjCmd( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgc_Init( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -119,10 +128,9 @@ Pkgc_Init( if (code != TCL_OK) { return code; } - Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); - Tcl_CreateObjCommand(interp, "pkgc_unsafe", Pkgc_UnsafeObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "pkgc_unsafe", Pkgc_UnsafeObjCmd, NULL, + NULL); return TCL_OK; } @@ -143,7 +151,7 @@ Pkgc_Init( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgc_SafeInit( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -157,7 +165,6 @@ Pkgc_SafeInit( if (code != TCL_OK) { return code; } - Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, (ClientData) 0, - (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, NULL, NULL); return TCL_OK; } diff --git a/unix/dltest/pkgd.c b/unix/dltest/pkgd.c index 7fe7c49..6e114e9 100644 --- a/unix/dltest/pkgd.c +++ b/unix/dltest/pkgd.c @@ -11,16 +11,25 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#undef STATIC_BUILD #include "tcl.h" /* + * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the + * Pkgd_Init declaration is in the source file itself, which is only + * accessed when we are building a library. + */ +#undef TCL_STORAGE_CLASS +#define TCL_STORAGE_CLASS DLLEXPORT + +/* * Prototypes for procedures defined later in this file: */ static int Pkgd_SubObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Pkgd_UnsafeObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* *---------------------------------------------------------------------- @@ -44,7 +53,7 @@ Pkgd_SubObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { int first, second; @@ -82,7 +91,7 @@ Pkgd_UnsafeObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); return TCL_OK; @@ -105,7 +114,7 @@ Pkgd_UnsafeObjCmd( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgd_Init( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -119,10 +128,9 @@ Pkgd_Init( if (code != TCL_OK) { return code; } - Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); - Tcl_CreateObjCommand(interp, "pkgd_unsafe", Pkgd_UnsafeObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "pkgd_unsafe", Pkgd_UnsafeObjCmd, NULL, + NULL); return TCL_OK; } @@ -143,7 +151,7 @@ Pkgd_Init( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgd_SafeInit( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -157,7 +165,6 @@ Pkgd_SafeInit( if (code != TCL_OK) { return code; } - Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, (ClientData) 0, - (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, NULL, NULL); return TCL_OK; } diff --git a/unix/dltest/pkge.c b/unix/dltest/pkge.c index abd2359..d616352 100644 --- a/unix/dltest/pkge.c +++ b/unix/dltest/pkge.c @@ -11,8 +11,17 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#undef STATIC_BUILD #include "tcl.h" +/* + * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the + * Pkge_Init declaration is in the source file itself, which is only + * accessed when we are building a library. + */ +#undef TCL_STORAGE_CLASS +#define TCL_STORAGE_CLASS DLLEXPORT + /* *---------------------------------------------------------------------- @@ -31,12 +40,12 @@ *---------------------------------------------------------------------- */ -int +EXTERN int Pkge_Init( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ { - static char script[] = "if 44 {open non_existent}"; + static const char script[] = "if 44 {open non_existent}"; if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { return TCL_ERROR; diff --git a/unix/dltest/pkgua.c b/unix/dltest/pkgua.c index 9c36e88..417bedb 100644 --- a/unix/dltest/pkgua.c +++ b/unix/dltest/pkgua.c @@ -11,16 +11,25 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#undef STATIC_BUILD #include "tcl.h" /* + * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the + * Pkgua_Init declaration is in the source file itself, which is only + * accessed when we are building a library. + */ +#undef TCL_STORAGE_CLASS +#define TCL_STORAGE_CLASS DLLEXPORT + +/* * Prototypes for procedures defined later in this file: */ static int PkguaEqObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int PkguaQuoteObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* * In the following hash table we are going to store a struct that holds all @@ -49,7 +58,7 @@ PkguaInitTokensHashTable(void) interpTokenMapInitialised = 1; } -void +static void PkguaFreeTokensHashTable(void) { Tcl_HashSearch search; @@ -77,7 +86,7 @@ PkguaInterpToTokens( for (newEntry=0 ; newEntry<MAX_REGISTERED_COMMANDS+1 ; ++newEntry) { cmdTokens[newEntry] = NULL; } - Tcl_SetHashValue(entryPtr, (ClientData) cmdTokens); + Tcl_SetHashValue(entryPtr, cmdTokens); } else { cmdTokens = (Tcl_Command *) Tcl_GetHashValue(entryPtr); } @@ -120,10 +129,10 @@ PkguaEqObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { int result; - CONST char *str1, *str2; + const char *str1, *str2; int len1, len2; if (objc != 3) { @@ -164,7 +173,7 @@ PkguaQuoteObjCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument strings. */ + Tcl_Obj *const objv[]) /* Argument strings. */ { if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "value"); @@ -191,7 +200,7 @@ PkguaQuoteObjCmd( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgua_Init( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -219,11 +228,11 @@ Pkgua_Init( cmdTokens = PkguaInterpToTokens(interp); cmdTokens[cmdIndex++] = - Tcl_CreateObjCommand(interp, "pkgua_eq", PkguaEqObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgua_eq", PkguaEqObjCmd, NULL, + NULL); cmdTokens[cmdIndex++] = Tcl_CreateObjCommand(interp, "pkgua_quote", PkguaQuoteObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + NULL, NULL); return TCL_OK; } @@ -244,7 +253,7 @@ Pkgua_Init( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgua_SafeInit( Tcl_Interp *interp) /* Interpreter in which the package is to be * made available. */ @@ -269,7 +278,7 @@ Pkgua_SafeInit( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgua_Unload( Tcl_Interp *interp, /* Interpreter from which the package is to be * unloaded. */ @@ -322,7 +331,7 @@ Pkgua_Unload( *---------------------------------------------------------------------- */ -int +EXTERN int Pkgua_SafeUnload( Tcl_Interp *interp, /* Interpreter from which the package is to be * unloaded. */ diff --git a/unix/install-sh b/unix/install-sh index 8cff938..c68581d 100755 --- a/unix/install-sh +++ b/unix/install-sh @@ -1,124 +1,528 @@ #!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2011-04-20.01; # UTC +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. # -# install - install a program, script, or datafile -# This comes from X11R5; it is not part of GNU. +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. # -# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $ +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. -# +nl=' +' +IFS=" "" $nl" # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" +doit=${DOITPROG-} +if test -z "$doit"; then + doit_exec=exec +else + doit_exec=$doit +fi + +# Put in absolute file names if you don't have them in your path; +# or use environment vars. +chgrpprog=${CHGRPPROG-chgrp} +chmodprog=${CHMODPROG-chmod} +chownprog=${CHOWNPROG-chown} +cmpprog=${CMPPROG-cmp} +cpprog=${CPPROG-cp} +mkdirprog=${MKDIRPROG-mkdir} +mvprog=${MVPROG-mv} +rmprog=${RMPROG-rm} +stripprog=${STRIPPROG-strip} -# put in absolute paths if you don't have them in your path; or use env. vars. +posix_glob='?' +initialize_posix_glob=' + test "$posix_glob" != "?" || { + if (set -f) 2>/dev/null; then + posix_glob= + else + posix_glob=: + fi + } +' -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" +posix_mkdir= -instcmd="$mvprog" -chmodcmd="" -chowncmd="" -chgrpcmd="" -stripcmd="" +# Desired mode of installed file. +mode=0755 + +chgrpcmd= +chmodcmd=$chmodprog +chowncmd= +mvcmd=$mvprog rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -S) stripcmd="$stripprog $2" - shift - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - dst=$1 - fi - shift - continue;; - esac +stripcmd= + +src= +dst= +dir_arg= +dst_arg= + +copy_on_change=false +no_target_directory= + +usage="\ +Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: + --help display this help and exit. + --version display version info and exit. + + -c (ignored) + -C install only if different (preserve the last data modification time) + -d create directories instead of installing files. + -g GROUP $chgrpprog installed files to GROUP. + -m MODE $chmodprog installed files to MODE. + -o USER $chownprog installed files to USER. + -s $stripprog installed files. + -S $stripprog installed files. + -t DIRECTORY install into DIRECTORY. + -T report an error if DSTFILE is a directory. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG + RMPROG STRIPPROG +" + +while test $# -ne 0; do + case $1 in + -c) ;; + + -C) copy_on_change=true;; + + -d) dir_arg=true;; + + -g) chgrpcmd="$chgrpprog $2" + shift;; + + --help) echo "$usage"; exit $?;; + + -m) mode=$2 + case $mode in + *' '* | *' '* | *' +'* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; + + -o) chowncmd="$chownprog $2" + shift;; + + -s) stripcmd=$stripprog;; + + -S) stripcmd="$stripprog $2" + shift;; + + -t) dst_arg=$2 + shift;; + + -T) no_target_directory=true;; + + --version) echo "$0 $scriptversion"; exit $?;; + + --) shift + break;; + + -*) echo "$0: invalid option: $1" >&2 + exit 1;; + + *) break;; + esac + shift done -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 +if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then + # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dst_arg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dst_arg" + shift # fnord + fi + shift # arg + dst_arg=$arg + done fi -if [ x"$dst" = x ] -then - echo "install: no destination specified" - exit 1 +if test $# -eq 0; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call `install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 fi +if test -z "$dir_arg"; then + do_exit='(exit $ret); exit $ret' + trap "ret=129; $do_exit" 1 + trap "ret=130; $do_exit" 2 + trap "ret=141; $do_exit" 13 + trap "ret=143; $do_exit" 15 -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic + # Set umask so as not to create temps with too-generous modes. + # However, 'strip' requires both read and write access to temps. + case $mode in + # Optimize common cases. + *644) cp_umask=133;; + *755) cp_umask=22;; -if [ -d "$dst" ] -then - dst="$dst/`basename "$src"`" + *[0-7]) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw='% 200' + fi + cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; + *) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw=,u+rw + fi + cp_umask=$mode$u_plus_rw;; + esac fi -# Make a temp file name in the proper directory. +for src +do + # Protect names starting with `-'. + case $src in + -*) src=./$src;; + esac + + if test -n "$dir_arg"; then + dst=$src + dstdir=$dst + test -d "$dstdir" + dstdir_status=$? + else + + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dst_arg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + + dst=$dst_arg + # Protect names starting with `-'. + case $dst in + -*) dst=./$dst;; + esac + + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dst_arg: Is a directory" >&2 + exit 1 + fi + dstdir=$dst + dst=$dstdir/`basename "$src"` + dstdir_status=0 + else + # Prefer dirname, but fall back on a substitute if dirname fails. + dstdir=` + (dirname "$dst") 2>/dev/null || + expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$dst" : 'X\(//\)[^/]' \| \ + X"$dst" : 'X\(//\)$' \| \ + X"$dst" : 'X\(/\)' \| . 2>/dev/null || + echo X"$dst" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q' + ` + + test -d "$dstdir" + dstdir_status=$? + fi + fi + + obsolete_mkdir_used=false + + if test $dstdir_status != 0; then + case $posix_mkdir in + '') + # Create intermediate dirs using mode 755 as modified by the umask. + # This is like FreeBSD 'install' as of 1997-10-28. + umask=`umask` + case $stripcmd.$umask in + # Optimize common cases. + *[2367][2367]) mkdir_umask=$umask;; + .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; + + *[0-7]) + mkdir_umask=`expr $umask + 22 \ + - $umask % 100 % 40 + $umask % 20 \ + - $umask % 10 % 4 + $umask % 2 + `;; + *) mkdir_umask=$umask,go-w;; + esac + + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi + + posix_mkdir=false + case $umask in + *[123567][0-7][0-7]) + # POSIX mkdir -p sets u+wx bits regardless of umask, which + # is incompatible with FreeBSD 'install' when (umask & 300) != 0. + ;; + *) + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 -dstdir="`dirname "$dst"`" -dsttmp="$dstdir"/#inst.$$# + if (umask $mkdir_umask && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writeable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + ls_ld_tmpdir=`ls -ld "$tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/d" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null + fi + trap '' 0;; + esac;; + esac + + if + $posix_mkdir && ( + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + ) + then : + else + + # The umask is ridiculous, or mkdir does not conform to POSIX, + # or it failed possibly due to a race condition. Create the + # directory the slow way, step by step, checking for races as we go. + + case $dstdir in + /*) prefix='/';; + -*) prefix='./';; + *) prefix='';; + esac + + eval "$initialize_posix_glob" + + oIFS=$IFS + IFS=/ + $posix_glob set -f + set fnord $dstdir + shift + $posix_glob set +f + IFS=$oIFS -# Move or copy the file name to the temp name + prefixes= -$doit $instcmd "$src" "$dsttmp" + for d + do + test -z "$d" && continue -# and set any options; do chmod last to preserve setuid bits + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask=$mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ + done -if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; fi -if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; fi -if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; fi -if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; fi + if test -n "$prefixes"; then + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true + fi + fi + fi -# Now rename the file to the real destination. + if test -n "$dir_arg"; then + { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && + { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || + test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 + else -$doit $rmcmd "$dst" -$doit $mvcmd "$dsttmp" "$dst" + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + # Trap to clean up those temp files at exit. + trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 + + # Copy the file name to the temp name. + (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && + { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && + { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && + + # If -C, don't bother to copy if it wouldn't change the file. + if $copy_on_change && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + + eval "$initialize_posix_glob" && + $posix_glob set -f && + set X $old && old=:$2:$4:$5:$6 && + set X $new && new=:$2:$4:$5:$6 && + $posix_glob set +f && + + test "$old" = "$new" && + $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 + then + rm -f "$dsttmp" + else + # Rename the file to the real destination. + $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || + + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + { + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd -f "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" + } + fi || exit 1 + + trap '' 0 + fi +done -exit 0 +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/unix/installManPage b/unix/installManPage index 6bdccf0..4d615bf 100755 --- a/unix/installManPage +++ b/unix/installManPage @@ -59,9 +59,7 @@ test -z "$SymOrLoc" && SymOrLoc="$Dir/" # backticks which doesn't pass backslashes literally. # Names=`sed -n ' -# Look for a line, that starts with .SH NAME -# optionally allow NAME to be surrounded -# by quotes. +# Look for a line that starts with .SH NAME /^\.SH NAME/{ # Read next line n @@ -71,6 +69,9 @@ Names=`sed -n ' s/\\\ //g # Delete from \- to the end of line s/ \\\-.*// +# Convert all non-space non-alphanum sequences +# to single underscores. + s/[^ A-Za-z0-9][^ A-Za-z0-9]*/_/g # print the result and exit p;q }' $ManPage` diff --git a/unix/tcl.m4 b/unix/tcl.m4 index 78eacd9..2f7cb16 100644 --- a/unix/tcl.m4 +++ b/unix/tcl.m4 @@ -618,8 +618,8 @@ AC_DEFUN([SC_ENABLE_FRAMEWORK], [ AC_DEFUN([SC_ENABLE_THREADS], [ AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads], - [build with threads (default: off)]), - [tcl_ok=$enableval], [tcl_ok=no]) + [build with threads (default: on)]), + [tcl_ok=$enableval], [tcl_ok=yes]) if test "${TCL_THREADS}" = 1; then tcl_threaded_core=1; @@ -676,44 +676,7 @@ AC_DEFUN([SC_ENABLE_THREADS], [ # Does the pthread-implementation provide # 'pthread_attr_setstacksize' ? - - ac_saved_libs=$LIBS - LIBS="$LIBS $THREADS_LIBS" AC_CHECK_FUNCS(pthread_attr_setstacksize) - AC_CHECK_FUNC(pthread_attr_get_np,tcl_ok=yes,tcl_ok=no) - if test $tcl_ok = yes ; then - AC_DEFINE(HAVE_PTHREAD_ATTR_GET_NP, 1, - [Do we want a BSD-like thread-attribute interface?]) - AC_CACHE_CHECK([for pthread_attr_get_np declaration], - tcl_cv_grep_pthread_attr_get_np, [ - AC_EGREP_HEADER(pthread_attr_get_np, pthread.h, - tcl_cv_grep_pthread_attr_get_np=present, - tcl_cv_grep_pthread_attr_get_np=missing)]) - if test $tcl_cv_grep_pthread_attr_get_np = missing ; then - AC_DEFINE(ATTRGETNP_NOT_DECLARED, 1, - [Is pthread_attr_get_np() declared in <pthread.h>?]) - fi - else - AC_CHECK_FUNC(pthread_getattr_np,tcl_ok=yes,tcl_ok=no) - if test $tcl_ok = yes ; then - AC_DEFINE(HAVE_PTHREAD_GETATTR_NP, 1, - [Do we want a Linux-like thread-attribute interface?]) - AC_CACHE_CHECK([for pthread_getattr_np declaration], - tcl_cv_grep_pthread_getattr_np, [ - AC_EGREP_HEADER(pthread_getattr_np, pthread.h, - tcl_cv_grep_pthread_getattr_np=present, - tcl_cv_grep_pthread_getattr_np=missing)]) - if test $tcl_cv_grep_pthread_getattr_np = missing ; then - AC_DEFINE(GETATTRNP_NOT_DECLARED, 1, - [Is pthread_getattr_np declared in <pthread.h>?]) - fi - fi - fi - if test $tcl_ok = no; then - # Darwin thread stacksize API - AC_CHECK_FUNCS(pthread_get_stacksize_np) - fi - LIBS=$ac_saved_libs else TCL_THREADS=0 fi @@ -727,7 +690,7 @@ AC_DEFUN([SC_ENABLE_THREADS], [ AC_MSG_RESULT([yes]) fi else - AC_MSG_RESULT([no (default)]) + AC_MSG_RESULT([no]) fi AC_SUBST(TCL_THREADS) @@ -1079,16 +1042,33 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ AC_CACHE_CHECK([if compiler supports visibility "hidden"], tcl_cv_cc_visibility_hidden, [ + AS_IF([test "$SHARED_BUILD" = 1], [ + hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -fvisibility=hidden -Werror" + AC_TRY_COMPILE(,[#if !defined(__GNUC__) || __GNUC__ < 4 +#error visibility hidden is not supported for this compiler +#endif + ], tcl_cv_cc_visibility_hidden=yes, + tcl_cv_cc_visibility_hidden=no) + CFLAGS=$hold_cflags + ], [ + tcl_cv_cc_visibility_hidden=no + ]) + ]) + AS_IF([test $tcl_cv_cc_visibility_hidden = yes], [ + CFLAGS="$CFLAGS -fvisibility=hidden" + AC_DEFINE(MODULE_SCOPE, [extern], [No need to mark inidividual symbols as hidden]) + ], [ hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror" AC_TRY_LINK([ extern __attribute__((__visibility__("hidden"))) void f(void); void f(void) {}], [f();], tcl_cv_cc_visibility_hidden=yes, tcl_cv_cc_visibility_hidden=no) - CFLAGS=$hold_cflags]) - AS_IF([test $tcl_cv_cc_visibility_hidden = yes], [ - AC_DEFINE(MODULE_SCOPE, - [extern __attribute__((__visibility__("hidden")))], - [Compiler support for module scope symbols]) + CFLAGS=$hold_cflags + AS_IF([test $tcl_cv_cc_visibility_hidden = yes], [ + AC_DEFINE(MODULE_SCOPE, + [extern __attribute__((__visibility__("hidden")))], + [Compiler support for module scope symbols]) + ]) ]) # Step 0.d: Disable -rpath support? @@ -1111,7 +1091,6 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ AC_CHECK_LIB(dl, dlopen, have_dl=yes, have_dl=no) # Require ranlib early so we can override it in special cases below. - AS_IF([test x"${SHLIB_VERSION}" = x], [SHLIB_VERSION="1.0"]) AC_REQUIRE([AC_PROG_RANLIB]) @@ -1130,16 +1109,20 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ ECHO_VERSION='`echo ${VERSION}`' TCL_LIB_VERSIONS_OK=ok CFLAGS_DEBUG=-g - CFLAGS_OPTIMIZE=-O AS_IF([test "$GCC" = yes], [ + CFLAGS_OPTIMIZE=-O2 CFLAGS_WARNING="-Wall" - ], [CFLAGS_WARNING=""]) + ], [ + CFLAGS_OPTIMIZE=-O + CFLAGS_WARNING="" + ]) AC_CHECK_TOOL(AR, ar) STLIB_LD='${AR} cr' LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH" PLAT_OBJS="" PLAT_SRCS="" LDAIX_SRC="" + AS_IF([test x"${SHLIB_VERSION}" = x], [SHLIB_VERSION="1.0"]) case $system in AIX-*) AS_IF([test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"], [ @@ -1290,6 +1273,8 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ AS_IF([test "$GCC" = yes], [ SHLIB_LD='${CC} -shared' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + ], [ + CFLAGS="$CFLAGS -z" ]) # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc @@ -1337,6 +1322,7 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" + AC_LIBOBJ(mkstemp) AS_IF([test $doRpath = yes], [ CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}']) @@ -1347,6 +1333,7 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" + AC_LIBOBJ(mkstemp) AS_IF([test $doRpath = yes], [ CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}']) @@ -1372,6 +1359,7 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ SHLIB_SUFFIX=".so" DL_OBJS="tclLoadDl.o" DL_LIBS="" + AC_LIBOBJ(mkstemp) AS_IF([test $doRpath = yes], [ CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}']) @@ -1676,6 +1664,7 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ AS_IF([test "$tcl_cv_cc_visibility_hidden" != yes], [ AC_DEFINE(MODULE_SCOPE, [__private_extern__], [Compiler support for module scope symbols]) + tcl_cv_cc_visibility_hidden=yes ]) CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" @@ -2074,15 +2063,27 @@ dnl # preprocessing tests use only CPPFLAGS. *) SHLIB_CFLAGS="-fPIC" ;; esac]) + AS_IF([test "$tcl_cv_cc_visibility_hidden" != yes], [ + AC_DEFINE(MODULE_SCOPE, [extern], + [No Compiler support for module scope symbols]) + AC_DEFINE(NO_VIZ, [], [No visibility attribute]) + ]) + AS_IF([test "$SHARED_LIB_SUFFIX" = ""], [ SHARED_LIB_SUFFIX='${VERSION}${SHLIB_SUFFIX}']) AS_IF([test "$UNSHARED_LIB_SUFFIX" = ""], [ UNSHARED_LIB_SUFFIX='${VERSION}.a']) + DLL_INSTALL_DIR="\$(LIB_INSTALL_DIR)" AS_IF([test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""], [ LIB_SUFFIX=${SHARED_LIB_SUFFIX} MAKE_LIB='${SHLIB_LD} -o [$]@ ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}' - INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)"/$(LIB_FILE)' + AS_IF([test "${SHLIB_SUFFIX}" = ".dll"], [ + INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)"/$(LIB_FILE)' + DLL_INSTALL_DIR="\$(BIN_INSTALL_DIR)" + ], [ + INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)"/$(LIB_FILE)' + ]) ], [ LIB_SUFFIX=${UNSHARED_LIB_SUFFIX} @@ -2144,6 +2145,7 @@ dnl # preprocessing tests use only CPPFLAGS. AC_SUBST(MAKE_LIB) AC_SUBST(MAKE_STUB_LIB) AC_SUBST(INSTALL_LIB) + AC_SUBST(DLL_INSTALL_DIR) AC_SUBST(INSTALL_STUB_LIB) AC_SUBST(RANLIB) ]) @@ -2465,11 +2467,6 @@ AC_DEFUN([SC_BLOCKING_STYLE], [ SC_CONFIG_SYSTEM AC_MSG_CHECKING([FIONBIO vs. O_NONBLOCK for nonblocking I/O]) case $system in - # There used to be code here to use FIONBIO under AIX. However, it - # was reported that FIONBIO doesn't work under AIX 3.2.5. Since - # using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO - # code (JO, 5/31/97). - OSF*) AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?]) AC_MSG_RESULT([FIONBIO]) @@ -3011,37 +3008,6 @@ AC_DEFUN([SC_TCL_GETHOSTBYNAME_R], [AC_CHECK_FUNC(gethostbyname_r, [ ])]) #-------------------------------------------------------------------- -# SC_TCL_GETADDRINFO -# -# Check if we have 'getaddrinfo' -# -# Arguments: -# None -# -# Results: -# Might define the following vars: -# HAVE_GETADDRINFO -# -#-------------------------------------------------------------------- - -AC_DEFUN([SC_TCL_GETADDRINFO], [AC_CHECK_FUNC(getaddrinfo, [ - AC_CACHE_CHECK([for working getaddrinfo], tcl_cv_api_getaddrinfo, [ - AC_TRY_COMPILE([ - #include <netdb.h> - ], [ - const char *name, *port; - struct addrinfo *aiPtr, hints; - (void)getaddrinfo(name,port, &hints, &aiPtr); - (void)freeaddrinfo(aiPtr); - ], tcl_cv_api_getaddrinfo=yes, tcl_cv_getaddrinfo=no)]) - tcl_ok=$tcl_cv_api_getaddrinfo - if test "$tcl_ok" = yes; then - AC_DEFINE(HAVE_GETADDRINFO, 1, - [Define to 1 if getaddrinfo is available.]) - fi -])]) - -#-------------------------------------------------------------------- # SC_TCL_GETPWUID_R # # Check if we have MT-safe variant of getpwuid() and if yes, @@ -3281,6 +3247,26 @@ AC_DEFUN([SC_TCL_GETGRNAM_R], [AC_CHECK_FUNC(getgrnam_r, [ fi ])]) +AC_DEFUN([SC_TCL_IPV6],[ + NEED_FAKE_RFC2553=0 + AC_CHECK_FUNCS(getnameinfo getaddrinfo freeaddrinfo gai_strerror,,[NEED_FAKE_RFC2553=1]) + AC_CHECK_TYPES([ + struct addrinfo, + struct in6_addr, + struct sockaddr_in6, + struct sockaddr_storage],,[NEED_FAKE_RFC2553=1],[[ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +]]) +if test "x$NEED_FAKE_RFC2553" = "x1"; then + AC_DEFINE([NEED_FAKE_RFC2553], 1, + [Use compat implementation of getaddrinfo() and friends]) + AC_LIBOBJ([fake-rfc2553]) + AC_CHECK_FUNC(strlcpy) +fi +]) # Local Variables: # mode: autoconf # End: diff --git a/unix/tcl.pc.in b/unix/tcl.pc.in new file mode 100644 index 0000000..8bf67cd --- /dev/null +++ b/unix/tcl.pc.in @@ -0,0 +1,15 @@ +# tcl pkg-config source file + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Tool Command Language +Description: Tcl is a powerful, easy-to-learn dynamic programming language, suitable for a wide range of uses. +URL: http://www.tcl.tk/ +Version: @TCL_VERSION@ +Requires: +Conflicts: +Libs: -L${libdir} @TCL_LIBS@ +Cflags: -I${includedir} diff --git a/unix/tcl.spec b/unix/tcl.spec index 7729960..b35e220 100644 --- a/unix/tcl.spec +++ b/unix/tcl.spec @@ -4,7 +4,7 @@ Name: tcl Summary: Tcl scripting language development environment -Version: 8.5.10 +Version: 8.6b2 Release: 2 License: BSD Group: Development/Languages diff --git a/unix/tclAppInit.c b/unix/tclAppInit.c index b9c64b1..159bbd8 100644 --- a/unix/tclAppInit.c +++ b/unix/tclAppInit.c @@ -2,32 +2,53 @@ * tclAppInit.c -- * * Provides a default version of the main program and Tcl_AppInit - * function for Tcl applications (without Tk). + * procedure for tclsh and other Tcl-based applications (without Tk). * * Copyright (c) 1993 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. - * Copyright (c) 1998-1999 by Scriptics Corporation. + * Copyright (c) 1998-1999 Scriptics Corporation. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#undef BUILD_tcl +#undef STATIC_BUILD #include "tcl.h" #ifdef TCL_TEST +extern Tcl_PackageInitProc Tcltest_Init; +extern Tcl_PackageInitProc Tcltest_SafeInit; +#endif /* TCL_TEST */ -#include "tclInt.h" +#ifdef TCL_XT_TEST +extern void XtToolkitInitialize(void); +extern int Tclxttest_Init(Tcl_Interp *interp); +#endif -extern Tcl_PackageInitProc Procbodytest_Init; -extern Tcl_PackageInitProc Procbodytest_SafeInit; -extern Tcl_PackageInitProc TclObjTest_Init; -extern Tcl_PackageInitProc Tcltest_Init; +/* + * The following #if block allows you to change the AppInit function by using + * a #define of TCL_LOCAL_APPINIT instead of rewriting this entire file. The + * #if checks for that #define and uses Tcl_AppInit if it doesn't exist. + */ -#endif /* TCL_TEST */ +#ifndef TCL_LOCAL_APPINIT +#define TCL_LOCAL_APPINIT Tcl_AppInit +#endif +#ifndef MODULE_SCOPE +# define MODULE_SCOPE extern +#endif +MODULE_SCOPE int TCL_LOCAL_APPINIT(Tcl_Interp *); +MODULE_SCOPE int main(int, char **); -#ifdef TCL_XT_TEST -extern void XtToolkitInitialize _ANSI_ARGS_((void)); -extern int Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp)); +/* + * The following #if block allows you to change how Tcl finds the startup + * script, prime the library or encoding paths, fiddle with the argv, etc., + * without needing to rewrite Tcl_Main() + */ + +#ifdef TCL_LOCAL_MAIN_HOOK +extern int TCL_LOCAL_MAIN_HOOK(int *argc, char ***argv); #endif /* @@ -38,11 +59,11 @@ extern int Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp)); * This is the main program for the application. * * Results: - * None: Tcl_Main never returns here, so this function never returns + * None: Tcl_Main never returns here, so this procedure never returns * either. * * Side effects: - * Whatever the application does. + * Just about anything, since from here we call arbitrary Tcl code. * *---------------------------------------------------------------------- */ @@ -52,28 +73,6 @@ main( int argc, /* Number of command-line arguments. */ char **argv) /* Values of command-line arguments. */ { - /* - * The following #if block allows you to change the AppInit function by - * using a #define of TCL_LOCAL_APPINIT instead of rewriting this entire - * file. The #if checks for that #define and uses Tcl_AppInit if it does - * not exist. - */ - -#ifndef TCL_LOCAL_APPINIT -#define TCL_LOCAL_APPINIT Tcl_AppInit -#endif - extern int TCL_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp)); - - /* - * The following #if block allows you to change how Tcl finds the startup - * script, prime the library or encoding paths, fiddle with the argv, - * etc., without needing to rewrite Tcl_Main() - */ - -#ifdef TCL_LOCAL_MAIN_HOOK - extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv)); -#endif - #ifdef TCL_XT_TEST XtToolkitInitialize(); #endif @@ -83,7 +82,6 @@ main( #endif Tcl_Main(argc, argv, TCL_LOCAL_APPINIT); - return 0; /* Needed only to prevent compiler warning. */ } @@ -92,9 +90,9 @@ main( * * Tcl_AppInit -- * - * This function performs application-specific initialization. Most + * This procedure performs application-specific initialization. Most * applications, especially those that incorporate additional packages, - * will have their own version of this function. + * will have their own version of this procedure. * * Results: * Returns a standard Tcl completion code, and leaves an error message in @@ -110,33 +108,25 @@ int Tcl_AppInit( Tcl_Interp *interp) /* Interpreter for application. */ { - if (Tcl_Init(interp) == TCL_ERROR) { + if ((Tcl_Init)(interp) == TCL_ERROR) { return TCL_ERROR; } -#ifdef TCL_TEST #ifdef TCL_XT_TEST if (Tclxttest_Init(interp) == TCL_ERROR) { return TCL_ERROR; } #endif + +#ifdef TCL_TEST if (Tcltest_Init(interp) == TCL_ERROR) { return TCL_ERROR; } - Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init, - (Tcl_PackageInitProc *) NULL); - if (TclObjTest_Init(interp) == TCL_ERROR) { - return TCL_ERROR; - } - if (Procbodytest_Init(interp) == TCL_ERROR) { - return TCL_ERROR; - } - Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init, - Procbodytest_SafeInit); + Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init, Tcltest_SafeInit); #endif /* TCL_TEST */ /* - * Call the init functions for included packages. Each call should look + * Call the init procedures for included packages. Each call should look * like this: * * if (Mod_Init(interp) == TCL_ERROR) { @@ -149,7 +139,7 @@ Tcl_AppInit( /* * Call Tcl_CreateCommand for application-specific commands, if they - * weren't already created by the init functions called above. + * weren't already created by the init procedures called above. */ /* @@ -160,9 +150,9 @@ Tcl_AppInit( */ #ifdef DJGPP - Tcl_SetVar(interp, "tcl_rcFileName", "~/tclsh.rc", TCL_GLOBAL_ONLY); + (Tcl_SetVar)(interp, "tcl_rcFileName", "~/tclsh.rc", TCL_GLOBAL_ONLY); #else - Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); + (Tcl_SetVar)(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); #endif return TCL_OK; diff --git a/unix/tclConfig.h.in b/unix/tclConfig.h.in index 8bede7e..42abf34 100644 --- a/unix/tclConfig.h.in +++ b/unix/tclConfig.h.in @@ -4,12 +4,6 @@ #ifndef _TCLCONFIG #define _TCLCONFIG -/* Is pthread_attr_get_np() declared in <pthread.h>? */ -#undef ATTRGETNP_NOT_DECLARED - -/* Is pthread_getattr_np declared in <pthread.h>? */ -#undef GETATTRNP_NOT_DECLARED - /* Is gettimeofday() actually declared in <sys/time.h>? */ #undef GETTOD_NOT_DECLARED @@ -34,10 +28,16 @@ /* Do we have access to Darwin CoreFoundation.framework? */ #undef HAVE_COREFOUNDATION +/* Define to 1 if you have the `freeaddrinfo' function. */ +#undef HAVE_FREEADDRINFO + /* Do we have fts functions? */ #undef HAVE_FTS -/* Define to 1 if getaddrinfo is available. */ +/* Define to 1 if you have the `gai_strerror' function. */ +#undef HAVE_GAI_STRERROR + +/* Define to 1 if you have the `getaddrinfo' function. */ #undef HAVE_GETADDRINFO /* Define to 1 if you have the `getattrlist' function. */ @@ -85,6 +85,9 @@ /* Define to 1 if gethostbyname_r takes 6 args. */ #undef HAVE_GETHOSTBYNAME_R_6 +/* Define to 1 if you have the `getnameinfo' function. */ +#undef HAVE_GETNAMEINFO + /* Define to 1 if getpwnam_r is available. */ #undef HAVE_GETPWNAM_R @@ -130,6 +133,12 @@ /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the `mkstemp' function. */ +#undef HAVE_MKSTEMP + +/* Define to 1 if you have the `mkstemps' function. */ +#undef HAVE_MKSTEMPS + /* Define to 1 if you have the `mktime' function. */ #undef HAVE_MKTIME @@ -154,18 +163,9 @@ /* Define to 1 if you have the `pthread_atfork' function. */ #undef HAVE_PTHREAD_ATFORK -/* Do we want a BSD-like thread-attribute interface? */ -#undef HAVE_PTHREAD_ATTR_GET_NP - /* Define to 1 if you have the `pthread_attr_setstacksize' function. */ #undef HAVE_PTHREAD_ATTR_SETSTACKSIZE -/* Do we want a Linux-like thread-attribute interface? */ -#undef HAVE_PTHREAD_GETATTR_NP - -/* Define to 1 if you have the `pthread_get_stacksize_np' function. */ -#undef HAVE_PTHREAD_GET_STACKSIZE_NP - /* Does putenv() copy strings or incorporate them by reference? */ #undef HAVE_PUTENV_THAT_COPIES @@ -187,9 +187,21 @@ /* Define to 1 if you have the `strtol' function. */ #undef HAVE_STRTOL +/* Define to 1 if the system has the type `struct addrinfo'. */ +#undef HAVE_STRUCT_ADDRINFO + /* Is 'struct dirent64' in <sys/types.h>? */ #undef HAVE_STRUCT_DIRENT64 +/* Define to 1 if the system has the type `struct in6_addr'. */ +#undef HAVE_STRUCT_IN6_ADDR + +/* Define to 1 if the system has the type `struct sockaddr_in6'. */ +#undef HAVE_STRUCT_SOCKADDR_IN6 + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE + /* Is 'struct stat64' in <sys/stat.h>? */ #undef HAVE_STRUCT_STAT64 @@ -247,15 +259,21 @@ /* Is weak import available? */ #undef HAVE_WEAK_IMPORT +/* Is there an installed zlib? */ +#undef HAVE_ZLIB + /* Is this a Mac I see before me? */ #undef MAC_OSX_TCL -/* Compiler support for module scope symbols */ +/* No Compiler support for module scope symbols */ #undef MODULE_SCOPE /* Default libtommath precision. */ #undef MP_PREC +/* Use compat implementation of getaddrinfo() and friends */ +#undef NEED_FAKE_RFC2553 + /* Is Darwin CoreFoundation unavailable for 64-bit? */ #undef NO_COREFOUNDATION_64 @@ -313,6 +331,9 @@ /* Do we have <values.h>? */ #undef NO_VALUES_H +/* No visibility attribute */ +#undef NO_VIZ + /* Do we have wait3() */ #undef NO_WAIT3 @@ -355,9 +376,6 @@ /* Are bytecode statistics enabled? */ #undef TCL_COMPILE_STATS -/* Are we cross-compiling? */ -#undef TCL_CROSS_COMPILE - /* Are we to override what our default encoding is? */ #undef TCL_DEFAULT_ENCODING @@ -373,9 +391,6 @@ /* What is the default extension for shared libraries? */ #undef TCL_SHLIB_EXT -/* The C stack grows upwards in memory. */ -#undef TCL_STACK_GROWS_UP - /* Are we building with threads enabled? */ #undef TCL_THREADS diff --git a/unix/tclLoadAix.c b/unix/tclLoadAix.c index 59bccbf..88e6b50 100644 --- a/unix/tclLoadAix.c +++ b/unix/tclLoadAix.c @@ -211,7 +211,7 @@ dlopen( if (mp->info = (struct dl_info *)dlsym(mp, "dl_info")) { if (mp->info->init) { - (*mp->info->init)(); + mp->info->init(); } } else { errvalid = 0; @@ -224,7 +224,7 @@ dlopen( if (mp->cdtors = (CdtorPtr) dlsym(mp, "__cdtors")) { while (mp->cdtors->init) { - (*mp->cdtors->init)(); + mp->cdtors->init(); mp->cdtors++; } } else { @@ -326,12 +326,12 @@ dlclose( } if (mp->info && mp->info->fini) { - (*mp->info->fini)(); + mp->info->fini(); } if (mp->cdtors) { while (mp->cdtors->term) { - (*mp->cdtors->term)(); + mp->cdtors->term(); mp->cdtors++; } } diff --git a/unix/tclLoadDl.c b/unix/tclLoadDl.c index e38c280..96f0717 100644 --- a/unix/tclLoadDl.c +++ b/unix/tclLoadDl.c @@ -6,8 +6,8 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" @@ -33,6 +33,14 @@ #endif /* + * Static procedures defined within this file. + */ + +static void * FindSymbol(Tcl_Interp *interp, + Tcl_LoadHandle loadHandle, const char *symbol); +static void UnloadFile(Tcl_LoadHandle loadHandle); + +/* *--------------------------------------------------------------------------- * * TclpDlopen -- @@ -64,7 +72,8 @@ TclpDlopen( * file. */ { void *handle; - CONST char *native; + Tcl_LoadHandle newHandle; + const char *native; /* * First try the full path the user gave us. This is particularly @@ -85,7 +94,7 @@ TclpDlopen( */ Tcl_DString ds; - char *fileName = Tcl_GetString(pathPtr); + const char *fileName = Tcl_GetString(pathPtr); native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds); /* @@ -107,16 +116,20 @@ TclpDlopen( Tcl_GetString(pathPtr), "\": ", errorStr, NULL); return TCL_ERROR; } + newHandle = ckalloc(sizeof(*newHandle)); + newHandle->clientData = handle; + newHandle->findSymbolProcPtr = &FindSymbol; + newHandle->unloadFileProcPtr = &UnloadFile; + *unloadProcPtr = &UnloadFile; + *loadHandle = newHandle; - *unloadProcPtr = &TclpUnloadFile; - *loadHandle = (Tcl_LoadHandle) handle; return TCL_OK; } /* *---------------------------------------------------------------------- * - * TclpFindSymbol -- + * FindSymbol -- * * Looks up a symbol, by name, through a handle associated with a * previously loaded piece of code (shared library). @@ -129,16 +142,21 @@ TclpDlopen( *---------------------------------------------------------------------- */ -Tcl_PackageInitProc * -TclpFindSymbol( +static void * +FindSymbol( Tcl_Interp *interp, /* Place to put error messages. */ Tcl_LoadHandle loadHandle, /* Value from TcpDlopen(). */ - CONST char *symbol) /* Symbol to look up. */ + const char *symbol) /* Symbol to look up. */ { - CONST char *native; - Tcl_DString newName, ds; - VOID *handle = (VOID*)loadHandle; - Tcl_PackageInitProc *proc; + const char *native; /* Name of the library to be loaded, in + * system encoding */ + Tcl_DString newName, ds; /* Buffers for converting the name to + * system encoding and prepending an + * underscore*/ + void *handle = (void *) loadHandle->clientData; + /* Native handle to the loaded library */ + void *proc; /* Address corresponding to the resolved + * symbol */ /* * Some platforms still add an underscore to the beginning of symbol @@ -147,25 +165,29 @@ TclpFindSymbol( */ native = Tcl_UtfToExternalDString(NULL, symbol, -1, &ds); - proc = (Tcl_PackageInitProc *) dlsym(handle, /* INTL: Native. */ - native); + proc = dlsym(handle, native); /* INTL: Native. */ if (proc == NULL) { Tcl_DStringInit(&newName); Tcl_DStringAppend(&newName, "_", 1); native = Tcl_DStringAppend(&newName, native, -1); - proc = (Tcl_PackageInitProc *) dlsym(handle, /* INTL: Native. */ - native); + proc = dlsym(handle, native); /* INTL: Native. */ Tcl_DStringFree(&newName); } Tcl_DStringFree(&ds); - + if (proc == NULL && interp != NULL) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot find symbol \"", symbol, "\": ", + dlerror(), NULL); + Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, + NULL); + } return proc; } /* *---------------------------------------------------------------------- * - * TclpUnloadFile -- + * UnloadFile -- * * Unloads a dynamically loaded binary code file from memory. Code * pointers in the formerly loaded file are no longer valid after calling @@ -180,16 +202,16 @@ TclpFindSymbol( *---------------------------------------------------------------------- */ -void -TclpUnloadFile( +static void +UnloadFile( Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { - void *handle; + void *handle = loadHandle->clientData; - handle = (void *) loadHandle; dlclose(handle); + ckfree(loadHandle); } /* @@ -214,7 +236,7 @@ TclpUnloadFile( int TclGuessPackageName( - CONST char *fileName, /* Name of file containing package (already + const char *fileName, /* Name of file containing package (already * translated to local form if needed). */ Tcl_DString *bufPtr) /* Initialized empty dstring. Append package * name to this if possible. */ diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c index 0a36215..3fba3a5 100644 --- a/unix/tclLoadDyld.c +++ b/unix/tclLoadDyld.c @@ -84,13 +84,23 @@ MODULE_SCOPE long tclMacOSXDarwinRelease; #endif #ifdef TCL_DEBUG_LOAD -#define TclLoadDbgMsg(m, ...) do { \ - fprintf(stderr, "%s:%d: %s(): " m ".\n", \ - strrchr(__FILE__, '/')+1, __LINE__, __func__, ##__VA_ARGS__); \ - } while (0) +#define TclLoadDbgMsg(m, ...) \ + do { \ + fprintf(stderr, "%s:%d: %s(): " m ".\n", \ + strrchr(__FILE__, '/')+1, __LINE__, __func__, \ + ##__VA_ARGS__); \ + } while (0) #else #define TclLoadDbgMsg(m, ...) #endif + +/* + * Static functions defined in this file. + */ + +static void * FindSymbol(Tcl_Interp *interp, + Tcl_LoadHandle loadHandle, const char *symbol); +static void UnloadFile(Tcl_LoadHandle handle); #if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY) /* @@ -110,7 +120,7 @@ MODULE_SCOPE long tclMacOSXDarwinRelease; *---------------------------------------------------------------------- */ -static CONST char* +static const char * DyldOFIErrorMsg( int err) { @@ -165,6 +175,7 @@ TclpDlopen( * file. */ { Tcl_DyldLoadHandle *dyldLoadHandle; + Tcl_LoadHandle newHandle; #if TCL_DYLD_USE_DLFCN void *dlHandle = NULL; #endif @@ -275,8 +286,7 @@ TclpDlopen( | NSLINKMODULE_OPTION_RETURN_ON_ERROR); NSDestroyObjectFileImage(dyldObjFileImage); if (module) { - modulePtr = (Tcl_DyldModuleHandle *) - ckalloc(sizeof(Tcl_DyldModuleHandle)); + modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle)); modulePtr->module = module; modulePtr->nextPtr = NULL; TclLoadDbgMsg("NSLinkModule() successful"); @@ -302,8 +312,7 @@ TclpDlopen( || dyldLibHeader || modulePtr #endif ) { - dyldLoadHandle = (Tcl_DyldLoadHandle *) - ckalloc(sizeof(Tcl_DyldLoadHandle)); + dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle)); #if TCL_DYLD_USE_DLFCN dyldLoadHandle->dlHandle = dlHandle; #endif @@ -311,8 +320,12 @@ TclpDlopen( dyldLoadHandle->dyldLibHeader = dyldLibHeader; dyldLoadHandle->modulePtr = modulePtr; #endif - *loadHandle = (Tcl_LoadHandle) dyldLoadHandle; - *unloadProcPtr = &TclpUnloadFile; + newHandle = ckalloc(sizeof(*newHandle)); + newHandle->clientData = dyldLoadHandle; + newHandle->findSymbolProcPtr = &FindSymbol; + newHandle->unloadFileProcPtr = &UnloadFile; + *unloadProcPtr = &UnloadFile; + *loadHandle = newHandle; result = TCL_OK; } else { Tcl_AppendResult(interp, errMsg, NULL); @@ -333,7 +346,7 @@ TclpDlopen( /* *---------------------------------------------------------------------- * - * TclpFindSymbol -- + * FindSymbol -- * * Looks up a symbol, by name, through a handle associated with a * previously loaded piece of code (shared library). @@ -346,13 +359,13 @@ TclpDlopen( *---------------------------------------------------------------------- */ -MODULE_SCOPE Tcl_PackageInitProc * -TclpFindSymbol( +static void * +FindSymbol( Tcl_Interp *interp, /* For error reporting. */ Tcl_LoadHandle loadHandle, /* Handle from TclpDlopen. */ - CONST char *symbol) /* Symbol name to look up. */ + const char *symbol) /* Symbol name to look up. */ { - Tcl_DyldLoadHandle *dyldLoadHandle = (Tcl_DyldLoadHandle *) loadHandle; + Tcl_DyldLoadHandle *dyldLoadHandle = loadHandle->clientData; Tcl_PackageInitProc *proc = NULL; const char *errMsg = NULL; Tcl_DString ds; @@ -404,8 +417,7 @@ TclpFindSymbol( modulePtr = modulePtr->nextPtr; } if (modulePtr == NULL) { - modulePtr = (Tcl_DyldModuleHandle *) - ckalloc(sizeof(Tcl_DyldModuleHandle)); + modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle)); modulePtr->module = module; modulePtr->nextPtr = dyldLoadHandle->modulePtr; dyldLoadHandle->modulePtr = modulePtr; @@ -440,8 +452,11 @@ TclpFindSymbol( #endif /* TCL_DYLD_USE_NSMODULE */ } Tcl_DStringFree(&ds); - if (errMsg) { - Tcl_AppendResult(interp, errMsg, NULL); + if (errMsg && (interp != NULL)) { + Tcl_AppendResult(interp, "cannot find symbol \"", symbol, "\": ", + errMsg, NULL); + Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, + NULL); } return proc; } @@ -449,7 +464,7 @@ TclpFindSymbol( /* *---------------------------------------------------------------------- * - * TclpUnloadFile -- + * UnloadFile -- * * Unloads a dynamically loaded binary code file from memory. Code * pointers in the formerly loaded file are no longer valid after calling @@ -466,13 +481,13 @@ TclpFindSymbol( *---------------------------------------------------------------------- */ -MODULE_SCOPE void -TclpUnloadFile( +static void +UnloadFile( Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { - Tcl_DyldLoadHandle *dyldLoadHandle = (Tcl_DyldLoadHandle *) loadHandle; + Tcl_DyldLoadHandle *dyldLoadHandle = loadHandle->clientData; #if TCL_DYLD_USE_DLFCN if (dyldLoadHandle->dlHandle) { @@ -507,7 +522,8 @@ TclpUnloadFile( } #endif /* TCL_DYLD_USE_NSMODULE */ } - ckfree((char*) dyldLoadHandle); + ckfree(dyldLoadHandle); + ckfree(loadHandle); } /* @@ -532,7 +548,7 @@ TclpUnloadFile( int TclGuessPackageName( - CONST char *fileName, /* Name of file containing package (already + const char *fileName, /* Name of file containing package (already * translated to local form if needed). */ Tcl_DString *bufPtr) /* Initialized empty dstring. Append package * name to this if possible. */ @@ -617,6 +633,7 @@ TclpLoadMemory( * function which should be used for this * file. */ { + Tcl_LoadHandle newHandle; Tcl_DyldLoadHandle *dyldLoadHandle; NSObjectFileImage dyldObjFileImage = NULL; Tcl_DyldModuleHandle *modulePtr; @@ -633,14 +650,14 @@ TclpLoadMemory( uint32_t ms = 0; #ifndef __LP64__ const struct mach_header *mh = NULL; - #define mh_size sizeof(struct mach_header) - #define mh_magic MH_MAGIC - #define arch_abi 0 +# define mh_size sizeof(struct mach_header) +# define mh_magic MH_MAGIC +# define arch_abi 0 #else const struct mach_header_64 *mh = NULL; - #define mh_size sizeof(struct mach_header_64) - #define mh_magic MH_MAGIC_64 - #define arch_abi CPU_ARCH_ABI64 +# define mh_size sizeof(struct mach_header_64) +# define mh_magic MH_MAGIC_64 +# define arch_abi CPU_ARCH_ABI64 #endif if ((size_t) codeSize >= sizeof(struct fat_header) @@ -751,18 +768,21 @@ TclpLoadMemory( * Stash the module reference within the load handle we create and return. */ - modulePtr = (Tcl_DyldModuleHandle *) ckalloc(sizeof(Tcl_DyldModuleHandle)); + modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle)); modulePtr->module = module; modulePtr->nextPtr = NULL; - dyldLoadHandle = (Tcl_DyldLoadHandle *) - ckalloc(sizeof(Tcl_DyldLoadHandle)); + dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle)); #if TCL_DYLD_USE_DLFCN dyldLoadHandle->dlHandle = NULL; #endif dyldLoadHandle->dyldLibHeader = NULL; dyldLoadHandle->modulePtr = modulePtr; - *loadHandle = (Tcl_LoadHandle) dyldLoadHandle; - *unloadProcPtr = &TclpUnloadFile; + newHandle = ckalloc(sizeof(*newHandle)); + newHandle->clientData = dyldLoadHandle; + newHandle->findSymbolProcPtr = &FindSymbol; + newHandle->unloadFileProcPtr = &UnloadFile; + *loadHandle = newHandle; + *unloadProcPtr = &UnloadFile; return TCL_OK; } #endif /* TCL_LOAD_FROM_MEMORY */ diff --git a/unix/tclLoadNext.c b/unix/tclLoadNext.c index 3de3cf1..c74a29a 100644 --- a/unix/tclLoadNext.c +++ b/unix/tclLoadNext.c @@ -6,13 +6,20 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #include <mach-o/rld.h> #include <streams/streams.h> + +/* Static procedures defined within this file */ + +static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle, + const char* symbol); +static void UnloadFile(Tcl_LoadHandle loadHandle); + /* *---------------------------------------------------------------------- @@ -45,10 +52,11 @@ TclpDlopen( * function which should be used for this * file. */ { + Tcl_LoadHandle newHandle; struct mach_header *header; char *fileName; char *files[2]; - CONST char *native; + const char *native; int result = 1; NXStream *errorStream = NXOpenMemory(0,0,NX_READWRITE); @@ -93,8 +101,12 @@ TclpDlopen( } NXCloseMemory(errorStream, NX_FREEBUFFER); - *loadHandle = (Tcl_LoadHandle)1; /* A dummy non-NULL value */ - *unloadProcPtr = &TclpUnloadFile; + newHandle = ckalloc(sizeof(*newHandle)); + newHandle->clientData = INT2PTR(1); + newHandle->findSymbolProcPtr = &FindSymbol; + newHandle->unloadFileProcPtr = &UnloadFile; + *loadHandle = newHandle; + *unloadProcPtr = &UnloadFile; return TCL_OK; } @@ -102,7 +114,7 @@ TclpDlopen( /* *---------------------------------------------------------------------- * - * TclpFindSymbol -- + * FindSymbol -- * * Looks up a symbol, by name, through a handle associated with a * previously loaded piece of code (shared library). @@ -115,11 +127,11 @@ TclpDlopen( *---------------------------------------------------------------------- */ -Tcl_PackageInitProc * -TclpFindSymbol( +static void* +FindSymbol( Tcl_Interp *interp, Tcl_LoadHandle loadHandle, - CONST char *symbol) + const char *symbol) { Tcl_PackageInitProc *proc = NULL; if (symbol) { @@ -130,13 +142,19 @@ TclpFindSymbol( strcat(sym, symbol); rld_lookup(NULL, sym, (unsigned long *)&proc); } + if (proc == NULL && interp != NULL) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot find symbol \"", symbol, + "\"", NULL); + Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL); + } return proc; } /* *---------------------------------------------------------------------- * - * TclpUnloadFile -- + * UnloadFile -- * * Unloads a dynamically loaded binary code file from memory. Code * pointers in the formerly loaded file are no longer valid after calling @@ -152,11 +170,12 @@ TclpFindSymbol( */ void -TclpUnloadFile( +UnloadFile( Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { + ckfree(loadHandle); } /* @@ -181,7 +200,7 @@ TclpUnloadFile( int TclGuessPackageName( - CONST char *fileName, /* Name of file containing package (already + const char *fileName, /* Name of file containing package (already * translated to local form if needed). */ Tcl_DString *bufPtr) /* Initialized empty dstring. Append package * name to this if possible. */ diff --git a/unix/tclLoadOSF.c b/unix/tclLoadOSF.c index 37536cf..fbd4d5f 100644 --- a/unix/tclLoadOSF.c +++ b/unix/tclLoadOSF.c @@ -36,6 +36,12 @@ #include <sys/types.h> #include <loader.h> +/* Static functions defined within this file */ + +static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle, + const char* symbol); +static void UnloadFile(Tcl_LoadHandle handle); + /* *---------------------------------------------------------------------- * @@ -67,10 +73,11 @@ TclpDlopen( * function which should be used for this * file. */ { + Tcl_LoadHandle newHandle; ldr_module_t lm; char *pkg; char *fileName = Tcl_GetString(pathPtr); - CONST char *native; + const char *native; /* * First try the full path the user gave us. This is particularly @@ -117,15 +124,19 @@ TclpDlopen( } else { pkg++; } - *loadHandle = pkg; - *unloadProcPtr = &TclpUnloadFile; + newHandle = ckalloc(sizeof(*newHandle)); + newHandle->clientData = pkg; + newHandle->findSymbolProcPtr = &FindSymbol; + newHandle->unloadFileProcPtr = &UnloadFile; + *loadHandle = newHandle; + *unloadProcPtr = &UnloadFile; return TCL_OK; } /* *---------------------------------------------------------------------- * - * TclpFindSymbol -- + * FindSymbol -- * * Looks up a symbol, by name, through a handle associated with a * previously loaded piece of code (shared library). @@ -138,19 +149,25 @@ TclpDlopen( *---------------------------------------------------------------------- */ -Tcl_PackageInitProc * -TclpFindSymbol( +static void * +FindSymbol( Tcl_Interp *interp, Tcl_LoadHandle loadHandle, - CONST char *symbol) + const char *symbol) { - return ldr_lookup_package((char *)loadHandle, symbol); + void* retval = ldr_lookup_package((char *)loadHandle, symbol); + if (retval == NULL && interp != NULL) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot find symbol\"", symbol, "\"", NULL); + Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL); + } + return retval; } /* *---------------------------------------------------------------------- * - * TclpUnloadFile -- + * UnloadFile -- * * Unloads a dynamically loaded binary code file from memory. Code * pointers in the formerly loaded file are no longer valid after calling @@ -165,12 +182,13 @@ TclpFindSymbol( *---------------------------------------------------------------------- */ -void -TclpUnloadFile( +static void +UnloadFile( Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { + ckfree(loadHandle); } /* @@ -195,7 +213,7 @@ TclpUnloadFile( int TclGuessPackageName( - CONST char *fileName, /* Name of file containing package (already + const char *fileName, /* Name of file containing package (already * translated to local form if needed). */ Tcl_DString *bufPtr) /* Initialized empty dstring. Append package * name to this if possible. */ diff --git a/unix/tclLoadShl.c b/unix/tclLoadShl.c index c9e4e27..9656983 100644 --- a/unix/tclLoadShl.c +++ b/unix/tclLoadShl.c @@ -23,6 +23,14 @@ #include "tclInt.h" +/* Static functions defined within this file */ + +static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle, + const char* symbol); +static void +UnloadFile(Tcl_LoadHandle handle); + + /* *---------------------------------------------------------------------- * @@ -55,7 +63,8 @@ TclpDlopen( * file. */ { shl_t handle; - CONST char *native; + Tcl_LoadHandle newHandle; + const char *native; char *fileName = Tcl_GetString(pathPtr); /* @@ -95,15 +104,18 @@ TclpDlopen( Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } - *loadHandle = (Tcl_LoadHandle) handle; - *unloadProcPtr = &TclpUnloadFile; + newHandle = ckalloc(sizeof(*newHandle)); + newHandle->clientData = handle; + newHandle->findSymbolProcPtr = &FindSymbol; + newHandle->unloadFileProcPtr = *unloadProcPtr = &UnloadFile; + *loadHandle = newHandle; return TCL_OK; } /* *---------------------------------------------------------------------- * - * TclpFindSymbol -- + * Tcl_FindSymbol -- * * Looks up a symbol, by name, through a handle associated with a * previously loaded piece of code (shared library). @@ -116,15 +128,15 @@ TclpDlopen( *---------------------------------------------------------------------- */ -Tcl_PackageInitProc * -TclpFindSymbol( +static void* +FindSymbol( Tcl_Interp *interp, Tcl_LoadHandle loadHandle, - CONST char *symbol) + const char *symbol) { Tcl_DString newName; Tcl_PackageInitProc *proc = NULL; - shl_t handle = (shl_t)loadHandle; + shl_t handle = (shl_t)(loadHandle->clientData); /* * Some versions of the HP system software still use "_" at the beginning @@ -142,13 +154,18 @@ TclpFindSymbol( } Tcl_DStringFree(&newName); } + if (proc == NULL && interp != NULL) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot find symbol\"", symbol, + "\": ", Tcl_PosixError(interp), NULL); + } return proc; } /* *---------------------------------------------------------------------- * - * TclpUnloadFile -- + * UnloadFile -- * * Unloads a dynamically loaded binary code file from memory. Code * pointers in the formerly loaded file are no longer valid after calling @@ -163,16 +180,17 @@ TclpFindSymbol( *---------------------------------------------------------------------- */ -void -TclpUnloadFile( +static void +UnloadFile( Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to * TclpDlopen(). The loadHandle is a token * that represents the loaded file. */ { shl_t handle; - handle = (shl_t) loadHandle; + handle = (shl_t) (loadHandle -> clientData); shl_unload(handle); + ckfree(loadHandle); } /* @@ -197,7 +215,7 @@ TclpUnloadFile( int TclGuessPackageName( - CONST char *fileName, /* Name of file containing package (already + const char *fileName, /* Name of file containing package (already * translated to local form if needed). */ Tcl_DString *bufPtr) /* Initialized empty dstring. Append package * name to this if possible. */ diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 53c5c47..866d77d 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -7,8 +7,8 @@ * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright (c) 1998-1999 by Scriptics Corporation. * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" /* Internal definitions for Tcl. */ @@ -139,63 +139,13 @@ typedef struct TtyAttrs { if (interp) { \ Tcl_AppendResult(interp, (detail), \ " not supported for this platform", NULL); \ + Tcl_SetErrorCode(interp, "TCL", "UNSUPPORTED", NULL); \ } /* - * This structure describes per-instance state of a tcp based channel. - */ - -typedef struct TcpState { - Tcl_Channel channel; /* Channel associated with this file. */ - int fd; /* The socket itself. */ - int flags; /* ORed combination of the bitfields defined - * below. */ - Tcl_TcpAcceptProc *acceptProc; - /* Proc to call on accept. */ - ClientData acceptProcData; /* The data for the accept proc. */ -} TcpState; - -/* - * These bits may be ORed together into the "flags" field of a TcpState - * structure. - */ - -#define TCP_ASYNC_SOCKET (1<<0) /* Asynchronous socket. */ -#define TCP_ASYNC_CONNECT (1<<1) /* Async connect in progress. */ - -/* - * The following defines the maximum length of the listen queue. This is the - * number of outstanding yet-to-be-serviced requests for a connection on a - * server socket, more than this number of outstanding requests and the - * connection request will fail. - */ - -#ifndef SOMAXCONN -# define SOMAXCONN 100 -#endif /* SOMAXCONN */ - -#if (SOMAXCONN < 100) -# undef SOMAXCONN -# define SOMAXCONN 100 -#endif /* SOMAXCONN < 100 */ - -/* - * The following defines how much buffer space the kernel should maintain for - * a socket. - */ - -#define SOCKET_BUFSIZE 4096 - -/* * Static routines for this file: */ -static TcpState * CreateSocket(Tcl_Interp *interp, int port, - const char *host, int server, const char *myaddr, - int myport, int async); -static int CreateSocketAddress(struct sockaddr_in *sockaddrPtr, - const char *host, int port, int willBind, - const char **errorMsgPtr); static int FileBlockModeProc(ClientData instanceData, int mode); static int FileCloseProc(ClientData instanceData, Tcl_Interp *interp); @@ -212,20 +162,6 @@ static int FileTruncateProc(ClientData instanceData, static Tcl_WideInt FileWideSeekProc(ClientData instanceData, Tcl_WideInt offset, int mode, int *errorCode); static void FileWatchProc(ClientData instanceData, int mask); -static void TcpAccept(ClientData data, int mask); -static int TcpBlockModeProc(ClientData data, int mode); -static int TcpCloseProc(ClientData instanceData, - Tcl_Interp *interp); -static int TcpGetHandleProc(ClientData instanceData, - int direction, ClientData *handlePtr); -static int TcpGetOptionProc(ClientData instanceData, - Tcl_Interp *interp, const char *optionName, - Tcl_DString *dsPtr); -static int TcpInputProc(ClientData instanceData, char *buf, - int toRead, int *errorCode); -static int TcpOutputProc(ClientData instanceData, - const char *buf, int toWrite, int *errorCode); -static void TcpWatchProc(ClientData instanceData, int mask); #ifdef SUPPORTS_TTY static void TtyGetAttributes(int fd, TtyAttrs *ttyPtr); static int TtyGetOptionProc(ClientData instanceData, @@ -245,15 +181,12 @@ static int TtySetOptionProc(ClientData instanceData, Tcl_Interp *interp, const char *optionName, const char *value); #endif /* SUPPORTS_TTY */ -static int WaitForConnect(TcpState *statePtr, int *errorCodePtr); -static Tcl_Channel MakeTcpClientChannelMode(ClientData tcpSocket, - int mode); /* * This structure describes the channel type structure for file based IO: */ -static Tcl_ChannelType fileChannelType = { +static const Tcl_ChannelType fileChannelType = { "file", /* Type name. */ TCL_CHANNEL_VERSION_5, /* v5 channel */ FileCloseProc, /* Close proc. */ @@ -270,7 +203,7 @@ static Tcl_ChannelType fileChannelType = { NULL, /* handler proc. */ FileWideSeekProc, /* wide seek proc. */ NULL, - FileTruncateProc, /* truncate proc. */ + FileTruncateProc /* truncate proc. */ }; #ifdef SUPPORTS_TTY @@ -279,7 +212,7 @@ static Tcl_ChannelType fileChannelType = { * Note that this type is a subclass of the "file" type. */ -static Tcl_ChannelType ttyChannelType = { +static const Tcl_ChannelType ttyChannelType = { "tty", /* Type name. */ TCL_CHANNEL_VERSION_5, /* v5 channel */ FileCloseProc, /* Close proc. */ @@ -296,34 +229,9 @@ static Tcl_ChannelType ttyChannelType = { NULL, /* handler proc. */ NULL, /* wide seek proc. */ NULL, /* thread action proc. */ - NULL, /* truncate proc. */ + NULL /* truncate proc. */ }; #endif /* SUPPORTS_TTY */ - -/* - * This structure describes the channel type structure for TCP socket - * based IO: - */ - -static Tcl_ChannelType tcpChannelType = { - "tcp", /* Type name. */ - TCL_CHANNEL_VERSION_5, /* v5 channel */ - TcpCloseProc, /* Close proc. */ - TcpInputProc, /* Input proc. */ - TcpOutputProc, /* Output proc. */ - NULL, /* Seek proc. */ - NULL, /* Set option proc. */ - TcpGetOptionProc, /* Get option proc. */ - TcpWatchProc, /* Initialize notifier. */ - TcpGetHandleProc, /* Get OS handles out of channel. */ - NULL, /* close2proc. */ - TcpBlockModeProc, /* Set blocking or non-blocking mode.*/ - NULL, /* flush proc. */ - NULL, /* handler proc. */ - NULL, /* wide seek proc. */ - NULL, /* thread action proc. */ - NULL, /* truncate proc. */ -}; /* *---------------------------------------------------------------------- @@ -346,11 +254,10 @@ static Tcl_ChannelType tcpChannelType = { static int FileBlockModeProc( ClientData instanceData, /* File state. */ - int mode) /* The mode to set. Can be one of - * TCL_MODE_BLOCKING or - * TCL_MODE_NONBLOCKING. */ + int mode) /* The mode to set. Can be TCL_MODE_BLOCKING + * or TCL_MODE_NONBLOCKING. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; if (TclUnixSetBlockingMode(fsPtr->fd, mode) < 0) { return errno; @@ -385,7 +292,7 @@ FileInputProc( * buffer? */ int *errorCodePtr) /* Where to store error code. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; int bytesRead; /* How many bytes were actually read from the * input device? */ @@ -431,7 +338,7 @@ FileOutputProc( int toWrite, /* How many bytes to write? */ int *errorCodePtr) /* Where to store error code. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; int written; *errorCodePtr = 0; @@ -475,7 +382,7 @@ FileCloseProc( ClientData instanceData, /* File state. */ Tcl_Interp *interp) /* For error reporting - unused. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; int errorCode = 0; Tcl_DeleteFileHandler(fsPtr->fd); @@ -490,7 +397,7 @@ FileCloseProc( errorCode = errno; } } - ckfree((char *) fsPtr); + ckfree(fsPtr); return errorCode; } @@ -521,7 +428,7 @@ FileSeekProc( * one of SEEK_START, SEEK_SET or SEEK_END. */ int *errorCodePtr) /* To store error code. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; Tcl_WideInt oldLoc, newLoc; /* @@ -582,7 +489,7 @@ FileWideSeekProc( * one of SEEK_START, SEEK_CUR or SEEK_END. */ int *errorCodePtr) /* To store error code. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; Tcl_WideInt newLoc; newLoc = TclOSseek(fsPtr->fd, (Tcl_SeekOffset) offset, mode); @@ -615,7 +522,7 @@ FileWatchProc( * TCL_READABLE, TCL_WRITABLE and * TCL_EXCEPTION. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; /* * Make sure we only register for events that are valid on this file. Note @@ -626,8 +533,7 @@ FileWatchProc( mask &= fsPtr->validMask; if (mask) { Tcl_CreateFileHandler(fsPtr->fd, mask, - (Tcl_FileProc *) Tcl_NotifyChannel, - (ClientData) fsPtr->channel); + (Tcl_FileProc *) Tcl_NotifyChannel, fsPtr->channel); } else { Tcl_DeleteFileHandler(fsPtr->fd); } @@ -657,10 +563,10 @@ FileGetHandleProc( int direction, /* TCL_READABLE or TCL_WRITABLE */ ClientData *handlePtr) /* Where to store the handle. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; if (direction & fsPtr->validMask) { - *handlePtr = (ClientData) INT2PTR(fsPtr->fd); + *handlePtr = INT2PTR(fsPtr->fd); return TCL_OK; } return TCL_ERROR; @@ -727,7 +633,7 @@ TtySetOptionProc( const char *optionName, /* Which option to set? */ const char *value) /* New value for option. */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; unsigned int len, vlen; TtyAttrs tty; #ifdef USE_TERMIOS @@ -742,6 +648,7 @@ TtySetOptionProc( /* * Option -mode baud,parity,databits,stopbits */ + if ((len > 2) && (strncmp(optionName, "-mode", len) == 0)) { if (TtyParseMode(interp, value, &tty.baud, &tty.parity, &tty.data, &tty.stop) != TCL_OK) { @@ -773,7 +680,9 @@ TtySetOptionProc( CLEAR_BITS(iostate.c_cflag, CRTSCTS); #endif /* CRTSCTS */ if (strncasecmp(value, "NONE", vlen) == 0) { - /* leave all handshake options disabled */ + /* + * Leave all handshake options disabled. + */ } else if (strncasecmp(value, "XONXOFF", vlen) == 0) { SET_BITS(iostate.c_iflag, IXON | IXOFF | IXANY); } else if (strncasecmp(value, "RTSCTS", vlen) == 0) { @@ -791,6 +700,8 @@ TtySetOptionProc( Tcl_AppendResult(interp, "bad value for -handshake: " "must be one of xonxoff, rtscts, dtrdsr or none", NULL); + Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE", + "VALUE", NULL); } return TCL_ERROR; } @@ -803,31 +714,33 @@ TtySetOptionProc( */ if ((len > 1) && (strncmp(optionName, "-xchar", len) == 0)) { - GETIOSTATE(fsPtr->fd, &iostate); + Tcl_DString ds; + if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) { return TCL_ERROR; - } - if (argc == 2) { - Tcl_DString ds; - Tcl_DStringInit(&ds); - - Tcl_UtfToExternalDString(NULL, argv[0], -1, &ds); - iostate.c_cc[VSTART] = *(const cc_t *) Tcl_DStringValue(&ds); - Tcl_DStringSetLength(&ds, 0); - - Tcl_UtfToExternalDString(NULL, argv[1], -1, &ds); - iostate.c_cc[VSTOP] = *(const cc_t *) Tcl_DStringValue(&ds); - Tcl_DStringFree(&ds); - } else { + } else if (argc != 2) { if (interp) { Tcl_AppendResult(interp, "bad value for -xchar: " "should be a list of two elements", NULL); + Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE", + "VALUE", NULL); } - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } + + GETIOSTATE(fsPtr->fd, &iostate); + + Tcl_UtfToExternalDString(NULL, argv[0], -1, &ds); + iostate.c_cc[VSTART] = *(const cc_t *) Tcl_DStringValue(&ds); + Tcl_DStringSetLength(&ds, 0); + + Tcl_UtfToExternalDString(NULL, argv[1], -1, &ds); + iostate.c_cc[VSTOP] = *(const cc_t *) Tcl_DStringValue(&ds); + Tcl_DStringFree(&ds); + ckfree(argv); + SETIOSTATE(fsPtr->fd, &iostate); - ckfree((char *) argv); return TCL_OK; } @@ -862,15 +775,17 @@ TtySetOptionProc( if (interp) { Tcl_AppendResult(interp, "bad value for -ttycontrol: " "should be a list of signal,value pairs", NULL); + Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE", + "VALUE", NULL); } - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } GETCONTROL(fsPtr->fd, &control); for (i = 0; i < argc-1; i += 2) { if (Tcl_GetBoolean(interp, argv[i+1], &flag) == TCL_ERROR) { - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } if (strncasecmp(argv[i], "DTR", strlen(argv[i])) == 0) { @@ -882,7 +797,7 @@ TtySetOptionProc( } #else /* !TIOCM_DTR */ UNSUPPORTED_OPTION("-ttycontrol DTR"); - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; #endif /* TIOCM_DTR */ } else if (strncasecmp(argv[i], "RTS", strlen(argv[i])) == 0) { @@ -894,7 +809,7 @@ TtySetOptionProc( } #else /* !TIOCM_RTS*/ UNSUPPORTED_OPTION("-ttycontrol RTS"); - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; #endif /* TIOCM_RTS*/ } else if (strncasecmp(argv[i], "BREAK", strlen(argv[i])) == 0) { @@ -902,7 +817,7 @@ TtySetOptionProc( SETBREAK(fsPtr->fd, flag); #else /* !SETBREAK */ UNSUPPORTED_OPTION("-ttycontrol BREAK"); - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; #endif /* SETBREAK */ } else { @@ -910,14 +825,16 @@ TtySetOptionProc( Tcl_AppendResult(interp, "bad signal \"", argv[i], "\" for -ttycontrol: must be " "DTR, RTS or BREAK", NULL); + Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE", + "VALUE", NULL); } - ckfree((char *) argv); + ckfree(argv); return TCL_ERROR; } } /* -ttycontrol options loop */ SETCONTROL(fsPtr->fd, &control); - ckfree((char *) argv); + ckfree(argv); return TCL_OK; } @@ -958,7 +875,7 @@ TtyGetOptionProc( const char *optionName, /* Option to get. */ Tcl_DString *dsPtr) /* Where to store value(s). */ { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; unsigned int len; char buf[3*TCL_INTEGER_SPACE + 16]; int valid = 0; /* Flag if valid option parsed. */ @@ -992,17 +909,17 @@ TtyGetOptionProc( if (len==0 || (len>1 && strncmp(optionName, "-xchar", len)==0)) { IOSTATE iostate; Tcl_DString ds; - valid = 1; + valid = 1; GETIOSTATE(fsPtr->fd, &iostate); Tcl_DStringInit(&ds); - Tcl_ExternalToUtfDString(NULL, (const char *) &iostate.c_cc[VSTART], 1, &ds); - Tcl_DStringAppendElement(dsPtr, (const char *) Tcl_DStringValue(&ds)); + Tcl_ExternalToUtfDString(NULL, (char *) &iostate.c_cc[VSTART], 1, &ds); + Tcl_DStringAppendElement(dsPtr, Tcl_DStringValue(&ds)); Tcl_DStringSetLength(&ds, 0); - Tcl_ExternalToUtfDString(NULL, (const char *) &iostate.c_cc[VSTOP], 1, &ds); - Tcl_DStringAppendElement(dsPtr, (const char *) Tcl_DStringValue(&ds)); + Tcl_ExternalToUtfDString(NULL, (char *) &iostate.c_cc[VSTOP], 1, &ds); + Tcl_DStringAppendElement(dsPtr, Tcl_DStringValue(&ds)); Tcl_DStringFree(&ds); } if (len == 0) { @@ -1039,6 +956,7 @@ TtyGetOptionProc( * Option is readonly and returned by [fconfigure chan -ttystatus] but not * returned by unnamed [fconfigure chan]. */ + if ((len > 4) && (strncmp(optionName, "-ttystatus", len) == 0)) { int status; @@ -1276,7 +1194,7 @@ TtyGetAttributes( case PARENB : parity = 'e'; break; case PARENB | PARODD : parity = 'o'; break; } -#endif /* !PAREXT */ +#endif /* PAREXT */ data = iostate.c_cflag & CSIZE; data = (data == CS5) ? 5 : (data == CS6) ? 6 : (data == CS7) ? 7 : 8; @@ -1472,6 +1390,7 @@ TtyParseMode( if (interp != NULL) { Tcl_AppendResult(interp, bad, ": should be baud,parity,data,stop", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL); } return TCL_ERROR; } @@ -1479,13 +1398,19 @@ TtyParseMode( /* * Only allow setting mark/space parity on platforms that support it Make * sure to allow for the case where strchr is a macro. [Bug: 5089] + * + * We cannot if/else/endif the strchr arguments, it has to be the whole + * function. On AIX this function is apparently a macro, and macros do + * not allow pre-processor directives in their arguments. */ + if ( #if defined(PAREXT) || defined(USE_TERMIO) - if (strchr("noems", parity) == NULL) { + strchr("noems", parity) #else - if (strchr("noe", parity) == NULL) { + strchr("noe", parity) #endif /* PAREXT|USE_TERMIO */ + == NULL) { if (interp != NULL) { Tcl_AppendResult(interp, bad, " parity: should be ", #if defined(PAREXT) || defined(USE_TERMIO) @@ -1494,6 +1419,7 @@ TtyParseMode( "n, o, or e", #endif /* PAREXT|USE_TERMIO */ NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL); } return TCL_ERROR; } @@ -1502,12 +1428,14 @@ TtyParseMode( if (interp != NULL) { Tcl_AppendResult(interp, bad, " data: should be 5, 6, 7, or 8", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL); } return TCL_ERROR; } if ((*stopPtr < 0) || (*stopPtr > 2)) { if (interp != NULL) { Tcl_AppendResult(interp, bad, " stop: should be 1 or 2", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL); } return TCL_ERROR; } @@ -1543,21 +1471,20 @@ TtyInit( * initialized. */ int initialize) { - TtyState *ttyPtr; + TtyState *ttyPtr = ckalloc(sizeof(TtyState)); int stateUpdated = 0; - ttyPtr = (TtyState *) ckalloc((unsigned) sizeof(TtyState)); GETIOSTATE(fd, &ttyPtr->savedState); if (initialize) { IOSTATE iostate = ttyPtr->savedState; #if defined(USE_TERMIOS) || defined(USE_TERMIO) - if (iostate.c_iflag != IGNBRK || - iostate.c_oflag != 0 || - iostate.c_lflag != 0 || - iostate.c_cflag & CREAD || - iostate.c_cc[VMIN] != 1 || - iostate.c_cc[VTIME] != 0) { + if (iostate.c_iflag != IGNBRK + || iostate.c_oflag != 0 + || iostate.c_lflag != 0 + || iostate.c_cflag & CREAD + || iostate.c_cc[VMIN] != 1 + || iostate.c_cc[VTIME] != 0) { stateUpdated = 1; } iostate.c_iflag = IGNBRK; @@ -1569,8 +1496,8 @@ TtyInit( #endif /* USE_TERMIOS|USE_TERMIO */ #ifdef USE_SGTTY - if ((iostate.sg_flags & (EVENP | ODDP)) || - !(iostate.sg_flags & RAW)) { + if ((iostate.sg_flags & (EVENP | ODDP)) + || !(iostate.sg_flags & RAW)) { ttyPtr->stateUpdated = 1; } iostate.sg_flags &= EVENP | ODDP; @@ -1622,7 +1549,7 @@ TclpOpenFileChannel( FileState *fsPtr; const char *native, *translation; char channelName[16 + TCL_INTEGER_SPACE]; - Tcl_ChannelType *channelTypePtr; + const Tcl_ChannelType *channelTypePtr; switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) { case O_RDONLY: @@ -1695,14 +1622,14 @@ TclpOpenFileChannel( { translation = NULL; channelTypePtr = &fileChannelType; - fsPtr = (FileState *) ckalloc((unsigned) sizeof(FileState)); + fsPtr = ckalloc(sizeof(FileState)); } fsPtr->validMask = channelPermissions | TCL_EXCEPTION; fsPtr->fd = fd; fsPtr->channel = Tcl_CreateChannel(channelTypePtr, channelName, - (ClientData) fsPtr, channelPermissions); + fsPtr, channelPermissions); if (translation != NULL) { /* @@ -1748,7 +1675,7 @@ Tcl_MakeFileChannel( FileState *fsPtr; char channelName[16 + TCL_INTEGER_SPACE]; int fd = PTR2INT(handle); - Tcl_ChannelType *channelTypePtr; + const Tcl_ChannelType *channelTypePtr; struct sockaddr sockaddr; socklen_t sockaddrLen = sizeof(sockaddr); @@ -1765,20 +1692,20 @@ Tcl_MakeFileChannel( sprintf(channelName, "serial%d", fd); } else #endif /* SUPPORTS_TTY */ - if (getsockname(fd, (struct sockaddr *)&sockaddr, &sockaddrLen) == 0 - && sockaddrLen > 0 - && sockaddr.sa_family == AF_INET) { - return MakeTcpClientChannelMode((ClientData) INT2PTR(fd), mode); + if ((getsockname(fd, (struct sockaddr *)&sockaddr, &sockaddrLen) == 0) + && (sockaddrLen > 0) + && (sockaddr.sa_family == AF_INET || sockaddr.sa_family == AF_INET6)) { + return TclpMakeTcpClientChannelMode(INT2PTR(fd), mode); } else { channelTypePtr = &fileChannelType; - fsPtr = (FileState *) ckalloc((unsigned) sizeof(FileState)); + fsPtr = ckalloc(sizeof(FileState)); sprintf(channelName, "file%d", fd); } fsPtr->fd = fd; fsPtr->validMask = mode | TCL_EXCEPTION; fsPtr->channel = Tcl_CreateChannel(channelTypePtr, channelName, - (ClientData) fsPtr, mode); + fsPtr, mode); return fsPtr->channel; } @@ -1786,1033 +1713,6 @@ Tcl_MakeFileChannel( /* *---------------------------------------------------------------------- * - * TcpBlockModeProc -- - * - * This function is invoked by the generic IO level to set blocking and - * nonblocking mode on a TCP socket based channel. - * - * Results: - * 0 if successful, errno when failed. - * - * Side effects: - * Sets the device into blocking or nonblocking mode. - * - *---------------------------------------------------------------------- - */ - - /* ARGSUSED */ -static int -TcpBlockModeProc( - ClientData instanceData, /* Socket state. */ - int mode) /* The mode to set. Can be one of - * TCL_MODE_BLOCKING or - * TCL_MODE_NONBLOCKING. */ -{ - TcpState *statePtr = (TcpState *) instanceData; - - if (mode == TCL_MODE_BLOCKING) { - CLEAR_BITS(statePtr->flags, TCP_ASYNC_SOCKET); - } else { - SET_BITS(statePtr->flags, TCP_ASYNC_SOCKET); - } - if (TclUnixSetBlockingMode(statePtr->fd, mode) < 0) { - return errno; - } - return 0; -} - -/* - *---------------------------------------------------------------------- - * - * WaitForConnect -- - * - * Waits for a connection on an asynchronously opened socket to be - * completed. - * - * Results: - * None. - * - * Side effects: - * The socket is connected after this function returns. - * - *---------------------------------------------------------------------- - */ - -static int -WaitForConnect( - TcpState *statePtr, /* State of the socket. */ - int *errorCodePtr) /* Where to store errors? */ -{ - int timeOut; /* How long to wait. */ - int state; /* Of calling TclWaitForFile. */ - - /* - * If an asynchronous connect is in progress, attempt to wait for it to - * complete before reading. - */ - - if (statePtr->flags & TCP_ASYNC_CONNECT) { - if (statePtr->flags & TCP_ASYNC_SOCKET) { - timeOut = 0; - } else { - timeOut = -1; - } - errno = 0; - state = TclUnixWaitForFile(statePtr->fd, - TCL_WRITABLE | TCL_EXCEPTION, timeOut); - if (!(statePtr->flags & TCP_ASYNC_SOCKET)) { - (void) TclUnixSetBlockingMode(statePtr->fd, TCL_MODE_BLOCKING); - } - if (state & TCL_EXCEPTION) { - return -1; - } - if (state & TCL_WRITABLE) { - CLEAR_BITS(statePtr->flags, TCP_ASYNC_CONNECT); - } else if (timeOut == 0) { - *errorCodePtr = errno = EWOULDBLOCK; - return -1; - } - } - return 0; -} - -/* - *---------------------------------------------------------------------- - * - * TcpInputProc -- - * - * This function is invoked by the generic IO level to read input from a - * TCP socket based channel. - * - * NOTE: We cannot share code with FilePipeInputProc because here we must - * use recv to obtain the input from the channel, not read. - * - * Results: - * The number of bytes read is returned or -1 on error. An output - * argument contains the POSIX error code on error, or zero if no error - * occurred. - * - * Side effects: - * Reads input from the input device of the channel. - * - *---------------------------------------------------------------------- - */ - - /* ARGSUSED */ -static int -TcpInputProc( - ClientData instanceData, /* Socket state. */ - char *buf, /* Where to store data read. */ - int bufSize, /* How much space is available in the - * buffer? */ - int *errorCodePtr) /* Where to store error code. */ -{ - TcpState *statePtr = (TcpState *) instanceData; - int bytesRead, state; - - *errorCodePtr = 0; - state = WaitForConnect(statePtr, errorCodePtr); - if (state != 0) { - return -1; - } - bytesRead = recv(statePtr->fd, buf, (size_t) bufSize, 0); - if (bytesRead > -1) { - return bytesRead; - } - if (errno == ECONNRESET) { - /* - * Turn ECONNRESET into a soft EOF condition. - */ - - return 0; - } - *errorCodePtr = errno; - return -1; -} - -/* - *---------------------------------------------------------------------- - * - * TcpOutputProc -- - * - * This function is invoked by the generic IO level to write output to a - * TCP socket based channel. - * - * NOTE: We cannot share code with FilePipeOutputProc because here we - * must use send, not write, to get reliable error reporting. - * - * Results: - * The number of bytes written is returned. An output argument is set to - * a POSIX error code if an error occurred, or zero. - * - * Side effects: - * Writes output on the output device of the channel. - * - *---------------------------------------------------------------------- - */ - -static int -TcpOutputProc( - ClientData instanceData, /* Socket state. */ - const char *buf, /* The data buffer. */ - int toWrite, /* How many bytes to write? */ - int *errorCodePtr) /* Where to store error code. */ -{ - TcpState *statePtr = (TcpState *) instanceData; - int written; - int state; /* Of waiting for connection. */ - - *errorCodePtr = 0; - state = WaitForConnect(statePtr, errorCodePtr); - if (state != 0) { - return -1; - } - written = send(statePtr->fd, buf, (size_t) toWrite, 0); - if (written > -1) { - return written; - } - *errorCodePtr = errno; - return -1; -} - -/* - *---------------------------------------------------------------------- - * - * TcpCloseProc -- - * - * This function is invoked by the generic IO level to perform - * channel-type-specific cleanup when a TCP socket based channel is - * closed. - * - * Results: - * 0 if successful, the value of errno if failed. - * - * Side effects: - * Closes the socket of the channel. - * - *---------------------------------------------------------------------- - */ - - /* ARGSUSED */ -static int -TcpCloseProc( - ClientData instanceData, /* The socket to close. */ - Tcl_Interp *interp) /* For error reporting - unused. */ -{ - TcpState *statePtr = (TcpState *) instanceData; - int errorCode = 0; - - /* - * Delete a file handler that may be active for this socket if this is a - * server socket - the file handler was created automatically by Tcl as - * part of the mechanism to accept new client connections. Channel - * handlers are already deleted in the generic IO channel closing code - * that called this function, so we do not have to delete them here. - */ - - Tcl_DeleteFileHandler(statePtr->fd); - - if (close(statePtr->fd) < 0) { - errorCode = errno; - } - ckfree((char *) statePtr); - - return errorCode; -} - -/* - *---------------------------------------------------------------------- - * - * TcpGetOptionProc -- - * - * Computes an option value for a TCP socket based channel, or a list of - * all options and their values. - * - * Note: This code is based on code contributed by John Haxby. - * - * Results: - * A standard Tcl result. The value of the specified option or a list of - * all options and their values is returned in the supplied DString. Sets - * Error message if needed. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static int -TcpGetOptionProc( - ClientData instanceData, /* Socket state. */ - Tcl_Interp *interp, /* For error reporting - can be NULL. */ - const char *optionName, /* Name of the option to retrieve the value - * for, or NULL to get all options and their - * values. */ - Tcl_DString *dsPtr) /* Where to store the computed value; - * initialized by caller. */ -{ - TcpState *statePtr = (TcpState *) instanceData; - struct sockaddr_in sockname; - struct sockaddr_in peername; - struct hostent *hostEntPtr; - socklen_t size = sizeof(struct sockaddr_in); - size_t len = 0; - char buf[TCL_INTEGER_SPACE]; - - if (optionName != NULL) { - len = strlen(optionName); - } - - if ((len > 1) && (optionName[1] == 'e') && - (strncmp(optionName, "-error", len) == 0)) { - socklen_t optlen = sizeof(int); - int err, ret; - - ret = getsockopt(statePtr->fd, SOL_SOCKET, SO_ERROR, - (char *)&err, &optlen); - if (ret < 0) { - err = errno; - } - if (err != 0) { - Tcl_DStringAppend(dsPtr, Tcl_ErrnoMsg(err), -1); - } - return TCL_OK; - } - - if ((len == 0) || - ((len > 1) && (optionName[1] == 'p') && - (strncmp(optionName, "-peername", len) == 0))) { - if (getpeername(statePtr->fd, (struct sockaddr *) &peername, - &size) >= 0) { - if (len == 0) { - Tcl_DStringAppendElement(dsPtr, "-peername"); - Tcl_DStringStartSublist(dsPtr); - } - Tcl_DStringAppendElement(dsPtr, inet_ntoa(peername.sin_addr)); - hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */ - (char *) &peername.sin_addr, - sizeof(peername.sin_addr), AF_INET); - if (hostEntPtr != NULL) { - Tcl_DString ds; - - Tcl_ExternalToUtfDString(NULL, hostEntPtr->h_name, -1, &ds); - Tcl_DStringAppendElement(dsPtr, Tcl_DStringValue(&ds)); - Tcl_DStringFree(&ds); - } else { - Tcl_DStringAppendElement(dsPtr, inet_ntoa(peername.sin_addr)); - } - TclFormatInt(buf, ntohs(peername.sin_port)); - Tcl_DStringAppendElement(dsPtr, buf); - if (len == 0) { - Tcl_DStringEndSublist(dsPtr); - } else { - return TCL_OK; - } - } else { - /* - * getpeername failed - but if we were asked for all the options - * (len==0), don't flag an error at that point because it could be - * an fconfigure request on a server socket (which have no peer). - * Same must be done on win&mac. - */ - - if (len) { - if (interp) { - Tcl_AppendResult(interp, "can't get peername: ", - Tcl_PosixError(interp), NULL); - } - return TCL_ERROR; - } - } - } - - if ((len == 0) || - ((len > 1) && (optionName[1] == 's') && - (strncmp(optionName, "-sockname", len) == 0))) { - if (getsockname(statePtr->fd, (struct sockaddr *) &sockname, - &size) >= 0) { - if (len == 0) { - Tcl_DStringAppendElement(dsPtr, "-sockname"); - Tcl_DStringStartSublist(dsPtr); - } - Tcl_DStringAppendElement(dsPtr, inet_ntoa(sockname.sin_addr)); - if (sockname.sin_addr.s_addr == INADDR_ANY) { - /* - * We don't want to resolve INADDR_ANY; it can sometimes cause - * problems (and never has a name). - */ - - hostEntPtr = NULL; - } else { - hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */ - (char *) &sockname.sin_addr, - sizeof(sockname.sin_addr), AF_INET); - } - if (hostEntPtr != NULL) { - Tcl_DString ds; - - Tcl_ExternalToUtfDString(NULL, hostEntPtr->h_name, -1, &ds); - Tcl_DStringAppendElement(dsPtr, Tcl_DStringValue(&ds)); - Tcl_DStringFree(&ds); - } else { - Tcl_DStringAppendElement(dsPtr, inet_ntoa(sockname.sin_addr)); - } - TclFormatInt(buf, ntohs(sockname.sin_port)); - Tcl_DStringAppendElement(dsPtr, buf); - if (len == 0) { - Tcl_DStringEndSublist(dsPtr); - } else { - return TCL_OK; - } - } else { - if (interp) { - Tcl_AppendResult(interp, "can't get sockname: ", - Tcl_PosixError(interp), NULL); - } - return TCL_ERROR; - } - } - - if (len > 0) { - return Tcl_BadChannelOption(interp, optionName, "peername sockname"); - } - - return TCL_OK; -} - -/* - *---------------------------------------------------------------------- - * - * TcpWatchProc -- - * - * Initialize the notifier to watch the fd from this channel. - * - * Results: - * None. - * - * Side effects: - * Sets up the notifier so that a future event on the channel will be - * seen by Tcl. - * - *---------------------------------------------------------------------- - */ - -static void -TcpWatchProc( - ClientData instanceData, /* The socket state. */ - int mask) /* Events of interest; an OR-ed combination of - * TCL_READABLE, TCL_WRITABLE and - * TCL_EXCEPTION. */ -{ - TcpState *statePtr = (TcpState *) instanceData; - - /* - * Make sure we don't mess with server sockets since they will never be - * readable or writable at the Tcl level. This keeps Tcl scripts from - * interfering with the -accept behavior. - */ - - if (!statePtr->acceptProc) { - if (mask) { - Tcl_CreateFileHandler(statePtr->fd, mask, - (Tcl_FileProc *) Tcl_NotifyChannel, - (ClientData) statePtr->channel); - } else { - Tcl_DeleteFileHandler(statePtr->fd); - } - } -} - -/* - *---------------------------------------------------------------------- - * - * TcpGetHandleProc -- - * - * Called from Tcl_GetChannelHandle to retrieve OS handles from inside a - * TCP socket based channel. - * - * Results: - * Returns TCL_OK with the fd in handlePtr, or TCL_ERROR if there is no - * handle for the specified direction. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - - /* ARGSUSED */ -static int -TcpGetHandleProc( - ClientData instanceData, /* The socket state. */ - int direction, /* Not used. */ - ClientData *handlePtr) /* Where to store the handle. */ -{ - TcpState *statePtr = (TcpState *) instanceData; - - *handlePtr = (ClientData) INT2PTR(statePtr->fd); - return TCL_OK; -} - -/* - *---------------------------------------------------------------------- - * - * CreateSocket -- - * - * This function opens a new socket in client or server mode and - * initializes the TcpState structure. - * - * Results: - * Returns a new TcpState, or NULL with an error in the interp's result, - * if interp is not NULL. - * - * Side effects: - * Opens a socket. - * - *---------------------------------------------------------------------- - */ - -static TcpState * -CreateSocket( - Tcl_Interp *interp, /* For error reporting; can be NULL. */ - int port, /* Port number to open. */ - const char *host, /* Name of host on which to open port. NULL - * implies INADDR_ANY */ - int server, /* 1 if socket should be a server socket, else - * 0 for a client socket. */ - const char *myaddr, /* Optional client-side address */ - int myport, /* Optional client-side port */ - int async) /* If nonzero and creating a client socket, - * attempt to do an async connect. Otherwise - * do a synchronous connect or bind. */ -{ - int status, sock, asyncConnect, curState; - struct sockaddr_in sockaddr; /* socket address */ - struct sockaddr_in mysockaddr; /* Socket address for client */ - TcpState *statePtr; - const char *errorMsg = NULL; - - sock = -1; - if (!CreateSocketAddress(&sockaddr, host, port, 0, &errorMsg)) { - goto addressError; - } - if ((myaddr != NULL || myport != 0) && - !CreateSocketAddress(&mysockaddr, myaddr, myport, 1, &errorMsg)) { - goto addressError; - } - - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) { - goto addressError; - } - - /* - * Set the close-on-exec flag so that the socket will not get inherited by - * child processes. - */ - - fcntl(sock, F_SETFD, FD_CLOEXEC); - - /* - * Set kernel space buffering - */ - - TclSockMinimumBuffers(sock, SOCKET_BUFSIZE); - - asyncConnect = 0; - status = 0; - if (server) { - /* - * Set up to reuse server addresses automatically and bind to the - * specified port. - */ - - status = 1; - (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &status, - sizeof(status)); - status = bind(sock, (struct sockaddr *) &sockaddr, - sizeof(struct sockaddr)); - if (status != -1) { - status = listen(sock, SOMAXCONN); - } - } else { - if (myaddr != NULL || myport != 0) { - curState = 1; - (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (char *) &curState, sizeof(curState)); - status = bind(sock, (struct sockaddr *) &mysockaddr, - sizeof(struct sockaddr)); - if (status < 0) { - goto bindError; - } - } - - /* - * Attempt to connect. The connect may fail at present with an - * EINPROGRESS but at a later time it will complete. The caller will - * set up a file handler on the socket if she is interested in being - * informed when the connect completes. - */ - - if (async) { - status = TclUnixSetBlockingMode(sock, TCL_MODE_NONBLOCKING); - } else { - status = 0; - } - if (status > -1) { - status = connect(sock, (struct sockaddr *) &sockaddr, - sizeof(sockaddr)); - if (status < 0) { - if (errno == EINPROGRESS) { - asyncConnect = 1; - status = 0; - } - } else { - /* - * Here we are if the connect succeeds. In case of an - * asynchronous connect we have to reset the channel to - * blocking mode. This appears to happen not very often, but - * e.g. on a HP 9000/800 under HP-UX B.11.00 we enter this - * stage. [Bug: 4388] - */ - - if (async) { - status = TclUnixSetBlockingMode(sock, TCL_MODE_BLOCKING); - } - } - } - } - - bindError: - if (status < 0) { - if (interp != NULL) { - Tcl_AppendResult(interp, "couldn't open socket: ", - Tcl_PosixError(interp), NULL); - } - if (sock != -1) { - close(sock); - } - return NULL; - } - - /* - * Allocate a new TcpState for this socket. - */ - - statePtr = (TcpState *) ckalloc((unsigned) sizeof(TcpState)); - statePtr->flags = 0; - if (asyncConnect) { - statePtr->flags = TCP_ASYNC_CONNECT; - } - statePtr->fd = sock; - - return statePtr; - - addressError: - if (sock != -1) { - close(sock); - } - if (interp != NULL) { - Tcl_AppendResult(interp, "couldn't open socket: ", - Tcl_PosixError(interp), NULL); - if (errorMsg != NULL) { - Tcl_AppendResult(interp, " (", errorMsg, ")", NULL); - } - } - return NULL; -} - -/* - *---------------------------------------------------------------------- - * - * CreateSocketAddress -- - * - * This function initializes a sockaddr structure for a host and port. - * - * Results: - * 1 if the host was valid, 0 if the host could not be converted to an IP - * address. - * - * Side effects: - * Fills in the *sockaddrPtr structure. - * - *---------------------------------------------------------------------- - */ - -static int -CreateSocketAddress( - struct sockaddr_in *sockaddrPtr, /* Socket address */ - const char *host, /* Host. NULL implies INADDR_ANY */ - int port, /* Port number */ - int willBind, /* Is this an address to bind() to or - * to connect() to? */ - const char **errorMsgPtr) /* Place to store the error message - * detail, if available. */ -{ -#ifdef HAVE_GETADDRINFO - struct addrinfo hints, *resPtr = NULL; - char *native; - Tcl_DString ds; - int result; - - if (host == NULL) { - sockaddrPtr->sin_family = AF_INET; - sockaddrPtr->sin_addr.s_addr = INADDR_ANY; - addPort: - sockaddrPtr->sin_port = htons((unsigned short) (port & 0xFFFF)); - return 1; - } - - (void) memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - if (willBind) { - hints.ai_flags |= AI_PASSIVE; - } - - /* - * Note that getaddrinfo() *is* thread-safe. If a platform doesn't get - * that right, it shouldn't use this part of the code. - */ - - native = Tcl_UtfToExternalDString(NULL, host, -1, &ds); - result = getaddrinfo(native, NULL, &hints, &resPtr); - Tcl_DStringFree(&ds); - if (result == 0) { - memcpy(sockaddrPtr, resPtr->ai_addr, sizeof(struct sockaddr_in)); - freeaddrinfo(resPtr); - goto addPort; - } - - /* - * Ought to use gai_strerror() here... - */ - - switch (result) { - case EAI_NONAME: - case EAI_SERVICE: -#if defined(EAI_ADDRFAMILY) && EAI_ADDRFAMILY != EAI_NONAME - case EAI_ADDRFAMILY: -#endif -#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME - case EAI_NODATA: -#endif - *errorMsgPtr = gai_strerror(result); - errno = EHOSTUNREACH; - return 0; - case EAI_SYSTEM: - return 0; - default: - *errorMsgPtr = gai_strerror(result); - errno = ENXIO; - return 0; - } -#else /* !HAVE_GETADDRINFO */ - struct in_addr addr; /* For 64/32 bit madness */ - - (void) memset(sockaddrPtr, '\0', sizeof(struct sockaddr_in)); - sockaddrPtr->sin_family = AF_INET; - sockaddrPtr->sin_port = htons((unsigned short) (port & 0xFFFF)); - if (host == NULL) { - addr.s_addr = INADDR_ANY; - } else { - struct hostent *hostent; /* Host database entry */ - Tcl_DString ds; - const char *native; - - if (host == NULL) { - native = NULL; - } else { - native = Tcl_UtfToExternalDString(NULL, host, -1, &ds); - } - addr.s_addr = inet_addr(native); /* INTL: Native. */ - - /* - * This is 0xFFFFFFFF to ensure that it compares as a 32bit -1 on - * either 32 or 64 bits systems. - */ - - if (addr.s_addr == 0xFFFFFFFF) { - hostent = TclpGetHostByName(native); /* INTL: Native. */ - if (hostent != NULL) { - memcpy(&addr, hostent->h_addr_list[0], - (size_t) hostent->h_length); - } else { -#ifdef EHOSTUNREACH - errno = EHOSTUNREACH; -#else /* !EHOSTUNREACH */ -#ifdef ENXIO - errno = ENXIO; -#endif /* ENXIO */ -#endif /* EHOSTUNREACH */ - if (native != NULL) { - Tcl_DStringFree(&ds); - } - return 0; /* Error. */ - } - } - if (native != NULL) { - Tcl_DStringFree(&ds); - } - } - - /* - * NOTE: On 64 bit machines the assignment below is rumored to not do the - * right thing. Please report errors related to this if you observe - * incorrect behavior on 64 bit machines such as DEC Alphas. Should we - * modify this code to do an explicit memcpy? - */ - - sockaddrPtr->sin_addr.s_addr = addr.s_addr; - return 1; /* Success. */ -#endif /* HAVE_GETADDRINFO */ -} - -/* - *---------------------------------------------------------------------- - * - * Tcl_OpenTcpClient -- - * - * Opens a TCP client socket and creates a channel around it. - * - * Results: - * The channel or NULL if failed. An error message is returned in the - * interpreter on failure. - * - * Side effects: - * Opens a client socket and creates a new channel. - * - *---------------------------------------------------------------------- - */ - -Tcl_Channel -Tcl_OpenTcpClient( - Tcl_Interp *interp, /* For error reporting; can be NULL. */ - int port, /* Port number to open. */ - const char *host, /* Host on which to open port. */ - const char *myaddr, /* Client-side address */ - int myport, /* Client-side port */ - int async) /* If nonzero, attempt to do an asynchronous - * connect. Otherwise we do a blocking - * connect. */ -{ - TcpState *statePtr; - char channelName[16 + TCL_INTEGER_SPACE]; - - /* - * Create a new client socket and wrap it in a channel. - */ - - statePtr = CreateSocket(interp, port, host, 0, myaddr, myport, async); - if (statePtr == NULL) { - return NULL; - } - - statePtr->acceptProc = NULL; - statePtr->acceptProcData = NULL; - - sprintf(channelName, "sock%d", statePtr->fd); - - statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, - (ClientData) statePtr, (TCL_READABLE | TCL_WRITABLE)); - if (Tcl_SetChannelOption(interp, statePtr->channel, "-translation", - "auto crlf") == TCL_ERROR) { - Tcl_Close(NULL, statePtr->channel); - return NULL; - } - return statePtr->channel; -} - -/* - *---------------------------------------------------------------------- - * - * Tcl_MakeTcpClientChannel -- - * - * Creates a Tcl_Channel from an existing client TCP socket. - * - * Results: - * The Tcl_Channel wrapped around the preexisting TCP socket. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Tcl_Channel -Tcl_MakeTcpClientChannel( - ClientData sock) /* The socket to wrap up into a channel. */ -{ - return MakeTcpClientChannelMode(sock, (TCL_READABLE | TCL_WRITABLE)); -} - -/* - *---------------------------------------------------------------------- - * - * MakeTcpClientChannelMode -- - * - * Creates a Tcl_Channel from an existing client TCP socket - * with given mode. - * - * Results: - * The Tcl_Channel wrapped around the preexisting TCP socket. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static Tcl_Channel -MakeTcpClientChannelMode( - ClientData sock, /* The socket to wrap up into a channel. */ - int mode) /* ORed combination of TCL_READABLE and - * TCL_WRITABLE to indicate file mode. */ -{ - TcpState *statePtr; - char channelName[16 + TCL_INTEGER_SPACE]; - - statePtr = (TcpState *) ckalloc((unsigned) sizeof(TcpState)); - statePtr->fd = PTR2INT(sock); - statePtr->flags = 0; - statePtr->acceptProc = NULL; - statePtr->acceptProcData = NULL; - - sprintf(channelName, "sock%d", statePtr->fd); - - statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, - (ClientData) statePtr, mode); - if (Tcl_SetChannelOption(NULL, statePtr->channel, "-translation", - "auto crlf") == TCL_ERROR) { - Tcl_Close(NULL, statePtr->channel); - return NULL; - } - return statePtr->channel; -} - -/* - *---------------------------------------------------------------------- - * - * Tcl_OpenTcpServer -- - * - * Opens a TCP server socket and creates a channel around it. - * - * Results: - * The channel or NULL if failed. If an error occurred, an error message - * is left in the interp's result if interp is not NULL. - * - * Side effects: - * Opens a server socket and creates a new channel. - * - *---------------------------------------------------------------------- - */ - -Tcl_Channel -Tcl_OpenTcpServer( - Tcl_Interp *interp, /* For error reporting - may be NULL. */ - int port, /* Port number to open. */ - const char *myHost, /* Name of local host. */ - Tcl_TcpAcceptProc *acceptProc, - /* Callback for accepting connections from new - * clients. */ - ClientData acceptProcData) /* Data for the callback. */ -{ - TcpState *statePtr; - char channelName[16 + TCL_INTEGER_SPACE]; - - /* - * Create a new client socket and wrap it in a channel. - */ - - statePtr = CreateSocket(interp, port, myHost, 1, NULL, 0, 0); - if (statePtr == NULL) { - return NULL; - } - - statePtr->acceptProc = acceptProc; - statePtr->acceptProcData = acceptProcData; - - /* - * Set up the callback mechanism for accepting connections from new - * clients. - */ - - Tcl_CreateFileHandler(statePtr->fd, TCL_READABLE, TcpAccept, - (ClientData) statePtr); - sprintf(channelName, "sock%d", statePtr->fd); - statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, - (ClientData) statePtr, 0); - return statePtr->channel; -} - -/* - *---------------------------------------------------------------------- - * - * TcpAccept -- - * Accept a TCP socket connection. This is called by the event loop. - * - * Results: - * None. - * - * Side effects: - * Creates a new connection socket. Calls the registered callback for the - * connection acceptance mechanism. - * - *---------------------------------------------------------------------- - */ - - /* ARGSUSED */ -static void -TcpAccept( - ClientData data, /* Callback token. */ - int mask) /* Not used. */ -{ - TcpState *sockState; /* Client data of server socket. */ - int newsock; /* The new client socket */ - TcpState *newSockState; /* State for new socket. */ - struct sockaddr_in addr; /* The remote address */ - socklen_t len; /* For accept interface */ - char channelName[16 + TCL_INTEGER_SPACE]; - - sockState = (TcpState *) data; - - len = sizeof(struct sockaddr_in); - newsock = accept(sockState->fd, (struct sockaddr *) &addr, &len); - if (newsock < 0) { - return; - } - - /* - * Set close-on-exec flag to prevent the newly accepted socket from being - * inherited by child processes. - */ - - (void) fcntl(newsock, F_SETFD, FD_CLOEXEC); - - newSockState = (TcpState *) ckalloc((unsigned) sizeof(TcpState)); - - newSockState->flags = 0; - newSockState->fd = newsock; - newSockState->acceptProc = NULL; - newSockState->acceptProcData = NULL; - - sprintf(channelName, "sock%d", newsock); - newSockState->channel = Tcl_CreateChannel(&tcpChannelType, channelName, - (ClientData) newSockState, (TCL_READABLE | TCL_WRITABLE)); - - Tcl_SetChannelOption(NULL, newSockState->channel, "-translation", - "auto crlf"); - - if (sockState->acceptProc != NULL) { - (*sockState->acceptProc)(sockState->acceptProcData, - newSockState->channel, inet_ntoa(addr.sin_addr), - ntohs(addr.sin_port)); - } -} - -/* - *---------------------------------------------------------------------- - * * TclpGetDefaultStdChannel -- * * Creates channels for standard input, standard output or standard error @@ -2834,7 +1734,7 @@ TclpGetDefaultStdChannel( Tcl_Channel channel = NULL; int fd = 0; /* Initializations needed to prevent */ int mode = 0; /* compiler warning (used before set). */ - char *bufMode = NULL; + const char *bufMode = NULL; /* * Some #def's to make the code a little clearer! @@ -2879,7 +1779,7 @@ TclpGetDefaultStdChannel( #undef ZERO_OFFSET #undef ERROR_OFFSET - channel = Tcl_MakeFileChannel((ClientData) INT2PTR(fd), mode); + channel = Tcl_MakeFileChannel(INT2PTR(fd), mode); if (channel == NULL) { return NULL; } @@ -2939,16 +1839,20 @@ Tcl_GetOpenFile( FILE *f; chan = Tcl_GetChannel(interp, chanID, &chanMode); - if (chan == (Tcl_Channel) NULL) { + if (chan == NULL) { return TCL_ERROR; } if ((forWriting) && ((chanMode & TCL_WRITABLE) == 0)) { Tcl_AppendResult(interp, "\"", chanID, "\" wasn't opened for writing", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_WRITABLE", + NULL); return TCL_ERROR; } else if ((!forWriting) && ((chanMode & TCL_READABLE) == 0)) { Tcl_AppendResult(interp, "\"", chanID, "\" wasn't opened for reading", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_READABLE", + NULL); return TCL_ERROR; } @@ -2963,11 +1867,10 @@ Tcl_GetOpenFile( #ifdef SUPPORTS_TTY || (chanTypePtr == &ttyChannelType) #endif /* SUPPORTS_TTY */ - || (chanTypePtr == &tcpChannelType) + || (strcmp(chanTypePtr->typeName, "tcp") == 0) || (strcmp(chanTypePtr->typeName, "pipe") == 0)) { if (Tcl_GetChannelHandle(chan, - (forWriting ? TCL_WRITABLE : TCL_READABLE), - (ClientData*) &data) == TCL_OK) { + (forWriting ? TCL_WRITABLE : TCL_READABLE), &data) == TCL_OK) { fd = PTR2INT(data); /* @@ -2980,15 +1883,19 @@ Tcl_GetOpenFile( if (f == NULL) { Tcl_AppendResult(interp, "cannot get a FILE * for \"", chanID, "\"", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", + "FILE_FAILURE", NULL); return TCL_ERROR; } - *filePtr = (ClientData) f; + *filePtr = f; return TCL_OK; } } Tcl_AppendResult(interp, "\"", chanID, "\" cannot be used to get a FILE *", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NO_DESCRIPTOR", + NULL); return TCL_ERROR; } @@ -3034,7 +1941,7 @@ TclUnixWaitForFile( int numFound, result = 0; fd_set readableMask; fd_set writableMask; - fd_set exceptionalMask; + fd_set exceptionMask; #ifndef _DARWIN_C_SOURCE /* @@ -3075,7 +1982,7 @@ TclUnixWaitForFile( FD_ZERO(&readableMask); FD_ZERO(&writableMask); - FD_ZERO(&exceptionalMask); + FD_ZERO(&exceptionMask); /* * Loop in a mini-event loop of our own, waiting for either the file to @@ -3100,14 +2007,14 @@ TclUnixWaitForFile( * Setup the select masks for the fd. */ - if (mask & TCL_READABLE) { + if (mask & TCL_READABLE) { FD_SET(fd, &readableMask); } - if (mask & TCL_WRITABLE) { + if (mask & TCL_WRITABLE) { FD_SET(fd, &writableMask); } if (mask & TCL_EXCEPTION) { - FD_SET(fd, &exceptionalMask); + FD_SET(fd, &exceptionMask); } /* @@ -3115,15 +2022,15 @@ TclUnixWaitForFile( */ numFound = select(fd + 1, &readableMask, &writableMask, - &exceptionalMask, timeoutPtr); + &exceptionMask, timeoutPtr); if (numFound == 1) { - if (FD_ISSET(fd, &readableMask)) { + if (FD_ISSET(fd, &readableMask)) { SET_BITS(result, TCL_READABLE); } - if (FD_ISSET(fd, &writableMask)) { + if (FD_ISSET(fd, &writableMask)) { SET_BITS(result, TCL_WRITABLE); } - if (FD_ISSET(fd, &exceptionalMask)) { + if (FD_ISSET(fd, &exceptionMask)) { SET_BITS(result, TCL_EXCEPTION); } result &= mask; @@ -3176,7 +2083,7 @@ FileTruncateProc( ClientData instanceData, Tcl_WideInt length) { - FileState *fsPtr = (FileState *) instanceData; + FileState *fsPtr = instanceData; int result; #ifdef HAVE_TYPE_OFF64_T @@ -3199,7 +2106,5 @@ FileTruncateProc( * mode: c * c-basic-offset: 4 * fill-column: 78 - * tab-width: 8 - * indent-tabs-mode: nil * End: */ diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c index 4d959d6..0ad3822 100644 --- a/unix/tclUnixCompat.c +++ b/unix/tclUnixCompat.c @@ -67,10 +67,10 @@ TclUnixSetBlockingMode( * 'length' stay aligned. */ -#define PadBuffer(buffer, length, size) \ - if (((length) % (size))) { \ - (buffer) += ((size) - ((length) % (size))); \ - (length) += ((size) - ((length) % (size))); \ +#define PadBuffer(buffer, length, size) \ + if (((length) % (size))) { \ + (buffer) += ((size) - ((length) % (size))); \ + (length) += ((size) - ((length) % (size))); \ } /* @@ -124,7 +124,7 @@ static int CopyGrp(struct group *tgtPtr, char *buf, int buflen); static int CopyHostent(struct hostent *tgtPtr, char *buf, int buflen); static int CopyPwd(struct passwd *tgtPtr, char *buf, int buflen); -static int CopyString(CONST char *src, char *buf, int buflen); +static int CopyString(const char *src, char *buf, int buflen); #endif #endif /* TCL_THREADS */ @@ -769,7 +769,7 @@ CopyArray( #ifdef NEED_COPYSTRING static int CopyString( - CONST char *src, /* String to copy. */ + const char *src, /* String to copy. */ char *buf, /* Buffer to copy into. */ int buflen) /* Size of buffer. */ { diff --git a/unix/tclUnixEvent.c b/unix/tclUnixEvent.c index e4d922d..40aac6f 100644 --- a/unix/tclUnixEvent.c +++ b/unix/tclUnixEvent.c @@ -64,7 +64,7 @@ Tcl_Sleep( } if ((vdelay.sec != 0) || (vdelay.usec != 0)) { - (*tclScaleTimeProcPtr) (&vdelay, tclTimeClientData); + tclScaleTimeProcPtr(&vdelay, tclTimeClientData); } delay.tv_sec = vdelay.sec; diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c index a96a81a..e3d9022 100644 --- a/unix/tclUnixFCmd.c +++ b/unix/tclUnixFCmd.c @@ -47,7 +47,7 @@ #ifndef NO_FSTATFS #include <sys/statfs.h> #endif -#endif +#endif /* !HAVE_STRUCT_STAT_ST_BLKSIZE */ #ifdef HAVE_FTS #include <fts.h> #endif @@ -80,7 +80,7 @@ static int SetPermissionsAttribute(Tcl_Interp *interp, int objIndex, Tcl_Obj *fileName, Tcl_Obj *attributePtr); static int GetModeFromPermString(Tcl_Interp *interp, - char *modeStringPtr, mode_t *modePtr); + const char *modeStringPtr, mode_t *modePtr); #if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) static int GetReadOnlyAttribute(Tcl_Interp *interp, int objIndex, Tcl_Obj *fileName, Tcl_Obj **attributePtrPtr); @@ -93,7 +93,7 @@ static int SetReadOnlyAttribute(Tcl_Interp *interp, int objIndex, */ typedef int (TraversalProc)(Tcl_DString *srcPtr, Tcl_DString *dstPtr, - CONST Tcl_StatBuf *statBufPtr, int type, Tcl_DString *errorPtr); + const Tcl_StatBuf *statBufPtr, int type, Tcl_DString *errorPtr); /* * Constants and variables necessary for file attributes subcommand. @@ -110,9 +110,9 @@ typedef int (TraversalProc)(Tcl_DString *srcPtr, Tcl_DString *dstPtr, */ extern TclFileAttrProcs tclpFileAttrProcs[]; -extern char *tclpFileAttrStrings[]; +extern const char *const tclpFileAttrStrings[]; -#else +#else /* !DJGPP */ enum { UNIX_GROUP_ATTRIBUTE, UNIX_OWNER_ATTRIBUTE, UNIX_PERMISSIONS_ATTRIBUTE, #if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) @@ -125,8 +125,8 @@ enum { UNIX_INVALID_ATTRIBUTE /* lint - last enum value needs no trailing , */ }; -MODULE_SCOPE CONST char *tclpFileAttrStrings[]; -CONST char *tclpFileAttrStrings[] = { +MODULE_SCOPE const char *const tclpFileAttrStrings[]; +const char *const tclpFileAttrStrings[] = { "-group", "-owner", "-permissions", #if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) "-readonly", @@ -137,8 +137,8 @@ CONST char *tclpFileAttrStrings[] = { NULL }; -MODULE_SCOPE CONST TclFileAttrProcs tclpFileAttrProcs[]; -CONST TclFileAttrProcs tclpFileAttrProcs[] = { +MODULE_SCOPE const TclFileAttrProcs tclpFileAttrProcs[]; +const TclFileAttrProcs tclpFileAttrProcs[] = { {GetGroupAttribute, SetGroupAttribute}, {GetOwnerAttribute, SetOwnerAttribute}, {GetPermissionsAttribute, SetPermissionsAttribute}, @@ -152,7 +152,7 @@ CONST TclFileAttrProcs tclpFileAttrProcs[] = { {TclMacOSXGetFileAttribute, TclMacOSXSetFileAttribute}, #endif }; -#endif +#endif /* DJGPP */ /* * This is the maximum number of consecutive readdir/unlink calls that can be @@ -173,20 +173,23 @@ CONST TclFileAttrProcs tclpFileAttrProcs[] = { * Declarations for local procedures defined in this file: */ -static int CopyFileAtts(CONST char *src, - CONST char *dst, CONST Tcl_StatBuf *statBufPtr); -static int DoCopyFile(CONST char *srcPtr, CONST char *dstPtr, - CONST Tcl_StatBuf *statBufPtr); -static int DoCreateDirectory(CONST char *pathPtr); +static int CopyFileAtts(const char *src, + const char *dst, const Tcl_StatBuf *statBufPtr); +static const char * DefaultTempDir(void); +static int DoCopyFile(const char *srcPtr, const char *dstPtr, + const Tcl_StatBuf *statBufPtr); +static int DoCreateDirectory(const char *pathPtr); static int DoRemoveDirectory(Tcl_DString *pathPtr, int recursive, Tcl_DString *errorPtr); -static int DoRenameFile(CONST char *src, CONST char *dst); +static int DoRenameFile(const char *src, const char *dst); static int TraversalCopy(Tcl_DString *srcPtr, - Tcl_DString *dstPtr, CONST Tcl_StatBuf *statBufPtr, - int type, Tcl_DString *errorPtr); + Tcl_DString *dstPtr, + const Tcl_StatBuf *statBufPtr, int type, + Tcl_DString *errorPtr); static int TraversalDelete(Tcl_DString *srcPtr, - Tcl_DString *dstPtr, CONST Tcl_StatBuf *statBufPtr, - int type, Tcl_DString *errorPtr); + Tcl_DString *dstPtr, + const Tcl_StatBuf *statBufPtr, int type, + Tcl_DString *errorPtr); static int TraverseUnixTree(TraversalProc *traversalProc, Tcl_DString *sourcePtr, Tcl_DString *destPtr, Tcl_DString *errorPtr, int doRewind); @@ -199,19 +202,19 @@ static int TraverseUnixTree(TraversalProc *traversalProc, * passing the standard MAXPATHLEN size resolved arg. */ -static char * Realpath(CONST char *path, char *resolved); +static char * Realpath(const char *path, char *resolved); char * Realpath( - CONST char *path, + const char *path, char *resolved) { memset(resolved, 0, MAXPATHLEN); return realpath(path, resolved); } #else -#define Realpath realpath -#endif +# define Realpath realpath +#endif /* PURIFY */ #ifndef NO_REALPATH #if defined(__APPLE__) && defined(TCL_THREADS) && \ @@ -224,16 +227,16 @@ Realpath( */ MODULE_SCOPE long tclMacOSXDarwinRelease; -#define haveRealpath (tclMacOSXDarwinRelease >= 7) +# define haveRealpath (tclMacOSXDarwinRelease >= 7) #else -#define haveRealpath 1 +# define haveRealpath 1 #endif #endif /* NO_REALPATH */ #ifdef HAVE_FTS #ifdef HAVE_STRUCT_STAT64 /* fts doesn't do stat64 */ -#define noFtsStat 1 +# define noFtsStat 1 #elif defined(__APPLE__) && defined(__LP64__) && \ defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \ MAC_OS_X_VERSION_MIN_REQUIRED < 1050 @@ -244,9 +247,9 @@ MODULE_SCOPE long tclMacOSXDarwinRelease; */ MODULE_SCOPE long tclMacOSXDarwinRelease; -#define noFtsStat (tclMacOSXDarwinRelease < 9) +# define noFtsStat (tclMacOSXDarwinRelease < 9) #else -#define noFtsStat 0 +# define noFtsStat 0 #endif #endif /* HAVE_FTS */ @@ -295,9 +298,9 @@ TclpObjRenameFile( static int DoRenameFile( - CONST char *src, /* Pathname of file or dir to be renamed + const char *src, /* Pathname of file or dir to be renamed * (native). */ - CONST char *dst) /* New pathname of file or directory + const char *dst) /* New pathname of file or directory * (native). */ { if (rename(src, dst) == 0) { /* INTL: Native. */ @@ -405,7 +408,7 @@ TclpObjCopyFile( Tcl_Obj *srcPathPtr, Tcl_Obj *destPathPtr) { - CONST char *src = Tcl_FSGetNativePath(srcPathPtr); + const char *src = Tcl_FSGetNativePath(srcPathPtr); Tcl_StatBuf srcStatBuf; if (TclOSlstat(src, &srcStatBuf) != 0) { /* INTL: Native. */ @@ -417,9 +420,9 @@ TclpObjCopyFile( static int DoCopyFile( - CONST char *src, /* Pathname of file to be copied (native). */ - CONST char *dst, /* Pathname of file to copy to (native). */ - CONST Tcl_StatBuf *statBufPtr) + const char *src, /* Pathname of file to be copied (native). */ + const char *dst, /* Pathname of file to copy to (native). */ + const Tcl_StatBuf *statBufPtr) /* Used to determine filetype. */ { Tcl_StatBuf dstStatBuf; @@ -449,15 +452,16 @@ DoCopyFile( switch ((int) (statBufPtr->st_mode & S_IFMT)) { #ifndef DJGPP case S_IFLNK: { - char link[MAXPATHLEN]; + char linkBuf[MAXPATHLEN]; int length; - length = readlink(src, link, sizeof(link)); /* INTL: Native. */ + length = readlink(src, linkBuf, sizeof(linkBuf)); + /* INTL: Native. */ if (length == -1) { return TCL_ERROR; } - link[length] = '\0'; - if (symlink(link, dst) < 0) { /* INTL: Native. */ + linkBuf[length] = '\0'; + if (symlink(linkBuf, dst) < 0) { /* INTL: Native. */ return TCL_ERROR; } #ifdef MAC_OSX_TCL @@ -465,7 +469,7 @@ DoCopyFile( #endif break; } -#endif +#endif /* !DJGPP */ case S_IFBLK: case S_IFCHR: if (mknod(dst, statBufPtr->st_mode, /* INTL: Native. */ @@ -503,10 +507,10 @@ DoCopyFile( int TclUnixCopyFile( - CONST char *src, /* Pathname of file to copy (native). */ - CONST char *dst, /* Pathname of file to create/overwrite + const char *src, /* Pathname of file to copy (native). */ + const char *dst, /* Pathname of file to create/overwrite * (native). */ - CONST Tcl_StatBuf *statBufPtr, + const Tcl_StatBuf *statBufPtr, /* Used to determine mode and blocksize. */ int dontCopyAtts) /* If flag set, don't copy attributes. */ { @@ -519,7 +523,9 @@ TclUnixCopyFile( #define BINMODE |O_BINARY #else #define BINMODE -#endif +#endif /* DJGPP */ + +#define DEFAULT_COPY_BLOCK_SIZE 4069 if ((srcFd = TclOSopen(src, O_RDONLY BINMODE, 0)) < 0) { /* INTL: Native */ return TCL_ERROR; @@ -547,11 +553,11 @@ TclUnixCopyFile( if (fstatfs(srcFd, &fs) == 0) { blockSize = fs.f_bsize; } else { - blockSize = 4096; + blockSize = DEFAULT_COPY_BLOCK_SIZE; } } #else - blockSize = 4096; + blockSize = DEFAULT_COPY_BLOCK_SIZE; #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */ /* @@ -563,7 +569,7 @@ TclUnixCopyFile( */ if (blockSize <= 0) { - blockSize = 4096; + blockSize = DEFAULT_COPY_BLOCK_SIZE; } buffer = ckalloc(blockSize); while (1) { @@ -626,9 +632,9 @@ TclpObjDeleteFile( int TclpDeleteFile( - CONST char *path) /* Pathname of file to be removed (native). */ + const void *path) /* Pathname of file to be removed (native). */ { - if (unlink(path) != 0) { /* INTL: Native. */ + if (unlink((const char *)path) != 0) { return TCL_ERROR; } return TCL_OK; @@ -669,7 +675,7 @@ TclpObjCreateDirectory( static int DoCreateDirectory( - CONST char *path) /* Pathname of directory to create (native). */ + const char *path) /* Pathname of directory to create (native). */ { mode_t mode; @@ -816,7 +822,7 @@ DoRemoveDirectory( * filled with UTF-8 name of file causing * error. */ { - CONST char *path; + const char *path; mode_t oldPerm = 0; int result; @@ -914,7 +920,7 @@ TraverseUnixTree( * files. */ { Tcl_StatBuf statBuf; - CONST char *source, *errfile; + const char *source, *errfile; int result, sourceLen; int targetLen; #ifndef HAVE_FTS @@ -922,7 +928,7 @@ TraverseUnixTree( Tcl_DirEntry *dirEntPtr; DIR *dirPtr; #else - CONST char *paths[2] = {NULL, NULL}; + const char *paths[2] = {NULL, NULL}; FTS *fts = NULL; FTSENT *ent; #endif @@ -941,7 +947,7 @@ TraverseUnixTree( * Process the regular file */ - return (*traverseProc)(sourcePtr, targetPtr, &statBuf, DOTREE_F, + return traverseProc(sourcePtr, targetPtr, &statBuf, DOTREE_F, errorPtr); } #ifndef HAVE_FTS @@ -954,7 +960,7 @@ TraverseUnixTree( errfile = source; goto end; } - result = (*traverseProc)(sourcePtr, targetPtr, &statBuf, DOTREE_PRED, + result = traverseProc(sourcePtr, targetPtr, &statBuf, DOTREE_PRED, errorPtr); if (result != TCL_OK) { closedir(dirPtr); @@ -1028,12 +1034,12 @@ TraverseUnixTree( * that directory. */ - result = (*traverseProc)(sourcePtr, targetPtr, &statBuf, DOTREE_POSTD, + result = traverseProc(sourcePtr, targetPtr, &statBuf, DOTREE_POSTD, errorPtr); } #else /* HAVE_FTS */ paths[0] = source; - fts = fts_open((char**)paths, FTS_PHYSICAL | FTS_NOCHDIR | + fts = fts_open((char **) paths, FTS_PHYSICAL | FTS_NOCHDIR | (noFtsStat || doRewind ? FTS_NOSTAT : 0), NULL); if (fts == NULL) { errfile = source; @@ -1051,7 +1057,7 @@ TraverseUnixTree( unsigned short pathlen = ent->fts_pathlen - sourceLen; int type; Tcl_StatBuf *statBufPtr = NULL; - + if (info == FTS_DNR || info == FTS_ERR || info == FTS_NS) { errfile = ent->fts_path; break; @@ -1082,7 +1088,7 @@ TraverseUnixTree( statBufPtr = (Tcl_StatBuf *) ent->fts_statp; } } - result = (*traverseProc)(sourcePtr, targetPtr, statBufPtr, type, + result = traverseProc(sourcePtr, targetPtr, statBufPtr, type, errorPtr); if (result != TCL_OK) { break; @@ -1092,7 +1098,7 @@ TraverseUnixTree( Tcl_DStringSetLength(targetPtr, targetLen); } } -#endif /* HAVE_FTS */ +#endif /* !HAVE_FTS */ end: if (errfile != NULL) { @@ -1132,7 +1138,7 @@ static int TraversalCopy( Tcl_DString *srcPtr, /* Source pathname to copy (native). */ Tcl_DString *dstPtr, /* Destination pathname of copy (native). */ - CONST Tcl_StatBuf *statBufPtr, + const Tcl_StatBuf *statBufPtr, /* Stat info for file specified by srcPtr. */ int type, /* Reason for call - see TraverseUnixTree(). */ Tcl_DString *errorPtr) /* If non-NULL, uninitialized or free DString @@ -1196,7 +1202,7 @@ static int TraversalDelete( Tcl_DString *srcPtr, /* Source pathname (native). */ Tcl_DString *ignore, /* Destination pathname (not used). */ - CONST Tcl_StatBuf *statBufPtr, + const Tcl_StatBuf *statBufPtr, /* Stat info for file specified by srcPtr. */ int type, /* Reason for call - see TraverseUnixTree(). */ Tcl_DString *errorPtr) /* If non-NULL, uninitialized or free DString @@ -1244,9 +1250,9 @@ TraversalDelete( static int CopyFileAtts( - CONST char *src, /* Path name of source file (native). */ - CONST char *dst, /* Path name of target file (native). */ - CONST Tcl_StatBuf *statBufPtr) + const char *src, /* Path name of source file (native). */ + const char *dst, /* Path name of target file (native). */ + const Tcl_StatBuf *statBufPtr) /* Stat info for source file */ { struct utimbuf tval; @@ -1327,7 +1333,7 @@ GetGroupAttribute( *attributePtrPtr = Tcl_NewIntObj((int) statBuf.st_gid); } else { Tcl_DString ds; - CONST char *utf; + const char *utf; utf = Tcl_ExternalToUtfDString(NULL, groupPtr->gr_name, -1, &ds); *attributePtrPtr = Tcl_NewStringObj(utf, -1); @@ -1381,7 +1387,7 @@ GetOwnerAttribute( *attributePtrPtr = Tcl_NewIntObj((int) statBuf.st_uid); } else { Tcl_DString ds; - CONST char *utf; + const char *utf; utf = Tcl_ExternalToUtfDString(NULL, pwPtr->pw_name, -1, &ds); *attributePtrPtr = Tcl_NewStringObj(utf, Tcl_DStringLength(&ds)); @@ -1458,12 +1464,12 @@ SetGroupAttribute( { long gid; int result; - CONST char *native; + const char *native; if (Tcl_GetLongFromObj(NULL, attributePtr, &gid) != TCL_OK) { Tcl_DString ds; struct group *groupPtr = NULL; - CONST char *string; + const char *string; int length; string = Tcl_GetStringFromObj(attributePtr, &length); @@ -1477,6 +1483,8 @@ SetGroupAttribute( Tcl_AppendResult(interp, "could not set group for file \"", TclGetString(fileName), "\": group \"", string, "\" does not exist", NULL); + Tcl_SetErrorCode(interp, "TCL", "OPERATION", "SETGRP", + "NO_GROUP", NULL); } return TCL_ERROR; } @@ -1522,12 +1530,12 @@ SetOwnerAttribute( { long uid; int result; - CONST char *native; + const char *native; if (Tcl_GetLongFromObj(NULL, attributePtr, &uid) != TCL_OK) { Tcl_DString ds; struct passwd *pwPtr = NULL; - CONST char *string; + const char *string; int length; string = Tcl_GetStringFromObj(attributePtr, &length); @@ -1541,6 +1549,8 @@ SetOwnerAttribute( Tcl_AppendResult(interp, "could not set owner for file \"", TclGetString(fileName), "\": user \"", string, "\" does not exist", NULL); + Tcl_SetErrorCode(interp, "TCL", "OPERATION", "SETOWN", + "NO_USER", NULL); } return TCL_ERROR; } @@ -1587,8 +1597,8 @@ SetPermissionsAttribute( long mode; mode_t newMode; int result = TCL_ERROR; - CONST char *native; - char *modeStringPtr = TclGetString(attributePtr); + const char *native; + const char *modeStringPtr = TclGetString(attributePtr); int scanned = TclParseAllWhiteSpace(modeStringPtr, -1); /* @@ -1634,6 +1644,7 @@ SetPermissionsAttribute( if (interp != NULL) { Tcl_AppendResult(interp, "unknown permission string format \"", modeStringPtr, "\"", NULL); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "PERMISSION", NULL); } return TCL_ERROR; } @@ -1672,7 +1683,8 @@ SetPermissionsAttribute( Tcl_Obj * TclpObjListVolumes(void) { - Tcl_Obj *resultPtr = Tcl_NewStringObj("/", 1); + Tcl_Obj *resultPtr; + TclNewLiteralStringObj(resultPtr, "/"); Tcl_IncrRefCount(resultPtr); return resultPtr; @@ -1700,7 +1712,7 @@ TclpObjListVolumes(void) static int GetModeFromPermString( Tcl_Interp *interp, /* The interp we are using for errors. */ - char *modeStringPtr, /* Permissions string */ + const char *modeStringPtr, /* Permissions string */ mode_t *modePtr) /* pointer to the mode value */ { mode_t newMode; @@ -1893,14 +1905,14 @@ TclpObjNormalizePath( Tcl_Obj *pathPtr, int nextCheckpoint) { - char *currentPathEndPosition; + const char *currentPathEndPosition; int pathLen; char cur; - char *path = Tcl_GetStringFromObj(pathPtr, &pathLen); + const char *path = Tcl_GetStringFromObj(pathPtr, &pathLen); + Tcl_DString ds; + const char *nativePath; #ifndef NO_REALPATH char normPath[MAXPATHLEN]; - Tcl_DString ds; - CONST char *nativePath; #endif /* @@ -1952,8 +1964,6 @@ TclpObjNormalizePath( * Reached directory separator. */ - Tcl_DString ds; - CONST char *nativePath; int accessOk; nativePath = Tcl_UtfToExternalDString(NULL, path, @@ -2004,7 +2014,7 @@ TclpObjNormalizePath( return 0; } - nativePath = Tcl_UtfToExternalDString(NULL, path, nextCheckpoint, &ds); + nativePath = Tcl_UtfToExternalDString(NULL, path,nextCheckpoint, &ds); if (Realpath(nativePath, normPath) != NULL) { int newNormLen; @@ -2079,6 +2089,126 @@ TclpObjNormalizePath( return nextCheckpoint; } +/* + *---------------------------------------------------------------------- + * + * TclpOpenTemporaryFile -- + * + * Creates a temporary file, possibly based on the supplied bits and + * pieces of template supplied in the first three arguments. If the + * fourth argument is non-NULL, it contains a Tcl_Obj to store the name + * of the temporary file in (and it is caller's responsibility to clean + * up). If the fourth argument is NULL, try to arrange for the temporary + * file to go away once it is no longer needed. + * + * Results: + * A read-write Tcl Channel open on the file. + * + *---------------------------------------------------------------------- + */ + +Tcl_Channel +TclpOpenTemporaryFile( + Tcl_Obj *dirObj, + Tcl_Obj *basenameObj, + Tcl_Obj *extensionObj, + Tcl_Obj *resultingNameObj) +{ + Tcl_Channel chan; + Tcl_DString template, tmp; + const char *string; + int len, fd; + + if (dirObj) { + string = Tcl_GetStringFromObj(dirObj, &len); + Tcl_UtfToExternalDString(NULL, string, len, &template); + } else { + Tcl_DStringInit(&template); + Tcl_DStringAppend(&template, DefaultTempDir(), -1); /* INTL: native */ + } + + Tcl_DStringAppend(&template, "/", -1); + + if (basenameObj) { + string = Tcl_GetStringFromObj(basenameObj, &len); + Tcl_UtfToExternalDString(NULL, string, len, &tmp); + Tcl_DStringAppend(&template, Tcl_DStringValue(&tmp), -1); + Tcl_DStringFree(&tmp); + } else { + Tcl_DStringAppend(&template, "tcl", -1); + } + + Tcl_DStringAppend(&template, "_XXXXXX", -1); + +#ifdef HAVE_MKSTEMPS + if (extensionObj) { + string = Tcl_GetStringFromObj(extensionObj, &len); + Tcl_UtfToExternalDString(NULL, string, len, &tmp); + Tcl_DStringAppend(&template, Tcl_DStringValue(&tmp), -1); + fd = mkstemps(Tcl_DStringValue(&template), Tcl_DStringLength(&tmp)); + Tcl_DStringFree(&tmp); + } else +#endif + { + fd = mkstemp(Tcl_DStringValue(&template)); + } + + if (fd == -1) { + return NULL; + } + chan = Tcl_MakeFileChannel(INT2PTR(fd), TCL_READABLE|TCL_WRITABLE); + if (resultingNameObj) { + Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&template), + Tcl_DStringLength(&template), &tmp); + Tcl_SetStringObj(resultingNameObj, Tcl_DStringValue(&tmp), + Tcl_DStringLength(&tmp)); + Tcl_DStringFree(&tmp); + } else { + /* + * Try to delete the file immediately since we're not reporting the + * name to anyone. Note that we're *not* handling any errors from + * this! + */ + + unlink(Tcl_DStringValue(&template)); + errno = 0; + } + Tcl_DStringFree(&template); + + return chan; +} + +/* + * Helper that does *part* of what tempnam() does. + */ + +static const char * +DefaultTempDir(void) +{ + const char *dir; + struct stat buf; + + dir = getenv("TMPDIR"); + if (dir && dir[0] && stat(dir, &buf) == 0 && S_ISDIR(buf.st_mode) + && access(dir, W_OK)) { + return dir; + } + +#ifdef P_tmpdir + dir = P_tmpdir; + if (stat(dir, &buf) == 0 && S_ISDIR(buf.st_mode) && access(dir, W_OK)) { + return dir; + } +#endif + + /* + * Assume that "/tmp" is always an existing writable directory; we've no + * recovery mechanism if it isn't. + */ + + return "/tmp"; +} + #if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) /* *---------------------------------------------------------------------- @@ -2147,9 +2277,8 @@ SetReadOnlyAttribute( Tcl_Obj *attributePtr) /* The attribute to set. */ { Tcl_StatBuf statBuf; - int result; - int readonly; - CONST char *native; + int result, readonly; + const char *native; if (Tcl_GetBooleanFromObj(interp, attributePtr, &readonly) != TCL_OK) { return TCL_ERROR; diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 2639d59..c8afeb2 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -6,15 +6,15 @@ * * Copyright (c) 1995-1998 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #include "tclFileSystem.h" -static int NativeMatchType(Tcl_Interp *interp, CONST char* nativeEntry, - CONST char* nativeName, Tcl_GlobTypeData *types); +static int NativeMatchType(Tcl_Interp *interp, const char* nativeEntry, + const char* nativeName, Tcl_GlobTypeData *types); /* *--------------------------------------------------------------------------- @@ -35,10 +35,10 @@ static int NativeMatchType(Tcl_Interp *interp, CONST char* nativeEntry, void TclpFindExecutable( - CONST char *argv0) /* The value of the application's argv[0] + const char *argv0) /* The value of the application's argv[0] * (native). */ { - CONST char *name, *p; + const char *name, *p; Tcl_StatBuf statBuf; Tcl_DString buffer, nameString, cwd, utfName; Tcl_Encoding encoding; @@ -200,12 +200,12 @@ TclpMatchInDirectory( Tcl_Interp *interp, /* Interpreter to receive errors. */ Tcl_Obj *resultPtr, /* List object to lappend results. */ Tcl_Obj *pathPtr, /* Contains path to directory to search. */ - CONST char *pattern, /* Pattern to match against. */ + const char *pattern, /* Pattern to match against. */ Tcl_GlobTypeData *types) /* Object containing list of acceptable types. * May be NULL. In particular the directory * flag is very important. */ { - CONST char *native; + const char *native; Tcl_Obj *fileNamePtr; int matchResult = 0; @@ -226,12 +226,13 @@ TclpMatchInDirectory( /* * Match a file directly. */ + Tcl_Obj *tailPtr; - CONST char *nativeTail; + const char *nativeTail; - native = (CONST char*) Tcl_FSGetNativePath(pathPtr); + native = Tcl_FSGetNativePath(pathPtr); tailPtr = TclPathPart(interp, pathPtr, TCL_PATH_TAIL); - nativeTail = (CONST char*) Tcl_FSGetNativePath(tailPtr); + nativeTail = Tcl_FSGetNativePath(tailPtr); matchResult = NativeMatchType(interp, native, nativeTail, types); if (matchResult == 1) { Tcl_ListObjAppendElement(interp, resultPtr, pathPtr); @@ -241,10 +242,9 @@ TclpMatchInDirectory( } else { DIR *d; Tcl_DirEntry *entryPtr; - CONST char *dirName; - int dirLength; + const char *dirName; + int dirLength, nativeDirLen; int matchHidden, matchHiddenPat; - int nativeDirLen; Tcl_StatBuf statBuf; Tcl_DString ds; /* native encoding of dir */ Tcl_DString dsOrig; /* utf-8 encoding of dir */ @@ -255,7 +255,7 @@ TclpMatchInDirectory( /* * Make sure that the directory part of the name really is a - * directory. If the directory name is "", use the name "." instead, + * directory. If the directory name is "", use the name "." instead, * because some UNIX systems don't treat "" like "." automatically. * Keep the "" for use in generating file names, otherwise "glob * foo.c" would return "./foo.c". @@ -297,7 +297,7 @@ TclpMatchInDirectory( Tcl_ResetResult(interp); Tcl_AppendResult(interp, "couldn't read directory \"", Tcl_DStringValue(&dsOrig), "\": ", - Tcl_PosixError(interp), (char *) NULL); + Tcl_PosixError(interp), NULL); } Tcl_DStringFree(&dsOrig); Tcl_DecrRefCount(fileNamePtr); @@ -312,11 +312,11 @@ TclpMatchInDirectory( matchHiddenPat = (pattern[0] == '.') || ((pattern[0] == '\\') && (pattern[1] == '.')); - matchHidden = matchHiddenPat + matchHidden = matchHiddenPat || (types && (types->perm & TCL_GLOB_PERM_HIDDEN)); while ((entryPtr = TclOSreaddir(d)) != NULL) { /* INTL: Native. */ Tcl_DString utfDs; - CONST char *utfname; + const char *utfname; /* * Skip this file if it doesn't agree with the hidden parameters @@ -324,13 +324,19 @@ TclpMatchInDirectory( */ if (*entryPtr->d_name == '.') { - if (!matchHidden) continue; + if (!matchHidden) { + continue; + } } else { #ifdef MAC_OSX_TCL - if (matchHiddenPat) continue; + if (matchHiddenPat) { + continue; + } /* Also need to check HFS hidden flag in TclMacOSXMatchType. */ #else - if (matchHidden) continue; + if (matchHidden) { + continue; + } #endif } @@ -370,9 +376,8 @@ TclpMatchInDirectory( } if (matchResult < 0) { return TCL_ERROR; - } else { - return TCL_OK; } + return TCL_OK; } /* @@ -380,13 +385,13 @@ TclpMatchInDirectory( * * NativeMatchType -- * - * This routine is used by the globbing code to check if a file - * matches a given type description. + * This routine is used by the globbing code to check if a file matches a + * given type description. * * Results: - * The return value is 1, 0 or -1 indicating whether the file - * matches the given criteria, does not match them, or an error - * occurred (in wich case an error is left in interp). + * The return value is 1, 0 or -1 indicating whether the file matches the + * given criteria, does not match them, or an error occurred (in which + * case an error is left in interp). * * Side effects: * None. @@ -397,11 +402,12 @@ TclpMatchInDirectory( static int NativeMatchType( Tcl_Interp *interp, /* Interpreter to receive errors. */ - CONST char *nativeEntry, /* Native path to check. */ - CONST char *nativeName, /* Native filename to check. */ + const char *nativeEntry, /* Native path to check. */ + const char *nativeName, /* Native filename to check. */ Tcl_GlobTypeData *types) /* Type description to match against. */ { Tcl_StatBuf buf; + if (types == NULL) { /* * Simply check for the file's existence, but do it with lstat, in @@ -412,124 +418,130 @@ NativeMatchType( if (TclOSlstat(nativeEntry, &buf) != 0) { return 0; } - } else { - if (types->perm != 0) { - if (TclOSstat(nativeEntry, &buf) != 0) { - /* - * Either the file has disappeared between the 'readdir' call - * and the 'stat' call, or the file is a link to a file which - * doesn't exist (which we could ascertain with lstat), or - * there is some other strange problem. In all these cases, we - * define this to mean the file does not match any defined - * permission, and therefore it is not added to the list of - * files to return. - */ - - return 0; - } + return 1; + } + if (types->perm != 0) { + if (TclOSstat(nativeEntry, &buf) != 0) { /* - * readonly means that there are NO write permissions (even for - * user), but execute is OK for anybody OR that the user immutable - * flag is set (where supported). + * Either the file has disappeared between the 'readdir' call and + * the 'stat' call, or the file is a link to a file which doesn't + * exist (which we could ascertain with lstat), or there is some + * other strange problem. In all these cases, we define this to + * mean the file does not match any defined permission, and + * therefore it is not added to the list of files to return. */ - if (((types->perm & TCL_GLOB_PERM_RONLY) && + return 0; + } + + /* + * readonly means that there are NO write permissions (even for user), + * but execute is OK for anybody OR that the user immutable flag is + * set (where supported). + */ + + if (((types->perm & TCL_GLOB_PERM_RONLY) && #if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) - !(buf.st_flags & UF_IMMUTABLE) && + !(buf.st_flags & UF_IMMUTABLE) && #endif - (buf.st_mode & (S_IWOTH|S_IWGRP|S_IWUSR))) || - ((types->perm & TCL_GLOB_PERM_R) && - (access(nativeEntry, R_OK) != 0)) || - ((types->perm & TCL_GLOB_PERM_W) && - (access(nativeEntry, W_OK) != 0)) || - ((types->perm & TCL_GLOB_PERM_X) && - (access(nativeEntry, X_OK) != 0)) + (buf.st_mode & (S_IWOTH|S_IWGRP|S_IWUSR))) || + ((types->perm & TCL_GLOB_PERM_R) && + (access(nativeEntry, R_OK) != 0)) || + ((types->perm & TCL_GLOB_PERM_W) && + (access(nativeEntry, W_OK) != 0)) || + ((types->perm & TCL_GLOB_PERM_X) && + (access(nativeEntry, X_OK) != 0)) #ifndef MAC_OSX_TCL - || ((types->perm & TCL_GLOB_PERM_HIDDEN) && - (*nativeName != '.')) + || ((types->perm & TCL_GLOB_PERM_HIDDEN) && + (*nativeName != '.')) #endif ) { - return 0; - } + return 0; } - if (types->type != 0) { - if (types->perm == 0) { + } + if (types->type != 0) { + if (types->perm == 0) { + /* + * We haven't yet done a stat on the file. + */ + + if (TclOSstat(nativeEntry, &buf) != 0) { /* - * We haven't yet done a stat on the file. + * Posix error occurred. The only ok case is if this is a link + * to a nonexistent file, and the user did 'glob -l'. So we + * check that here: */ - if (TclOSstat(nativeEntry, &buf) != 0) { - /* - * Posix error occurred. The only ok case is if this is a - * link to a nonexistent file, and the user did 'glob -l'. - * So we check that here: - */ - - if (types->type & TCL_GLOB_TYPE_LINK) { - if (TclOSlstat(nativeEntry, &buf) == 0) { - if (S_ISLNK(buf.st_mode)) { - return 1; - } + if (types->type & TCL_GLOB_TYPE_LINK) { + if (TclOSlstat(nativeEntry, &buf) == 0) { + if (S_ISLNK(buf.st_mode)) { + return 1; } } - return 0; } + return 0; } + } - /* - * In order bcdpfls as in 'find -t' - */ + /* + * In order bcdpsfl as in 'find -t' + */ - if (((types->type & TCL_GLOB_TYPE_BLOCK)&& S_ISBLK(buf.st_mode)) || + if ( ((types->type & TCL_GLOB_TYPE_BLOCK)&& S_ISBLK(buf.st_mode)) || ((types->type & TCL_GLOB_TYPE_CHAR) && S_ISCHR(buf.st_mode)) || ((types->type & TCL_GLOB_TYPE_DIR) && S_ISDIR(buf.st_mode)) || ((types->type & TCL_GLOB_TYPE_PIPE) && S_ISFIFO(buf.st_mode))|| - ((types->type & TCL_GLOB_TYPE_FILE) && S_ISREG(buf.st_mode)) #ifdef S_ISSOCK - ||((types->type & TCL_GLOB_TYPE_SOCK) && S_ISSOCK(buf.st_mode)) + ((types->type & TCL_GLOB_TYPE_SOCK) && S_ISSOCK(buf.st_mode))|| #endif /* S_ISSOCK */ - ) { - /* - * Do nothing - this file is ok. - */ - } else { + ((types->type & TCL_GLOB_TYPE_FILE) && S_ISREG(buf.st_mode))) { + /* + * Do nothing - this file is ok. + */ + } else { #ifdef S_ISLNK - if (types->type & TCL_GLOB_TYPE_LINK) { - if (TclOSlstat(nativeEntry, &buf) == 0) { - if (S_ISLNK(buf.st_mode)) { - goto filetypeOK; - } + if (types->type & TCL_GLOB_TYPE_LINK) { + if (TclOSlstat(nativeEntry, &buf) == 0) { + if (S_ISLNK(buf.st_mode)) { + goto filetypeOK; } } -#endif /* S_ISLNK */ - return 0; } +#endif /* S_ISLNK */ + return 0; } - filetypeOK: ; + } + filetypeOK: + + /* + * If we're on OSX, we also have to worry about matching the file creator + * code (if specified). Do that now. + */ + #ifdef MAC_OSX_TCL - if (types->macType != NULL || types->macCreator != NULL || - (types->perm & TCL_GLOB_PERM_HIDDEN)) { - int matchResult; + if (types->macType != NULL || types->macCreator != NULL || + (types->perm & TCL_GLOB_PERM_HIDDEN)) { + int matchResult; - if (types->perm == 0 && types->type == 0) { - /* - * We haven't yet done a stat on the file. - */ + if (types->perm == 0 && types->type == 0) { + /* + * We haven't yet done a stat on the file. + */ - if (TclOSstat(nativeEntry, &buf) != 0) { - return 0; - } + if (TclOSstat(nativeEntry, &buf) != 0) { + return 0; } + } - matchResult = TclMacOSXMatchType(interp, nativeEntry, nativeName, - &buf, types); - if (matchResult != 1) { - return matchResult; - } + matchResult = TclMacOSXMatchType(interp, nativeEntry, nativeName, + &buf, types); + if (matchResult != 1) { + return matchResult; } -#endif } +#endif /* MAC_OSX_TCL */ + return 1; } @@ -554,17 +566,16 @@ NativeMatchType( *---------------------------------------------------------------------- */ -char * +const char * TclpGetUserHome( - CONST char *name, /* User name for desired home directory. */ + const char *name, /* User name for desired home directory. */ Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with * name of user's home directory. */ { struct passwd *pwPtr; Tcl_DString ds; - CONST char *native; + const char *native = Tcl_UtfToExternalDString(NULL, name, -1, &ds); - native = Tcl_UtfToExternalDString(NULL, name, -1, &ds); pwPtr = TclpGetPwNam(native); /* INTL: Native. */ Tcl_DStringFree(&ds); @@ -596,12 +607,12 @@ TclpObjAccess( Tcl_Obj *pathPtr, /* Path of file to access */ int mode) /* Permission setting. */ { - CONST char *path = Tcl_FSGetNativePath(pathPtr); + const char *path = Tcl_FSGetNativePath(pathPtr); + if (path == NULL) { return -1; - } else { - return access(path, mode); } + return access(path, mode); } /* @@ -624,12 +635,12 @@ int TclpObjChdir( Tcl_Obj *pathPtr) /* Path to new working directory */ { - CONST char *path = Tcl_FSGetNativePath(pathPtr); + const char *path = Tcl_FSGetNativePath(pathPtr); + if (path == NULL) { return -1; - } else { - return chdir(path); } + return chdir(path); } /* @@ -684,24 +695,27 @@ TclpGetNativeCwd( char buffer[MAXPATHLEN+1]; #ifdef USEGETWD - if (getwd(buffer) == NULL) /* INTL: Native. */ + if (getwd(buffer) == NULL) { /* INTL: Native. */ + return NULL; + } #else - if (getcwd(buffer, MAXPATHLEN+1) == NULL) /* INTL: Native. */ -#endif - { + if (getcwd(buffer, MAXPATHLEN+1) == NULL) { /* INTL: Native. */ return NULL; } - if ((clientData != NULL) && strcmp(buffer, (CONST char*)clientData) == 0) { - /* - * No change to pwd. - */ +#endif + + if ((clientData == NULL) || strcmp(buffer, (const char*)clientData)) { + char *newCd = ckalloc(strlen(buffer) + 1); - return clientData; - } else { - char *newCd = (char *) ckalloc((unsigned) (strlen(buffer) + 1)); strcpy(newCd, buffer); - return (ClientData) newCd; + return newCd; } + + /* + * No change to pwd. + */ + + return clientData; } /* @@ -726,7 +740,7 @@ TclpGetNativeCwd( *---------------------------------------------------------------------- */ -CONST char * +const char * TclpGetCwd( Tcl_Interp *interp, /* If non-NULL, used for error reporting. */ Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with @@ -772,14 +786,14 @@ TclpGetCwd( char * TclpReadlink( - CONST char *path, /* Path of file to readlink (UTF-8). */ + const char *path, /* Path of file to readlink (UTF-8). */ Tcl_DString *linkPtr) /* Uninitialized or free DString filled with * contents of link (UTF-8). */ { #ifndef DJGPP char link[MAXPATHLEN]; int length; - CONST char *native; + const char *native; Tcl_DString ds; native = Tcl_UtfToExternalDString(NULL, path, -1, &ds); @@ -818,12 +832,12 @@ TclpObjStat( Tcl_Obj *pathPtr, /* Path of file to stat */ Tcl_StatBuf *bufPtr) /* Filled with results of stat call. */ { - CONST char *path = Tcl_FSGetNativePath(pathPtr); + const char *path = Tcl_FSGetNativePath(pathPtr); + if (path == NULL) { return -1; - } else { - return TclOSstat(path, bufPtr); } + return TclOSstat(path, bufPtr); } #ifdef S_IFLNK @@ -835,8 +849,8 @@ TclpObjLink( int linkAction) { if (toPtr != NULL) { - CONST char *src = Tcl_FSGetNativePath(pathPtr); - CONST char *target = NULL; + const char *src = Tcl_FSGetNativePath(pathPtr); + const char *target = NULL; if (src == NULL) { return NULL; @@ -1030,8 +1044,8 @@ TclpNativeToNormalized( Tcl_Obj *objPtr; int len; - CONST char *copy; - Tcl_ExternalToUtfDString(NULL, (CONST char*)clientData, -1, &ds); + const char *copy; + Tcl_ExternalToUtfDString(NULL, (const char*)clientData, -1, &ds); copy = Tcl_DStringValue(&ds); len = Tcl_DStringLength(&ds); @@ -1063,10 +1077,10 @@ TclNativeCreateNativeRep( Tcl_Obj *pathPtr) { char *nativePathPtr; + const char *str; Tcl_DString ds; Tcl_Obj *validPathPtr; int len; - char *str; if (TclFSCwdIsNative()) { /* @@ -1095,11 +1109,11 @@ TclNativeCreateNativeRep( Tcl_UtfToExternalDString(NULL, str, len, &ds); len = Tcl_DStringLength(&ds) + sizeof(char); Tcl_DecrRefCount(validPathPtr); - nativePathPtr = ckalloc((unsigned) len); - memcpy((void*)nativePathPtr, (void*)Tcl_DStringValue(&ds), (size_t) len); + nativePathPtr = ckalloc(len); + memcpy(nativePathPtr, Tcl_DStringValue(&ds), (size_t) len); Tcl_DStringFree(&ds); - return (ClientData)nativePathPtr; + return nativePathPtr; } /* @@ -1134,11 +1148,11 @@ TclNativeDupInternalRep( * ASCII representation when running on Unix. */ - len = sizeof(char) + (strlen((CONST char*) clientData) * sizeof(char)); + len = (strlen((const char*) clientData) + 1) * sizeof(char); - copy = (char *) ckalloc(len); - memcpy((void *) copy, (void *) clientData, len); - return (ClientData)copy; + copy = ckalloc(len); + memcpy(copy, clientData, len); + return copy; } /* diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index 5111746..8f872d5 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -16,7 +16,7 @@ # ifdef __APPLE__ # if defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1030 /* Support for weakly importing nl_langinfo on Darwin. */ -# define WEAK_IMPORT_NL_LANGINFO +# define WEAK_IMPORT_NL_LANGINFO extern char *nl_langinfo(nl_item) WEAK_IMPORT_ATTRIBUTE; # endif # endif @@ -36,64 +36,6 @@ #endif /* - * Define TCL_NO_STACK_CHECK in the compiler options if you want to revert to - * the old behavior of never checking the stack. - */ - -/* - * Define this if you want to see a lot of output regarding stack checking. - */ - -#undef TCL_DEBUG_STACK_CHECK - -/* - * Values used to compute how much space is really available for Tcl's use for - * the stack. - * - * The getrlimit() function is documented to return the maximum stack size in - * bytes. However, with threads enabled, the pthread library on some platforms - * does bad things to the stack size limits. First, the limits cannot be - * changed. Second, they appear to be sometimes reported incorrectly. - * - * The defines below may need to be adjusted if more platforms have this - * broken behavior with threads enabled. - */ - -#ifndef TCL_MAGIC_STACK_DIVISOR -#define TCL_MAGIC_STACK_DIVISOR 1 -#endif -#ifndef TCL_RESERVED_STACK_PAGES -#define TCL_RESERVED_STACK_PAGES 8 -#endif - -/* - * Thread specific data for stack checking. - */ - -#ifndef TCL_NO_STACK_CHECK -typedef struct ThreadSpecificData { - int *outerVarPtr; /* The "outermost" stack frame pointer for - * this thread. */ - int *stackBound; /* The current stack boundary */ -} ThreadSpecificData; -static Tcl_ThreadDataKey dataKey; -#ifdef TCL_CROSS_COMPILE -static int stackGrowsDown = -1; -static int StackGrowsDown(int *parent); -#elif defined(TCL_STACK_GROWS_UP) -#define stackGrowsDown 0 -#else -#define stackGrowsDown 1 -#endif -#endif /* TCL_NO_STACK_CHECK */ - -#ifdef TCL_DEBUG_STACK_CHECK -#define STACK_DEBUG(args) printf args -#else -#define STACK_DEBUG(args) (void)0 -#endif /* TCL_DEBUG_STACK_CHECK */ - -/* * Tcl tries to use standard and homebrew methods to guess the right encoding * on the platform. However, there is always a final fallback, and this value * is it. Make sure it is a real Tcl encoding. @@ -126,8 +68,8 @@ static char pkgPath[sizeof(TCL_PACKAGE_PATH)+200] = TCL_PACKAGE_PATH; */ typedef struct LocaleTable { - CONST char *lang; - CONST char *encoding; + const char *lang; + const char *encoding; } LocaleTable; /* @@ -140,7 +82,7 @@ typedef struct LocaleTable { * among existing platforms. */ -static CONST LocaleTable localeTable[] = { +static const LocaleTable localeTable[] = { {"", "iso8859-1"}, {"ansi-1251", "cp1251"}, {"ansi_x3.4-1968", "iso8859-1"}, @@ -325,9 +267,6 @@ static CONST LocaleTable localeTable[] = { {"zh_tw.big5", "big5"}, }; -#ifndef TCL_NO_STACK_CHECK -static int GetStackSize(size_t *stackSizePtr); -#endif /* TCL_NO_STACK_CHECK */ #ifdef HAVE_COREFOUNDATION static int MacOSXGetLibraryPath(Tcl_Interp *interp, int maxPathLen, char *tclLibPath); @@ -479,7 +418,7 @@ TclpInitLibraryPath( { #define LIBRARY_SIZE 32 Tcl_Obj *pathPtr, *objPtr; - CONST char *str; + const char *str; Tcl_DString buffer; pathPtr = Tcl_NewObj(); @@ -498,7 +437,7 @@ TclpInitLibraryPath( if ((str != NULL) && (str[0] != '\0')) { Tcl_DString ds; int pathc; - CONST char **pathv; + const char **pathv; char installLib[LIBRARY_SIZE]; Tcl_DStringInit(&ds); @@ -534,7 +473,7 @@ TclpInitLibraryPath( Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); Tcl_DStringFree(&ds); } - ckfree((char *) pathv); + ckfree(pathv); } /* @@ -567,7 +506,7 @@ TclpInitLibraryPath( *encodingPtr = Tcl_GetEncoding(NULL, NULL); str = Tcl_GetStringFromObj(pathPtr, lengthPtr); - *valuePtr = ckalloc((unsigned int) (*lengthPtr)+1); + *valuePtr = ckalloc((*lengthPtr) + 1); memcpy(*valuePtr, str, (size_t)(*lengthPtr)+1); Tcl_DecrRefCount(pathPtr); } @@ -611,9 +550,9 @@ TclpSetInterfaces(void) /* do nothing */ } -static CONST char * +static const char * SearchKnownEncodings( - CONST char *encoding) + const char *encoding) { int left = 0; int right = sizeof(localeTable)/sizeof(LocaleTable); @@ -634,12 +573,12 @@ SearchKnownEncodings( return NULL; } -CONST char * +const char * Tcl_GetEncodingNameFromEnvironment( Tcl_DString *bufPtr) { - CONST char *encoding; - CONST char *knownEncoding; + const char *encoding; + const char *knownEncoding; Tcl_DStringInit(bufPtr); @@ -695,7 +634,7 @@ Tcl_GetEncodingNameFromEnvironment( } if (encoding != NULL) { - CONST char *p; + const char *p; Tcl_DString ds; Tcl_DStringInit(&ds); @@ -799,7 +738,7 @@ TclpSetVariables( #endif /* MAC_OS_X_VERSION_MAX_ALLOWED > 1020 */ if (MacOSXGetLibraryPath(interp, MAXPATHLEN, tclLibPath) == TCL_OK) { - CONST char *str; + const char *str; CFBundleRef bundleRef; Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY); @@ -875,7 +814,7 @@ TclpSetVariables( unameOK = 0; #ifndef NO_UNAME if (uname(&name) >= 0) { - CONST char *native; + const char *native; unameOK = 1; @@ -948,6 +887,12 @@ TclpSetVariables( Tcl_SetVar2(interp, "tcl_platform", "user", user, TCL_GLOBAL_ONLY); Tcl_DStringFree(&ds); } + + /* + * Define what the platform PATH separator is. [TIP #315] + */ + + Tcl_SetVar2(interp, "tcl_platform","pathSeparator", ":", TCL_GLOBAL_ONLY); } /* @@ -972,7 +917,7 @@ TclpSetVariables( int TclpFindVariable( - CONST char *name, /* Name of desired environment variable + const char *name, /* Name of desired environment variable * (native). */ int *lengthPtr) /* Used to return length of name (for * successful searches) or number of non-NULL @@ -980,7 +925,7 @@ TclpFindVariable( * searches). */ { int i, result = -1; - register CONST char *env, *p1, *p2; + register const char *env, *p1, *p2; Tcl_DString envString; Tcl_DStringInit(&envString); @@ -1007,212 +952,6 @@ TclpFindVariable( return result; } -#ifndef TCL_NO_STACK_CHECK -/* - *---------------------------------------------------------------------- - * - * TclpGetCStackParams -- - * - * Determine the stack params for the current thread: in which - * direction does the stack grow, and what is the stack lower (resp. - * upper) bound for safe invocation of a new command? This is used to - * cache the values needed for an efficient computation of - * TclpCheckStackSpace() when the interp is known. - * - * Results: - * Returns 1 if the stack grows down, in which case a stack lower bound - * is stored at stackBoundPtr. If the stack grows up, 0 is returned and - * an upper bound is stored at stackBoundPtr. If a bound cannot be - * determined NULL is stored at stackBoundPtr. - * - *---------------------------------------------------------------------- - */ - -int -TclpGetCStackParams( - int **stackBoundPtr) -{ - int result = TCL_OK; - size_t stackSize = 0; /* The size of the current stack. */ - ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - /* Most variables are actually in a - * thread-specific data block to minimise the - * impact on the stack. */ -#ifdef TCL_CROSS_COMPILE - if (stackGrowsDown == -1) { - /* - * Not initialised! - */ - - stackGrowsDown = StackGrowsDown(&result); - } -#endif - - /* - * The first time through in a thread: record the "outermost" stack - * frame and inquire with the OS about the stack size. - */ - - if (tsdPtr->outerVarPtr == NULL) { - tsdPtr->outerVarPtr = &result; - result = GetStackSize(&stackSize); - if (result != TCL_OK) { - /* Can't check, assume it always succeeds */ -#ifdef TCL_CROSS_COMPILE - stackGrowsDown = 1; -#endif - tsdPtr->stackBound = NULL; - goto done; - } - } - - if (stackSize || (tsdPtr->stackBound && - ((stackGrowsDown && (&result < tsdPtr->stackBound)) || - (!stackGrowsDown && (&result > tsdPtr->stackBound))))) { - /* - * Either the thread's first pass or stack failure: set the params - */ - - if (!stackSize) { - /* - * Stack failure: if we didn't already blow up, we are within the - * safety area. Recheck with the OS in case the stack was grown. - */ - result = GetStackSize(&stackSize); - if (result != TCL_OK) { - /* Can't check, assume it always succeeds */ -#ifdef TCL_CROSS_COMPILE - stackGrowsDown = 1; -#endif - tsdPtr->stackBound = NULL; - goto done; - } - } - - if (stackGrowsDown) { - tsdPtr->stackBound = (int *) ((char *)tsdPtr->outerVarPtr - - stackSize); - if (tsdPtr->stackBound > tsdPtr->outerVarPtr) { - /* Overflow, that should never happen, just set it to NULL. - * See [Bug #3166410] */ - tsdPtr->stackBound = NULL; - } - } else { - tsdPtr->stackBound = (int *) ((char *)tsdPtr->outerVarPtr + - stackSize); - if (tsdPtr->stackBound < tsdPtr->outerVarPtr) { - /* Overflow, that should never happen, just set it to NULL. - * See [Bug #3166410] */ - tsdPtr->stackBound = NULL; - } - } - } - - done: - *stackBoundPtr = tsdPtr->stackBound; - return stackGrowsDown; -} - -#ifdef TCL_CROSS_COMPILE -int -StackGrowsDown( - int *parent) -{ - int here; - return (&here < parent); -} -#endif - -/* - *---------------------------------------------------------------------- - * - * GetStackSize -- - * - * Discover what the stack size for the current thread/process actually - * is. Expects to only ever be called once per thread and then only at a - * point when there is a reasonable amount of space left on the current - * stack; TclpCheckStackSpace is called sufficiently frequently that that - * is true. - * - * Results: - * TCL_OK if the stack space was discovered, TCL_BREAK if the stack space - * was undiscoverable in a way that stack checks should fail, and - * TCL_CONTINUE if the stack space was undiscoverable in a way that stack - * checks should succeed. - * - * Side effects: - * None - * - *---------------------------------------------------------------------- - */ - -static int -GetStackSize( - size_t *stackSizePtr) -{ - size_t rawStackSize; - struct rlimit rLimit; /* The result from getrlimit(). */ - -#ifdef TCL_THREADS - rawStackSize = TclpThreadGetStackSize(); - if (rawStackSize == (size_t) -1) { - /* - * Some kind of confirmed error in TclpThreadGetStackSize?! Fall back - * to whatever getrlimit can determine. - */ - STACK_DEBUG(("stack checks: TclpThreadGetStackSize failed in \n")); - } - if (rawStackSize > 0) { - goto finalSanityCheck; - } - - /* - * If we have zero or an error, try the system limits instead. After all, - * the pthread documentation states that threads should always be bound by - * the system stack size limit in any case. - */ -#endif /* TCL_THREADS */ - - if (getrlimit(RLIMIT_STACK, &rLimit) != 0) { - /* - * getrlimit() failed, just fail the whole thing. - */ - STACK_DEBUG(("skipping stack checks with failure: getrlimit failed\n")); - return TCL_BREAK; - } - if (rLimit.rlim_cur == RLIM_INFINITY) { - /* - * Limit is "infinite"; there is no stack limit. - */ - STACK_DEBUG(("skipping stack checks with success: infinite limit\n")); - return TCL_CONTINUE; - } - rawStackSize = rLimit.rlim_cur; - - /* - * Final sanity check on the determined stack size. If we fail this, - * assume there are bogus values about and that we can't actually figure - * out what the stack size really is. - */ - -#ifdef TCL_THREADS /* Stop warning... */ - finalSanityCheck: -#endif - if (rawStackSize <= 0) { - STACK_DEBUG(("skipping stack checks with success\n")); - return TCL_CONTINUE; - } - - /* - * Calculate a stack size with a safety margin. - */ - - *stackSizePtr = (rawStackSize / TCL_MAGIC_STACK_DIVISOR) - - (getpagesize() * TCL_RESERVED_STACK_PAGES); - - return TCL_OK; -} -#endif /* TCL_NO_STACK_CHECK */ /* *---------------------------------------------------------------------- diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c index e7bf78d..ebbbb78 100644 --- a/unix/tclUnixNotfy.c +++ b/unix/tclUnixNotfy.c @@ -7,8 +7,8 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" @@ -17,14 +17,6 @@ #include <signal.h> /* - * This code does deep stub magic to allow replacement of the notifier at - * runtime. - */ - -extern TclStubs tclStubs; -extern Tcl_NotifierProcs tclOriginalNotifier; - -/* * This structure is used to keep track of the notifier info for a registered * file. */ @@ -59,13 +51,13 @@ typedef struct FileHandlerEvent { /* * The following structure contains a set of select() masks to track readable, - * writable, and exceptional conditions. + * writable, and exception conditions. */ typedef struct SelectMasks { fd_set readable; fd_set writable; - fd_set exceptional; + fd_set exception; } SelectMasks; /* @@ -178,16 +170,16 @@ static Tcl_Condition notifierCV; static Tcl_ThreadId notifierThread; -#endif +#endif /* TCL_THREADS */ /* * Static routines defined in this file. */ #ifdef TCL_THREADS -static void NotifierThreadProc(ClientData clientData); +static void NotifierThreadProc(ClientData clientData); #endif -static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); +static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); /* *---------------------------------------------------------------------- @@ -208,35 +200,39 @@ static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); ClientData Tcl_InitNotifier(void) { - ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + if (tclNotifierHooks.initNotifierProc) { + return tclNotifierHooks.initNotifierProc(); + } else { + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); #ifdef TCL_THREADS - tsdPtr->eventReady = 0; + tsdPtr->eventReady = 0; - /* - * Start the Notifier thread if necessary. - */ + /* + * Start the Notifier thread if necessary. + */ - Tcl_MutexLock(¬ifierMutex); - if (notifierCount == 0) { - if (TclpThreadCreate(¬ifierThread, NotifierThreadProc, NULL, - TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) { - Tcl_Panic("Tcl_InitNotifier: unable to start notifier thread"); + Tcl_MutexLock(¬ifierMutex); + if (notifierCount == 0) { + if (TclpThreadCreate(¬ifierThread, NotifierThreadProc, NULL, + TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) { + Tcl_Panic("Tcl_InitNotifier: unable to start notifier thread"); + } } - } - notifierCount++; + notifierCount++; - /* - * Wait for the notifier pipe to be created. - */ + /* + * Wait for the notifier pipe to be created. + */ - while (triggerPipe < 0) { - Tcl_ConditionWait(¬ifierCV, ¬ifierMutex, NULL); - } + while (triggerPipe < 0) { + Tcl_ConditionWait(¬ifierCV, ¬ifierMutex, NULL); + } - Tcl_MutexUnlock(¬ifierMutex); -#endif - return (ClientData) tsdPtr; + Tcl_MutexUnlock(¬ifierMutex); +#endif /* TCL_THREADS */ + return tsdPtr; + } } /* @@ -261,57 +257,65 @@ void Tcl_FinalizeNotifier( ClientData clientData) /* Not used. */ { + if (tclNotifierHooks.finalizeNotifierProc) { + tclNotifierHooks.finalizeNotifierProc(clientData); + return; + } else { #ifdef TCL_THREADS - ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - Tcl_MutexLock(¬ifierMutex); - notifierCount--; + Tcl_MutexLock(¬ifierMutex); + notifierCount--; - /* - * If this is the last thread to use the notifier, close the notifier pipe - * and wait for the background thread to terminate. - */ + /* + * If this is the last thread to use the notifier, close the notifier + * pipe and wait for the background thread to terminate. + */ - if (notifierCount == 0) { - int result; + if (notifierCount == 0) { + int result; - if (triggerPipe < 0) { - Tcl_Panic("Tcl_FinalizeNotifier: notifier pipe not initialized"); - } + if (triggerPipe < 0) { + Tcl_Panic("Tcl_FinalizeNotifier: %s", + "notifier pipe not initialized"); + } - /* - * Send "q" message to the notifier thread so that it will terminate. - * The notifier will return from its call to select() and notice that - * a "q" message has arrived, it will then close its side of the pipe - * and terminate its thread. Note the we can not just close the pipe - * and check for EOF in the notifier thread because if a background - * child process was created with exec, select() would not register - * the EOF on the pipe until the child processes had terminated. [Bug: - * 4139] [Bug: 1222872] - */ + /* + * Send "q" message to the notifier thread so that it will + * terminate. The notifier will return from its call to select() + * and notice that a "q" message has arrived, it will then close + * its side of the pipe and terminate its thread. Note the we can + * not just close the pipe and check for EOF in the notifier thread + * because if a background child process was created with exec, + * select() would not register the EOF on the pipe until the child + * processes had terminated. [Bug: 4139] [Bug: 1222872] + */ - if (write(triggerPipe, "q", 1) != 1) { - Tcl_Panic("Tcl_FinalizeNotifier: unable to write q to triggerPipe"); - } - close(triggerPipe); - while(triggerPipe >= 0) { - Tcl_ConditionWait(¬ifierCV, ¬ifierMutex, NULL); - } + if (write(triggerPipe, "q", 1) != 1) { + Tcl_Panic("Tcl_FinalizeNotifier: %s", + "unable to write q to triggerPipe"); + } + close(triggerPipe); + while(triggerPipe >= 0) { + Tcl_ConditionWait(¬ifierCV, ¬ifierMutex, NULL); + } - result = Tcl_JoinThread(notifierThread, NULL); - if (result) { - Tcl_Panic("Tcl_FinalizeNotifier: unable to join notifier thread"); + result = Tcl_JoinThread(notifierThread, NULL); + if (result) { + Tcl_Panic("Tcl_FinalizeNotifier: %s", + "unable to join notifier thread"); + } } - } - /* - * Clean up any synchronization objects in the thread local storage. - */ + /* + * Clean up any synchronization objects in the thread local storage. + */ - Tcl_ConditionFinalize(&(tsdPtr->waitCV)); + Tcl_ConditionFinalize(&tsdPtr->waitCV); - Tcl_MutexUnlock(¬ifierMutex); -#endif + Tcl_MutexUnlock(¬ifierMutex); +#endif /* TCL_THREADS */ + } } /* @@ -337,13 +341,19 @@ void Tcl_AlertNotifier( ClientData clientData) { + if (tclNotifierHooks.alertNotifierProc) { + tclNotifierHooks.alertNotifierProc(clientData); + return; + } else { #ifdef TCL_THREADS - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) clientData; - Tcl_MutexLock(¬ifierMutex); - tsdPtr->eventReady = 1; - Tcl_ConditionNotify(&tsdPtr->waitCV); - Tcl_MutexUnlock(¬ifierMutex); -#endif + ThreadSpecificData *tsdPtr = clientData; + + Tcl_MutexLock(¬ifierMutex); + tsdPtr->eventReady = 1; + Tcl_ConditionNotify(&tsdPtr->waitCV); + Tcl_MutexUnlock(¬ifierMutex); +#endif /* TCL_THREADS */ + } } /* @@ -366,16 +376,17 @@ Tcl_AlertNotifier( void Tcl_SetTimer( - Tcl_Time *timePtr) /* Timeout value, may be NULL. */ + const Tcl_Time *timePtr) /* Timeout value, may be NULL. */ { - /* - * The interval timer doesn't do anything in this implementation, because - * the only event loop is via Tcl_DoOneEvent, which passes timeout values - * to Tcl_WaitForEvent. - */ - - if (tclStubs.tcl_SetTimer != tclOriginalNotifier.setTimerProc) { - tclStubs.tcl_SetTimer(timePtr); + if (tclNotifierHooks.setTimerProc) { + tclNotifierHooks.setTimerProc(timePtr); + return; + } else { + /* + * The interval timer doesn't do anything in this implementation, + * because the only event loop is via Tcl_DoOneEvent, which passes + * timeout values to Tcl_WaitForEvent. + */ } } @@ -400,6 +411,12 @@ Tcl_ServiceModeHook( int mode) /* Either TCL_SERVICE_ALL, or * TCL_SERVICE_NONE. */ { + if (tclNotifierHooks.serviceModeHookProc) { + tclNotifierHooks.serviceModeHookProc(mode); + return; + } else { + /* Does nothing in this implementation. */ + } } /* @@ -429,53 +446,52 @@ Tcl_CreateFileHandler( * event. */ ClientData clientData) /* Arbitrary data to pass to proc. */ { - ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - FileHandler *filePtr; - - if (tclStubs.tcl_CreateFileHandler != - tclOriginalNotifier.createFileHandlerProc) { - tclStubs.tcl_CreateFileHandler(fd, mask, proc, clientData); + if (tclNotifierHooks.createFileHandlerProc) { + tclNotifierHooks.createFileHandlerProc(fd, mask, proc, clientData); return; - } + } else { + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + FileHandler *filePtr; - for (filePtr = tsdPtr->firstFileHandlerPtr; filePtr != NULL; - filePtr = filePtr->nextPtr) { - if (filePtr->fd == fd) { - break; + for (filePtr = tsdPtr->firstFileHandlerPtr; filePtr != NULL; + filePtr = filePtr->nextPtr) { + if (filePtr->fd == fd) { + break; + } } - } - if (filePtr == NULL) { - filePtr = (FileHandler*) ckalloc(sizeof(FileHandler)); - filePtr->fd = fd; - filePtr->readyMask = 0; - filePtr->nextPtr = tsdPtr->firstFileHandlerPtr; - tsdPtr->firstFileHandlerPtr = filePtr; - } - filePtr->proc = proc; - filePtr->clientData = clientData; - filePtr->mask = mask; + if (filePtr == NULL) { + filePtr = ckalloc(sizeof(FileHandler)); + filePtr->fd = fd; + filePtr->readyMask = 0; + filePtr->nextPtr = tsdPtr->firstFileHandlerPtr; + tsdPtr->firstFileHandlerPtr = filePtr; + } + filePtr->proc = proc; + filePtr->clientData = clientData; + filePtr->mask = mask; - /* - * Update the check masks for this file. - */ + /* + * Update the check masks for this file. + */ - if (mask & TCL_READABLE) { - FD_SET(fd, &(tsdPtr->checkMasks.readable)); - } else { - FD_CLR(fd, &(tsdPtr->checkMasks.readable)); - } - if (mask & TCL_WRITABLE) { - FD_SET(fd, &(tsdPtr->checkMasks.writable)); - } else { - FD_CLR(fd, &(tsdPtr->checkMasks.writable)); - } - if (mask & TCL_EXCEPTION) { - FD_SET(fd, &(tsdPtr->checkMasks.exceptional)); - } else { - FD_CLR(fd, &(tsdPtr->checkMasks.exceptional)); - } - if (tsdPtr->numFdBits <= fd) { - tsdPtr->numFdBits = fd+1; + if (mask & TCL_READABLE) { + FD_SET(fd, &tsdPtr->checkMasks.readable); + } else { + FD_CLR(fd, &tsdPtr->checkMasks.readable); + } + if (mask & TCL_WRITABLE) { + FD_SET(fd, &tsdPtr->checkMasks.writable); + } else { + FD_CLR(fd, &tsdPtr->checkMasks.writable); + } + if (mask & TCL_EXCEPTION) { + FD_SET(fd, &tsdPtr->checkMasks.exception); + } else { + FD_CLR(fd, &tsdPtr->checkMasks.exception); + } + if (tsdPtr->numFdBits <= fd) { + tsdPtr->numFdBits = fd+1; + } } } @@ -500,72 +516,71 @@ Tcl_DeleteFileHandler( int fd) /* Stream id for which to remove callback * function. */ { - FileHandler *filePtr, *prevPtr; - int i; - ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - - if (tclStubs.tcl_DeleteFileHandler != - tclOriginalNotifier.deleteFileHandlerProc) { - tclStubs.tcl_DeleteFileHandler(fd); + if (tclNotifierHooks.deleteFileHandlerProc) { + tclNotifierHooks.deleteFileHandlerProc(fd); return; - } + } else { + FileHandler *filePtr, *prevPtr; + int i; + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - /* - * Find the entry for the given file (and return if there isn't one). - */ + /* + * Find the entry for the given file (and return if there isn't one). + */ - for (prevPtr = NULL, filePtr = tsdPtr->firstFileHandlerPtr; ; - prevPtr = filePtr, filePtr = filePtr->nextPtr) { - if (filePtr == NULL) { - return; - } - if (filePtr->fd == fd) { - break; + for (prevPtr = NULL, filePtr = tsdPtr->firstFileHandlerPtr; ; + prevPtr = filePtr, filePtr = filePtr->nextPtr) { + if (filePtr == NULL) { + return; + } + if (filePtr->fd == fd) { + break; + } } - } - /* - * Update the check masks for this file. - */ + /* + * Update the check masks for this file. + */ - if (filePtr->mask & TCL_READABLE) { - FD_CLR(fd, &(tsdPtr->checkMasks.readable)); - } - if (filePtr->mask & TCL_WRITABLE) { - FD_CLR(fd, &(tsdPtr->checkMasks.writable)); - } - if (filePtr->mask & TCL_EXCEPTION) { - FD_CLR(fd, &(tsdPtr->checkMasks.exceptional)); - } + if (filePtr->mask & TCL_READABLE) { + FD_CLR(fd, &tsdPtr->checkMasks.readable); + } + if (filePtr->mask & TCL_WRITABLE) { + FD_CLR(fd, &tsdPtr->checkMasks.writable); + } + if (filePtr->mask & TCL_EXCEPTION) { + FD_CLR(fd, &tsdPtr->checkMasks.exception); + } - /* - * Find current max fd. - */ + /* + * Find current max fd. + */ - if (fd+1 == tsdPtr->numFdBits) { - int numFdBits = 0; + if (fd+1 == tsdPtr->numFdBits) { + int numFdBits = 0; - for (i = fd-1; i >= 0; i--) { - if (FD_ISSET(i, &(tsdPtr->checkMasks.readable)) - || FD_ISSET(i, &(tsdPtr->checkMasks.writable)) - || FD_ISSET(i, &(tsdPtr->checkMasks.exceptional))) { - numFdBits = i+1; - break; + for (i = fd-1; i >= 0; i--) { + if (FD_ISSET(i, &tsdPtr->checkMasks.readable) + || FD_ISSET(i, &tsdPtr->checkMasks.writable) + || FD_ISSET(i, &tsdPtr->checkMasks.exception)) { + numFdBits = i+1; + break; + } } + tsdPtr->numFdBits = numFdBits; } - tsdPtr->numFdBits = numFdBits; - } - /* - * Clean up information in the callback record. - */ + /* + * Clean up information in the callback record. + */ - if (prevPtr == NULL) { - tsdPtr->firstFileHandlerPtr = filePtr->nextPtr; - } else { - prevPtr->nextPtr = filePtr->nextPtr; + if (prevPtr == NULL) { + tsdPtr->firstFileHandlerPtr = filePtr->nextPtr; + } else { + prevPtr->nextPtr = filePtr->nextPtr; + } + ckfree(filePtr); } - ckfree((char *) filePtr); } /* @@ -634,7 +649,7 @@ FileHandlerEventProc( mask = filePtr->readyMask & filePtr->mask; filePtr->readyMask = 0; if (mask != 0) { - (*filePtr->proc)(filePtr->clientData, mask); + filePtr->proc(filePtr->clientData, mask); } break; } @@ -661,210 +676,214 @@ FileHandlerEventProc( int Tcl_WaitForEvent( - Tcl_Time *timePtr) /* Maximum block time, or NULL. */ + const Tcl_Time *timePtr) /* Maximum block time, or NULL. */ { - FileHandler *filePtr; - FileHandlerEvent *fileEvPtr; - int mask; - Tcl_Time vTime; + if (tclNotifierHooks.waitForEventProc) { + return tclNotifierHooks.waitForEventProc(timePtr); + } else { + FileHandler *filePtr; + int mask; + Tcl_Time vTime; #ifdef TCL_THREADS - int waitForFiles; + int waitForFiles; #else - /* - * Impl. notes: timeout & timeoutPtr are used if, and only if threads are - * not enabled. They are the arguments for the regular select() used when - * the core is not thread-enabled. - */ + /* + * Impl. notes: timeout & timeoutPtr are used if, and only if threads + * are not enabled. They are the arguments for the regular select() + * used when the core is not thread-enabled. + */ - struct timeval timeout, *timeoutPtr; - int numFound; + struct timeval timeout, *timeoutPtr; + int numFound; #endif /* TCL_THREADS */ - ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - - if (tclStubs.tcl_WaitForEvent != tclOriginalNotifier.waitForEventProc) { - return tclStubs.tcl_WaitForEvent(timePtr); - } + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - /* - * Set up the timeout structure. Note that if there are no events to check - * for, we return with a negative result rather than blocking forever. - */ - - if (timePtr != NULL) { /* - * TIP #233 (Virtualized Time). Is virtual time in effect? And do we - * actually have something to scale? If yes to both then we call the - * handler to do this scaling. + * Set up the timeout structure. Note that if there are no events to + * check for, we return with a negative result rather than blocking + * forever. */ - if (timePtr->sec != 0 || timePtr->usec != 0) { - vTime = *timePtr; - (*tclScaleTimeProcPtr) (&vTime, tclTimeClientData); - timePtr = &vTime; - } + if (timePtr != NULL) { + /* + * TIP #233 (Virtualized Time). Is virtual time in effect? And do + * we actually have something to scale? If yes to both then we call + * the handler to do this scaling. + */ + + if (timePtr->sec != 0 || timePtr->usec != 0) { + vTime = *timePtr; + tclScaleTimeProcPtr(&vTime, tclTimeClientData); + timePtr = &vTime; + } #ifndef TCL_THREADS - timeout.tv_sec = timePtr->sec; - timeout.tv_usec = timePtr->usec; - timeoutPtr = &timeout; - } else if (tsdPtr->numFdBits == 0) { - /* - * If there are no threads, no timeout, and no fds registered, then - * there are no events possible and we must avoid deadlock. Note that - * this is not entirely correct because there might be a signal that - * could interrupt the select call, but we don't handle that case if - * we aren't using threads. - */ + timeout.tv_sec = timePtr->sec; + timeout.tv_usec = timePtr->usec; + timeoutPtr = &timeout; + } else if (tsdPtr->numFdBits == 0) { + /* + * If there are no threads, no timeout, and no fds registered, then + * there are no events possible and we must avoid deadlock. Note + * that this is not entirely correct because there might be a + * signal that could interrupt the select call, but we don't handle + * that case if we aren't using threads. + */ - return -1; - } else { - timeoutPtr = NULL; + return -1; + } else { + timeoutPtr = NULL; #endif /* TCL_THREADS */ - } + } #ifdef TCL_THREADS - /* - * Place this thread on the list of interested threads, signal the - * notifier thread, and wait for a response or a timeout. - */ + /* + * Place this thread on the list of interested threads, signal the + * notifier thread, and wait for a response or a timeout. + */ - Tcl_MutexLock(¬ifierMutex); + Tcl_MutexLock(¬ifierMutex); - if (timePtr != NULL && timePtr->sec == 0 && (timePtr->usec == 0 + if (timePtr != NULL && timePtr->sec == 0 && (timePtr->usec == 0 #if defined(__APPLE__) && defined(__LP64__) + /* + * On 64-bit Darwin, pthread_cond_timedwait() appears to have a + * bug that causes it to wait forever when passed an absolute + * time which has already been exceeded by the system time; as + * a workaround, when given a very brief timeout, just do a + * poll. [Bug 1457797] + */ + || timePtr->usec < 10 +#endif /* __APPLE__ && __LP64__ */ + )) { /* - * On 64-bit Darwin, pthread_cond_timedwait() appears to have a bug - * that causes it to wait forever when passed an absolute time which - * has already been exceeded by the system time; as a workaround, - * when given a very brief timeout, just do a poll. [Bug 1457797] + * Cannot emulate a polling select with a polling condition + * variable. Instead, pretend to wait for files and tell the + * notifier thread what we are doing. The notifier thread makes + * sure it goes through select with its select mask in the same + * state as ours currently is. We block until that happens. */ - || timePtr->usec < 10 -#endif - )) { - /* - * Cannot emulate a polling select with a polling condition variable. - * Instead, pretend to wait for files and tell the notifier thread - * what we are doing. The notifier thread makes sure it goes through - * select with its select mask in the same state as ours currently is. - * We block until that happens. - */ - waitForFiles = 1; - tsdPtr->pollState = POLL_WANT; - timePtr = NULL; - } else { - waitForFiles = (tsdPtr->numFdBits > 0); - tsdPtr->pollState = 0; - } + waitForFiles = 1; + tsdPtr->pollState = POLL_WANT; + timePtr = NULL; + } else { + waitForFiles = (tsdPtr->numFdBits > 0); + tsdPtr->pollState = 0; + } - if (waitForFiles) { - /* - * Add the ThreadSpecificData structure of this thread to the list of - * ThreadSpecificData structures of all threads that are waiting on - * file events. - */ + if (waitForFiles) { + /* + * Add the ThreadSpecificData structure of this thread to the list + * of ThreadSpecificData structures of all threads that are waiting + * on file events. + */ - tsdPtr->nextPtr = waitingListPtr; - if (waitingListPtr) { - waitingListPtr->prevPtr = tsdPtr; - } - tsdPtr->prevPtr = 0; - waitingListPtr = tsdPtr; - tsdPtr->onList = 1; + tsdPtr->nextPtr = waitingListPtr; + if (waitingListPtr) { + waitingListPtr->prevPtr = tsdPtr; + } + tsdPtr->prevPtr = 0; + waitingListPtr = tsdPtr; + tsdPtr->onList = 1; - if (write(triggerPipe, "", 1) != 1) { - Tcl_Panic("Tcl_WaitForEvent: unable to write to triggerPipe"); + if (write(triggerPipe, "", 1) != 1) { + Tcl_Panic("Tcl_WaitForEvent: %s", + "unable to write to triggerPipe"); + } } - } - FD_ZERO(&(tsdPtr->readyMasks.readable)); - FD_ZERO(&(tsdPtr->readyMasks.writable)); - FD_ZERO(&(tsdPtr->readyMasks.exceptional)); + FD_ZERO(&tsdPtr->readyMasks.readable); + FD_ZERO(&tsdPtr->readyMasks.writable); + FD_ZERO(&tsdPtr->readyMasks.exception); - if (!tsdPtr->eventReady) { - Tcl_ConditionWait(&tsdPtr->waitCV, ¬ifierMutex, timePtr); - } - tsdPtr->eventReady = 0; + if (!tsdPtr->eventReady) { + Tcl_ConditionWait(&tsdPtr->waitCV, ¬ifierMutex, timePtr); + } + tsdPtr->eventReady = 0; - if (waitForFiles && tsdPtr->onList) { - /* - * Remove the ThreadSpecificData structure of this thread from the - * waiting list. Alert the notifier thread to recompute its select - * masks - skipping this caused a hang when trying to close a pipe - * which the notifier thread was still doing a select on. - */ + if (waitForFiles && tsdPtr->onList) { + /* + * Remove the ThreadSpecificData structure of this thread from the + * waiting list. Alert the notifier thread to recompute its select + * masks - skipping this caused a hang when trying to close a pipe + * which the notifier thread was still doing a select on. + */ - if (tsdPtr->prevPtr) { - tsdPtr->prevPtr->nextPtr = tsdPtr->nextPtr; - } else { - waitingListPtr = tsdPtr->nextPtr; - } - if (tsdPtr->nextPtr) { - tsdPtr->nextPtr->prevPtr = tsdPtr->prevPtr; - } - tsdPtr->nextPtr = tsdPtr->prevPtr = NULL; - tsdPtr->onList = 0; - if (write(triggerPipe, "", 1) != 1) { - Tcl_Panic("Tcl_WaitForEvent: unable to write to triggerPipe"); + if (tsdPtr->prevPtr) { + tsdPtr->prevPtr->nextPtr = tsdPtr->nextPtr; + } else { + waitingListPtr = tsdPtr->nextPtr; + } + if (tsdPtr->nextPtr) { + tsdPtr->nextPtr->prevPtr = tsdPtr->prevPtr; + } + tsdPtr->nextPtr = tsdPtr->prevPtr = NULL; + tsdPtr->onList = 0; + if (write(triggerPipe, "", 1) != 1) { + Tcl_Panic("Tcl_WaitForEvent: %s", + "unable to write to triggerPipe"); + } } - } #else - tsdPtr->readyMasks = tsdPtr->checkMasks; - numFound = select(tsdPtr->numFdBits, &(tsdPtr->readyMasks.readable), - &(tsdPtr->readyMasks.writable), &(tsdPtr->readyMasks.exceptional), - timeoutPtr); + tsdPtr->readyMasks = tsdPtr->checkMasks; + numFound = select(tsdPtr->numFdBits, &tsdPtr->readyMasks.readable, + &tsdPtr->readyMasks.writable, &tsdPtr->readyMasks.exception, + timeoutPtr); - /* - * Some systems don't clear the masks after an error, so we have to do it - * here. - */ + /* + * Some systems don't clear the masks after an error, so we have to do + * it here. + */ - if (numFound == -1) { - FD_ZERO(&(tsdPtr->readyMasks.readable)); - FD_ZERO(&(tsdPtr->readyMasks.writable)); - FD_ZERO(&(tsdPtr->readyMasks.exceptional)); - } + if (numFound == -1) { + FD_ZERO(&tsdPtr->readyMasks.readable); + FD_ZERO(&tsdPtr->readyMasks.writable); + FD_ZERO(&tsdPtr->readyMasks.exception); + } #endif /* TCL_THREADS */ - /* - * Queue all detected file events before returning. - */ + /* + * Queue all detected file events before returning. + */ - for (filePtr = tsdPtr->firstFileHandlerPtr; (filePtr != NULL); - filePtr = filePtr->nextPtr) { + for (filePtr = tsdPtr->firstFileHandlerPtr; (filePtr != NULL); + filePtr = filePtr->nextPtr) { + mask = 0; + if (FD_ISSET(filePtr->fd, &tsdPtr->readyMasks.readable)) { + mask |= TCL_READABLE; + } + if (FD_ISSET(filePtr->fd, &tsdPtr->readyMasks.writable)) { + mask |= TCL_WRITABLE; + } + if (FD_ISSET(filePtr->fd, &tsdPtr->readyMasks.exception)) { + mask |= TCL_EXCEPTION; + } - mask = 0; - if (FD_ISSET(filePtr->fd, &(tsdPtr->readyMasks.readable))) { - mask |= TCL_READABLE; - } - if (FD_ISSET(filePtr->fd, &(tsdPtr->readyMasks.writable))) { - mask |= TCL_WRITABLE; - } - if (FD_ISSET(filePtr->fd, &(tsdPtr->readyMasks.exceptional))) { - mask |= TCL_EXCEPTION; - } + if (!mask) { + continue; + } - if (!mask) { - continue; - } + /* + * Don't bother to queue an event if the mask was previously + * non-zero since an event must still be on the queue. + */ - /* - * Don't bother to queue an event if the mask was previously non-zero - * since an event must still be on the queue. - */ + if (filePtr->readyMask == 0) { + FileHandlerEvent *fileEvPtr = + ckalloc(sizeof(FileHandlerEvent)); - if (filePtr->readyMask == 0) { - fileEvPtr = (FileHandlerEvent *) ckalloc(sizeof(FileHandlerEvent)); - fileEvPtr->header.proc = FileHandlerEventProc; - fileEvPtr->fd = filePtr->fd; - Tcl_QueueEvent((Tcl_Event *) fileEvPtr, TCL_QUEUE_TAIL); + fileEvPtr->header.proc = FileHandlerEventProc; + fileEvPtr->fd = filePtr->fd; + Tcl_QueueEvent((Tcl_Event *) fileEvPtr, TCL_QUEUE_TAIL); + } + filePtr->readyMask = mask; } - filePtr->readyMask = mask; - } #ifdef TCL_THREADS - Tcl_MutexUnlock(¬ifierMutex); + Tcl_MutexUnlock(¬ifierMutex); #endif /* TCL_THREADS */ - return 0; + return 0; + } } #ifdef TCL_THREADS @@ -899,7 +918,7 @@ NotifierThreadProc( ThreadSpecificData *tsdPtr; fd_set readableMask; fd_set writableMask; - fd_set exceptionalMask; + fd_set exceptionMask; int fds[2]; int i, numFdBits = 0, receivePipe; long found; @@ -907,16 +926,26 @@ NotifierThreadProc( char buf[2]; if (pipe(fds) != 0) { - Tcl_Panic("NotifierThreadProc: could not create trigger pipe"); + Tcl_Panic("NotifierThreadProc: %s", "could not create trigger pipe"); } receivePipe = fds[0]; if (TclUnixSetBlockingMode(receivePipe, TCL_MODE_NONBLOCKING) < 0) { - Tcl_Panic("NotifierThreadProc: could not make receive pipe non blocking"); + Tcl_Panic("NotifierThreadProc: %s", + "could not make receive pipe non blocking"); } if (TclUnixSetBlockingMode(fds[1], TCL_MODE_NONBLOCKING) < 0) { - Tcl_Panic("NotifierThreadProc: could not make trigger pipe non blocking"); + Tcl_Panic("NotifierThreadProc: %s", + "could not make trigger pipe non blocking"); + } + if (fcntl(receivePipe, F_SETFD, FD_CLOEXEC) < 0) { + Tcl_Panic("NotifierThreadProc: %s", + "could not make receive pipe close-on-exec"); + } + if (fcntl(fds[1], F_SETFD, FD_CLOEXEC) < 0) { + Tcl_Panic("NotifierThreadProc: %s", + "could not make trigger pipe close-on-exec"); } /* @@ -940,7 +969,7 @@ NotifierThreadProc( while (1) { FD_ZERO(&readableMask); FD_ZERO(&writableMask); - FD_ZERO(&exceptionalMask); + FD_ZERO(&exceptionMask); /* * Compute the logical OR of the select masks from all the waiting @@ -951,14 +980,14 @@ NotifierThreadProc( timePtr = NULL; for (tsdPtr = waitingListPtr; tsdPtr; tsdPtr = tsdPtr->nextPtr) { for (i = tsdPtr->numFdBits-1; i >= 0; --i) { - if (FD_ISSET(i, &(tsdPtr->checkMasks.readable))) { + if (FD_ISSET(i, &tsdPtr->checkMasks.readable)) { FD_SET(i, &readableMask); } - if (FD_ISSET(i, &(tsdPtr->checkMasks.writable))) { + if (FD_ISSET(i, &tsdPtr->checkMasks.writable)) { FD_SET(i, &writableMask); } - if (FD_ISSET(i, &(tsdPtr->checkMasks.exceptional))) { - FD_SET(i, &exceptionalMask); + if (FD_ISSET(i, &tsdPtr->checkMasks.exception)) { + FD_SET(i, &exceptionMask); } } if (tsdPtr->numFdBits > numFdBits) { @@ -985,7 +1014,7 @@ NotifierThreadProc( } FD_SET(receivePipe, &readableMask); - if (select(numFdBits, &readableMask, &writableMask, &exceptionalMask, + if (select(numFdBits, &readableMask, &writableMask, &exceptionMask, timePtr) == -1) { /* * Try again immediately on an error. @@ -1003,19 +1032,19 @@ NotifierThreadProc( found = 0; for (i = tsdPtr->numFdBits-1; i >= 0; --i) { - if (FD_ISSET(i, &(tsdPtr->checkMasks.readable)) + if (FD_ISSET(i, &tsdPtr->checkMasks.readable) && FD_ISSET(i, &readableMask)) { - FD_SET(i, &(tsdPtr->readyMasks.readable)); + FD_SET(i, &tsdPtr->readyMasks.readable); found = 1; } - if (FD_ISSET(i, &(tsdPtr->checkMasks.writable)) + if (FD_ISSET(i, &tsdPtr->checkMasks.writable) && FD_ISSET(i, &writableMask)) { - FD_SET(i, &(tsdPtr->readyMasks.writable)); + FD_SET(i, &tsdPtr->readyMasks.writable); found = 1; } - if (FD_ISSET(i, &(tsdPtr->checkMasks.exceptional)) - && FD_ISSET(i, &exceptionalMask)) { - FD_SET(i, &(tsdPtr->readyMasks.exceptional)); + if (FD_ISSET(i, &tsdPtr->checkMasks.exception) + && FD_ISSET(i, &exceptionMask)) { + FD_SET(i, &tsdPtr->readyMasks.exception); found = 1; } } @@ -1079,7 +1108,7 @@ NotifierThreadProc( Tcl_ConditionNotify(¬ifierCV); Tcl_MutexUnlock(¬ifierMutex); - TclpThreadExit (0); + TclpThreadExit(0); } #endif /* TCL_THREADS */ diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index eb3a218..d01624c 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -49,8 +49,8 @@ typedef struct PipeState { */ static int PipeBlockModeProc(ClientData instanceData, int mode); -static int PipeCloseProc(ClientData instanceData, - Tcl_Interp *interp); +static int PipeClose2Proc(ClientData instanceData, + Tcl_Interp *interp, int flags); static int PipeGetHandleProc(ClientData instanceData, int direction, ClientData *handlePtr); static int PipeInputProc(ClientData instanceData, char *buf, @@ -66,10 +66,10 @@ static int SetupStdFile(TclFile file, int type); * I/O: */ -static Tcl_ChannelType pipeChannelType = { +static const Tcl_ChannelType pipeChannelType = { "pipe", /* Type name. */ TCL_CHANNEL_VERSION_5, /* v5 channel */ - PipeCloseProc, /* Close proc. */ + TCL_CLOSE2PROC, /* Close proc. */ PipeInputProc, /* Input proc. */ PipeOutputProc, /* Output proc. */ NULL, /* Seek proc. */ @@ -77,7 +77,7 @@ static Tcl_ChannelType pipeChannelType = { NULL, /* Get option proc. */ PipeWatchProc, /* Initialize notifier. */ PipeGetHandleProc, /* Get OS handles out of channel. */ - NULL, /* close2proc. */ + PipeClose2Proc, /* close2proc. */ PipeBlockModeProc, /* Set blocking or non-blocking mode.*/ NULL, /* flush proc. */ NULL, /* handler proc. */ @@ -109,12 +109,11 @@ TclpMakeFile( { ClientData data; - if (Tcl_GetChannelHandle(channel, direction, - (ClientData *) &data) == TCL_OK) { - return MakeFile(PTR2INT(data)); - } else { - return (TclFile) NULL; + if (Tcl_GetChannelHandle(channel, direction, &data) != TCL_OK) { + return NULL; } + + return MakeFile(PTR2INT(data)); } /* @@ -262,12 +261,46 @@ TclpTempFileName(void) fcntl(fd, F_SETFD, FD_CLOEXEC); unlink(fileName); /* INTL: Native. */ - result = TclpNativeToNormalized((ClientData) fileName); + result = TclpNativeToNormalized(fileName); close(fd); return result; } /* + *----------------------------------------------------------------------------- + * + * TclpTempFileNameForLibrary -- + * + * Constructs a file name in the native file system where a + * dynamically loaded library may be placed. + * + * Results: + * Returns the constructed file name. If an error occurs, + * returns NULL and leaves an error message in the interpreter + * result. + * + * On Unix, it works to load a shared object from a file of any + * name, so this function is merely a thin wrapper around + * TclpTempFileName(). + * + *----------------------------------------------------------------------------- + */ + +Tcl_Obj* +TclpTempFileNameForLibrary(Tcl_Interp* interp, /* Tcl interpreter */ + Tcl_Obj* path) /* Path name of the library + * in the VFS */ +{ + Tcl_Obj* retval; + retval = TclpTempFileName(); + if (retval == NULL) { + Tcl_AppendResult(interp, "couldn't create temporary file: ", + Tcl_PosixError(interp), NULL); + } + return retval; +} + +/* *---------------------------------------------------------------------- * * TclpCreatePipe -- @@ -419,9 +452,8 @@ TclpCreateProcess( * deallocated later */ - dsArray = (Tcl_DString *) - TclStackAlloc(interp, argc * sizeof(Tcl_DString)); - newArgv = (char **) TclStackAlloc(interp, (argc+1) * sizeof(char *)); + dsArray = TclStackAlloc(interp, argc * sizeof(Tcl_DString)); + newArgv = TclStackAlloc(interp, (argc+1) * sizeof(char *)); newArgv[argc] = NULL; for (i = 0; i < argc; i++) { newArgv[i] = Tcl_UtfToExternalDString(NULL, argv[i], -1, &dsArray[i]); @@ -729,7 +761,7 @@ TclpCreateCommandChannel( { char channelName[16 + TCL_INTEGER_SPACE]; int channelId; - PipeState *statePtr = (PipeState *) ckalloc((unsigned) sizeof(PipeState)); + PipeState *statePtr = ckalloc(sizeof(PipeState)); int mode; statePtr->inFile = readFile; @@ -769,13 +801,56 @@ TclpCreateCommandChannel( sprintf(channelName, "file%d", channelId); statePtr->channel = Tcl_CreateChannel(&pipeChannelType, channelName, - (ClientData) statePtr, mode); + statePtr, mode); return statePtr->channel; } /* *---------------------------------------------------------------------- * + * Tcl_CreatePipe -- + * + * System dependent interface to create a pipe for the [chan pipe] + * command. Stolen from TclX. + * + * Results: + * TCL_OK or TCL_ERROR. + * + * Side effects: + * Registers two channels. + * + *---------------------------------------------------------------------- + */ + +int +Tcl_CreatePipe( + Tcl_Interp *interp, /* Errors returned in result. */ + Tcl_Channel *rchan, /* Returned read side. */ + Tcl_Channel *wchan, /* Returned write side. */ + int flags) /* Reserved for future use. */ +{ + int fileNums[2]; + + if (pipe(fileNums) < 0) { + Tcl_AppendResult(interp, "pipe creation failed: ", + Tcl_PosixError(interp), NULL); + return TCL_ERROR; + } + + fcntl(fileNums[0], F_SETFD, FD_CLOEXEC); + fcntl(fileNums[1], F_SETFD, FD_CLOEXEC); + + *rchan = Tcl_MakeFileChannel(INT2PTR(fileNums[0]), TCL_READABLE); + Tcl_RegisterChannel(interp, *rchan); + *wchan = Tcl_MakeFileChannel(INT2PTR(fileNums[1]), TCL_WRITABLE); + Tcl_RegisterChannel(interp, *wchan); + + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * TclGetAndDetachPids -- * * This function is invoked in the generic implementation of a @@ -818,7 +893,7 @@ TclGetAndDetachPids( Tcl_DetachPids(1, &(pipePtr->pidPtr[i])); } if (pipePtr->numPids > 0) { - ckfree((char *) pipePtr->pidPtr); + ckfree(pipePtr->pidPtr); pipePtr->numPids = 0; } } @@ -850,15 +925,13 @@ PipeBlockModeProc( { PipeState *psPtr = instanceData; - if (psPtr->inFile) { - if (TclUnixSetBlockingMode(GetFd(psPtr->inFile), mode) < 0) { - return errno; - } + if (psPtr->inFile + && TclUnixSetBlockingMode(GetFd(psPtr->inFile), mode) < 0) { + return errno; } - if (psPtr->outFile) { - if (TclUnixSetBlockingMode(GetFd(psPtr->outFile), mode) < 0) { - return errno; - } + if (psPtr->outFile + && TclUnixSetBlockingMode(GetFd(psPtr->outFile), mode) < 0) { + return errno; } psPtr->isNonBlocking = (mode == TCL_MODE_NONBLOCKING); @@ -869,11 +942,10 @@ PipeBlockModeProc( /* *---------------------------------------------------------------------- * - * PipeCloseProc -- + * PipeClose2Proc * * This function is invoked by the generic IO level to perform - * channel-type-specific cleanup when a command pipeline channel is - * closed. + * pipeline-type-specific half or full-close. * * Results: * 0 on success, errno otherwise. @@ -884,29 +956,42 @@ PipeBlockModeProc( *---------------------------------------------------------------------- */ - /* ARGSUSED */ static int -PipeCloseProc( +PipeClose2Proc( ClientData instanceData, /* The pipe to close. */ - Tcl_Interp *interp) /* For error reporting. */ + Tcl_Interp *interp, /* For error reporting. */ + int flags) /* Flags that indicate which side to close. */ { - PipeState *pipePtr; + PipeState *pipePtr = instanceData; Tcl_Channel errChan; int errorCode, result; errorCode = 0; result = 0; - pipePtr = (PipeState *) instanceData; - if (pipePtr->inFile) { + + if (((!flags) || (flags & TCL_CLOSE_READ)) && (pipePtr->inFile != NULL)) { if (TclpCloseFile(pipePtr->inFile) < 0) { errorCode = errno; + } else { + pipePtr->inFile = NULL; } } - if (pipePtr->outFile) { - if ((TclpCloseFile(pipePtr->outFile) < 0) && (errorCode == 0)) { + if (((!flags) || (flags & TCL_CLOSE_WRITE)) && (pipePtr->outFile != NULL) + && (errorCode == 0)) { + if (TclpCloseFile(pipePtr->outFile) < 0) { errorCode = errno; + } else { + pipePtr->outFile = NULL; } } + + /* + * If half-closing, stop here. + */ + + if (flags) { + return errorCode; + } if (pipePtr->isNonBlocking || TclInExit()) { /* @@ -929,7 +1014,8 @@ PipeCloseProc( if (pipePtr->errorFile) { errChan = Tcl_MakeFileChannel( - (ClientData) INT2PTR(GetFd(pipePtr->errorFile)), TCL_READABLE); + INT2PTR(GetFd(pipePtr->errorFile)), + TCL_READABLE); } else { errChan = NULL; } @@ -938,9 +1024,9 @@ PipeCloseProc( } if (pipePtr->numPids != 0) { - ckfree((char *) pipePtr->pidPtr); + ckfree(pipePtr->pidPtr); } - ckfree((char *) pipePtr); + ckfree(pipePtr); if (errorCode == 0) { return result; } @@ -973,7 +1059,7 @@ PipeInputProc( * buffer? */ int *errorCodePtr) /* Where to store error code. */ { - PipeState *psPtr = (PipeState *) instanceData; + PipeState *psPtr = instanceData; int bytesRead; /* How many bytes were actually read from the * input device? */ @@ -994,9 +1080,8 @@ PipeInputProc( if (bytesRead < 0) { *errorCodePtr = errno; return -1; - } else { - return bytesRead; } + return bytesRead; } /* @@ -1024,7 +1109,7 @@ PipeOutputProc( int toWrite, /* How many bytes to write? */ int *errorCodePtr) /* Where to store error code. */ { - PipeState *psPtr = (PipeState *) instanceData; + PipeState *psPtr = instanceData; int written; *errorCodePtr = 0; @@ -1041,9 +1126,8 @@ PipeOutputProc( if (written < 0) { *errorCodePtr = errno; return -1; - } else { - return written; } + return written; } /* @@ -1070,15 +1154,14 @@ PipeWatchProc( * TCL_READABLE, TCL_WRITABLE and * TCL_EXCEPTION. */ { - PipeState *psPtr = (PipeState *) instanceData; + PipeState *psPtr = instanceData; int newmask; if (psPtr->inFile) { newmask = mask & (TCL_READABLE | TCL_EXCEPTION); if (newmask) { Tcl_CreateFileHandler(GetFd(psPtr->inFile), mask, - (Tcl_FileProc *) Tcl_NotifyChannel, - (ClientData) psPtr->channel); + (Tcl_FileProc *) Tcl_NotifyChannel, psPtr->channel); } else { Tcl_DeleteFileHandler(GetFd(psPtr->inFile)); } @@ -1087,8 +1170,7 @@ PipeWatchProc( newmask = mask & (TCL_WRITABLE | TCL_EXCEPTION); if (newmask) { Tcl_CreateFileHandler(GetFd(psPtr->outFile), mask, - (Tcl_FileProc *) Tcl_NotifyChannel, - (ClientData) psPtr->channel); + (Tcl_FileProc *) Tcl_NotifyChannel, psPtr->channel); } else { Tcl_DeleteFileHandler(GetFd(psPtr->outFile)); } @@ -1119,14 +1201,14 @@ PipeGetHandleProc( int direction, /* TCL_READABLE or TCL_WRITABLE */ ClientData *handlePtr) /* Where to store the handle. */ { - PipeState *psPtr = (PipeState *) instanceData; + PipeState *psPtr = instanceData; if (direction == TCL_READABLE && psPtr->inFile) { - *handlePtr = (ClientData) INT2PTR(GetFd(psPtr->inFile)); + *handlePtr = INT2PTR(GetFd(psPtr->inFile)); return TCL_OK; } if (direction == TCL_WRITABLE && psPtr->outFile) { - *handlePtr = (ClientData) INT2PTR(GetFd(psPtr->outFile)); + *handlePtr = INT2PTR(GetFd(psPtr->outFile)); return TCL_OK; } return TCL_ERROR; @@ -1190,6 +1272,11 @@ Tcl_PidObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const *objv) /* Argument strings. */ { + Tcl_Channel chan; + PipeState *pipePtr; + int i; + Tcl_Obj *resultPtr, *longObjPtr; + if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "?channelId?"); return TCL_ERROR; @@ -1201,18 +1288,12 @@ Tcl_PidObjCmd( /* * Get the channel and make sure that it refers to a pipe. */ - Tcl_Channel chan; - const Tcl_ChannelType *chanTypePtr; - PipeState *pipePtr; - int i; - Tcl_Obj *resultPtr, *longObjPtr; chan = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL); - if (chan == (Tcl_Channel) NULL) { + if (chan == NULL) { return TCL_ERROR; } - chanTypePtr = Tcl_GetChannelType(chan); - if (chanTypePtr != &pipeChannelType) { + if (Tcl_GetChannelType(chan) != &pipeChannelType) { return TCL_OK; } diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h index 421d73c..fd396f7 100644 --- a/unix/tclUnixPort.h +++ b/unix/tclUnixPort.h @@ -1,32 +1,31 @@ /* * tclUnixPort.h -- * - * This header file handles porting issues that occur because - * of differences between systems. It reads in UNIX-related - * header files and sets up UNIX-related macros for Tcl's UNIX - * core. It should be the only file that contains #ifdefs to - * handle different flavors of UNIX. This file sets up the - * union of all UNIX-related things needed by any of the Tcl - * core files. This file depends on configuration #defines such - * as NO_DIRENT_H that are set up by the "configure" script. + * This header file handles porting issues that occur because of + * differences between systems. It reads in UNIX-related header files and + * sets up UNIX-related macros for Tcl's UNIX core. It should be the only + * file that contains #ifdefs to handle different flavors of UNIX. This + * file sets up the union of all UNIX-related things needed by any of the + * Tcl core files. This file depends on configuration #defines such as + * NO_DIRENT_H that are set up by the "configure" script. * - * Much of the material in this file was originally contributed - * by Karl Lehenbauer, Mark Diekhans and Peter da Silva. + * Much of the material in this file was originally contributed by Karl + * Lehenbauer, Mark Diekhans and Peter da Silva. * * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #ifndef _TCLUNIXPORT #define _TCLUNIXPORT #ifndef MODULE_SCOPE -#define MODULE_SCOPE extern +#define MODULE_SCOPE extern #endif - + /* *--------------------------------------------------------------------------- * The following sets of #includes and #ifdefs are required to get Tcl to @@ -54,6 +53,12 @@ # include <dirent.h> #endif #endif + +/* + *--------------------------------------------------------------------------- + * Parameterize for 64-bit filesystem support. + *--------------------------------------------------------------------------- + */ #ifdef HAVE_STRUCT_DIRENT64 typedef struct dirent64 Tcl_DirEntry; @@ -80,6 +85,12 @@ typedef off_t Tcl_SeekOffset; # define TclOSstat stat # define TclOSlstat lstat #endif + +/* + *--------------------------------------------------------------------------- + * Miscellaneous includes that might be missing. + *--------------------------------------------------------------------------- + */ #include <sys/file.h> #ifdef HAVE_SYS_SELECT_H @@ -116,26 +127,34 @@ typedef off_t Tcl_SeekOffset; # include "../compat/unistd.h" #endif -MODULE_SCOPE int TclUnixSetBlockingMode(int fd, int mode); +MODULE_SCOPE int TclUnixSetBlockingMode(int fd, int mode); #include <utime.h> - + /* - * Socket support stuff: This likely needs more work to parameterize for - * each system. + *--------------------------------------------------------------------------- + * Socket support stuff: This likely needs more work to parameterize for each + * system. + *--------------------------------------------------------------------------- */ + #include <sys/socket.h> /* struct sockaddr, SOCK_STREAM, ... */ #ifndef NO_UNAME # include <sys/utsname.h> /* uname system call. */ #endif #include <netinet/in.h> /* struct in_addr, struct sockaddr_in */ #include <arpa/inet.h> /* inet_ntoa() */ -#include <netdb.h> /* gethostbyname() */ - +#include <netdb.h> /* getaddrinfo() */ +#ifdef NEED_FAKE_RFC2553 +# include "../compat/fake-rfc2553.h" +#endif + /* - * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we - * look for an alternative definition. If no other alternative is available - * we use a reasonable guess. + *--------------------------------------------------------------------------- + * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we look + * for an alternative definition. If no other alternative is available we use + * a reasonable guess. + *--------------------------------------------------------------------------- */ #ifndef NO_FLOAT_H @@ -148,74 +167,84 @@ MODULE_SCOPE int TclUnixSetBlockingMode(int fd, int mode); #ifndef FLT_MAX # ifdef MAXFLOAT -# define FLT_MAX MAXFLOAT +# define FLT_MAX MAXFLOAT # else -# define FLT_MAX 3.402823466E+38F +# define FLT_MAX 3.402823466E+38F # endif #endif #ifndef FLT_MIN # ifdef MINFLOAT -# define FLT_MIN MINFLOAT +# define FLT_MIN MINFLOAT # else -# define FLT_MIN 1.175494351E-38F +# define FLT_MIN 1.175494351E-38F # endif #endif - + /* + *--------------------------------------------------------------------------- * NeXT doesn't define O_NONBLOCK, so #define it here if necessary. + *--------------------------------------------------------------------------- */ #ifndef O_NONBLOCK # define O_NONBLOCK 0x80 #endif - + /* - * The type of the status returned by wait varies from UNIX system - * to UNIX system. The macro below defines it: + *--------------------------------------------------------------------------- + * The type of the status returned by wait varies from UNIX system to UNIX + * system. The macro below defines it: + *--------------------------------------------------------------------------- */ #ifdef _AIX -# define WAIT_STATUS_TYPE pid_t +# define WAIT_STATUS_TYPE pid_t #else #ifndef NO_UNION_WAIT -# define WAIT_STATUS_TYPE union wait +# define WAIT_STATUS_TYPE union wait #else -# define WAIT_STATUS_TYPE int +# define WAIT_STATUS_TYPE int #endif #endif - + /* - * Supply definitions for macros to query wait status, if not already - * defined in header files above. + *--------------------------------------------------------------------------- + * Supply definitions for macros to query wait status, if not already defined + * in header files above. + *--------------------------------------------------------------------------- */ #ifndef WIFEXITED -# define WIFEXITED(stat) (((*((int *) &(stat))) & 0xff) == 0) +# define WIFEXITED(stat) (((*((int *) &(stat))) & 0xff) == 0) #endif #ifndef WEXITSTATUS -# define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff) +# define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff) #endif #ifndef WIFSIGNALED -# define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff))) +# define WIFSIGNALED(stat) \ + (((*((int *) &(stat)))) && ((*((int *) &(stat))) \ + == ((*((int *) &(stat))) & 0x00ff))) #endif #ifndef WTERMSIG -# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7f) +# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7f) #endif #ifndef WIFSTOPPED -# define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xff) == 0177) +# define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xff) == 0177) #endif #ifndef WSTOPSIG -# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xff) +# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xff) #endif - + /* - * Define constants for waitpid() system call if they aren't defined - * by a system header file. + *--------------------------------------------------------------------------- + * Define constants for waitpid() system call if they aren't defined by a + * system header file. + *--------------------------------------------------------------------------- */ #ifndef WNOHANG @@ -224,10 +253,12 @@ MODULE_SCOPE int TclUnixSetBlockingMode(int fd, int mode); #ifndef WUNTRACED # define WUNTRACED 2 #endif - + /* - * Supply macros for seek offsets, if they're not already provided by - * an include file. + *--------------------------------------------------------------------------- + * Supply macros for seek offsets, if they're not already provided by an + * include file. + *--------------------------------------------------------------------------- */ #ifndef SEEK_SET @@ -239,10 +270,12 @@ MODULE_SCOPE int TclUnixSetBlockingMode(int fd, int mode); #ifndef SEEK_END # define SEEK_END 2 #endif - + /* - * The stuff below is needed by the "time" command. If this system has no + *--------------------------------------------------------------------------- + * The stuff below is needed by the "time" command. If this system has no * gettimeofday call, then must use times() instead. + *--------------------------------------------------------------------------- */ #ifdef NO_GETTOD @@ -254,39 +287,45 @@ MODULE_SCOPE int TclUnixSetBlockingMode(int fd, int mode); #endif #ifdef GETTOD_NOT_DECLARED -EXTERN int gettimeofday _ANSI_ARGS_((struct timeval *tp, - struct timezone *tzp)); +MODULE_SCOPE int gettimeofday(struct timeval *tp, + struct timezone *tzp); #endif - + /* + *--------------------------------------------------------------------------- * Define access mode constants if they aren't already defined. + *--------------------------------------------------------------------------- */ #ifndef F_OK -# define F_OK 00 +# define F_OK 00 #endif #ifndef X_OK -# define X_OK 01 +# define X_OK 01 #endif #ifndef W_OK -# define W_OK 02 +# define W_OK 02 #endif #ifndef R_OK -# define R_OK 04 +# define R_OK 04 #endif - + /* - * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't - * already defined. + *--------------------------------------------------------------------------- + * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't already + * defined. + *--------------------------------------------------------------------------- */ #ifndef FD_CLOEXEC -# define FD_CLOEXEC 1 +# define FD_CLOEXEC 1 #endif - + /* - * On systems without symbolic links (i.e. S_IFLNK isn't defined) - * define "lstat" to use "stat" instead. + *--------------------------------------------------------------------------- + * On systems without symbolic links (i.e. S_IFLNK isn't defined) define + * "lstat" to use "stat" instead. + *--------------------------------------------------------------------------- */ #ifndef S_IFLNK @@ -295,270 +334,313 @@ EXTERN int gettimeofday _ANSI_ARGS_((struct timeval *tp, # define lstat64 stat64 # define TclOSlstat TclOSstat #endif - + /* - * Define macros to query file type bits, if they're not already - * defined. + *--------------------------------------------------------------------------- + * Define macros to query file type bits, if they're not already defined. + *--------------------------------------------------------------------------- */ #ifndef S_ISREG # ifdef S_IFREG -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) # else -# define S_ISREG(m) 0 +# define S_ISREG(m) 0 # endif #endif /* !S_ISREG */ #ifndef S_ISDIR # ifdef S_IFDIR -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) # else -# define S_ISDIR(m) 0 +# define S_ISDIR(m) 0 # endif #endif /* !S_ISDIR */ #ifndef S_ISCHR # ifdef S_IFCHR -# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) # else -# define S_ISCHR(m) 0 +# define S_ISCHR(m) 0 # endif #endif /* !S_ISCHR */ + #ifndef S_ISBLK # ifdef S_IFBLK -# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) # else -# define S_ISBLK(m) 0 +# define S_ISBLK(m) 0 # endif #endif /* !S_ISBLK */ + #ifndef S_ISFIFO # ifdef S_IFIFO -# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) # else -# define S_ISFIFO(m) 0 +# define S_ISFIFO(m) 0 # endif #endif /* !S_ISFIFO */ + #ifndef S_ISLNK # ifdef S_IFLNK -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) # else -# define S_ISLNK(m) 0 +# define S_ISLNK(m) 0 # endif #endif /* !S_ISLNK */ + #ifndef S_ISSOCK # ifdef S_IFSOCK -# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) +# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) # else -# define S_ISSOCK(m) 0 +# define S_ISSOCK(m) 0 # endif #endif /* !S_ISSOCK */ - + /* + *--------------------------------------------------------------------------- * Make sure that MAXPATHLEN and MAXNAMLEN are defined. + *--------------------------------------------------------------------------- */ #ifndef MAXPATHLEN # ifdef PATH_MAX -# define MAXPATHLEN PATH_MAX +# define MAXPATHLEN PATH_MAX # else -# define MAXPATHLEN 2048 +# define MAXPATHLEN 2048 # endif #endif #ifndef MAXNAMLEN # ifdef NAME_MAX -# define MAXNAMLEN NAME_MAX +# define MAXNAMLEN NAME_MAX # else -# define MAXNAMLEN 255 +# define MAXNAMLEN 255 # endif #endif - + /* + *--------------------------------------------------------------------------- * Make sure that L_tmpnam is defined. + *--------------------------------------------------------------------------- */ #ifndef L_tmpnam -# define L_tmpnam 100 +# define L_tmpnam 100 #endif - + /* - * The following macro defines the type of the mask arguments to - * select: + *--------------------------------------------------------------------------- + * The following macro defines the type of the mask arguments to select: + *--------------------------------------------------------------------------- */ #ifndef NO_FD_SET -# define SELECT_MASK fd_set +# define SELECT_MASK fd_set #else /* NO_FD_SET */ # ifndef _AIX - typedef long fd_mask; + typedef long fd_mask; # endif /* !AIX */ # if defined(_IBMR2) -# define SELECT_MASK void +# define SELECT_MASK void # else /* !defined(_IBMR2) */ -# define SELECT_MASK int +# define SELECT_MASK int # endif /* defined(_IBMR2) */ #endif /* !NO_FD_SET */ - + /* + *--------------------------------------------------------------------------- * Define "NBBY" (number of bits per byte) if it's not already defined. + *--------------------------------------------------------------------------- */ #ifndef NBBY -# define NBBY 8 +# define NBBY 8 #endif - + /* + *--------------------------------------------------------------------------- * The following macro defines the number of fd_masks in an fd_set: + *--------------------------------------------------------------------------- */ #ifndef FD_SETSIZE # ifdef OPEN_MAX -# define FD_SETSIZE OPEN_MAX +# define FD_SETSIZE OPEN_MAX # else -# define FD_SETSIZE 256 +# define FD_SETSIZE 256 # endif #endif /* FD_SETSIZE */ -#if !defined(howmany) -# define howmany(x, y) (((x)+((y)-1))/(y)) + +#ifndef howmany +# define howmany(x, y) (((x)+((y)-1))/(y)) #endif /* !defined(howmany) */ + #ifndef NFDBITS -# define NFDBITS NBBY*sizeof(fd_mask) +# define NFDBITS NBBY*sizeof(fd_mask) #endif /* NFDBITS */ -#define MASK_SIZE howmany(FD_SETSIZE, NFDBITS) +#define MASK_SIZE howmany(FD_SETSIZE, NFDBITS) + /* - * Not all systems declare the errno variable in errno.h. so this - * file does it explicitly. The list of system error messages also - * isn't generally declared in a header file anywhere. + *--------------------------------------------------------------------------- + * Not all systems declare the errno variable in errno.h. so this file does it + * explicitly. The list of system error messages also isn't generally declared + * in a header file anywhere. + *--------------------------------------------------------------------------- */ #ifdef NO_ERRNO extern int errno; #endif /* NO_ERRNO */ - + /* - * Not all systems declare all the errors that Tcl uses! Provide some + *--------------------------------------------------------------------------- + * Not all systems declare all the errors that Tcl uses! Provide some * work-arounds... + *--------------------------------------------------------------------------- */ #ifndef EOVERFLOW # ifdef EFBIG -# define EOVERFLOW EFBIG +# define EOVERFLOW EFBIG # else /* !EFBIG */ -# define EOVERFLOW EINVAL +# define EOVERFLOW EINVAL # endif /* EFBIG */ #endif /* EOVERFLOW */ - + /* + *--------------------------------------------------------------------------- * Variables provided by the C library: + *--------------------------------------------------------------------------- */ #if defined(__APPLE__) && defined(__DYNAMIC__) # include <crt_externs.h> -# define environ (*_NSGetEnviron()) -# define USE_PUTENV 1 +# define environ (*_NSGetEnviron()) +# define USE_PUTENV 1 #else # if defined(_sgi) || defined(__sgi) -# define environ _environ +# define environ _environ # endif -extern char **environ; +extern char ** environ; #endif - -/* - * There is no platform-specific panic routine for Unix in the Tcl internals. - */ - -#define TclpPanic ((Tcl_PanicProc *) NULL) - + /* + *--------------------------------------------------------------------------- * Darwin specifc configure overrides. + *--------------------------------------------------------------------------- */ #ifdef __APPLE__ + /* + *--------------------------------------------------------------------------- * Support for fat compiles: configure runs only once for multiple architectures + *--------------------------------------------------------------------------- */ + # if defined(__LP64__) && defined (NO_COREFOUNDATION_64) -# undef HAVE_COREFOUNDATION -# endif /* __LP64__ && NO_COREFOUNDATION_64 */ +# undef HAVE_COREFOUNDATION +# endif /* __LP64__ && NO_COREFOUNDATION_64 */ # include <sys/cdefs.h> # ifdef __DARWIN_UNIX03 -# if __DARWIN_UNIX03 -# undef HAVE_PUTENV_THAT_COPIES -# else -# define HAVE_PUTENV_THAT_COPIES 1 -# endif +# if __DARWIN_UNIX03 +# undef HAVE_PUTENV_THAT_COPIES +# else +# define HAVE_PUTENV_THAT_COPIES 1 +# endif # endif /* __DARWIN_UNIX03 */ + /* + *--------------------------------------------------------------------------- * The termios configure test program relies on the configure script being run - * from a terminal, which is not the case e.g. when configuring from Xcode. + * from a terminal, which is not the case e.g., when configuring from Xcode. * Since termios is known to be present on all Mac OS X releases since 10.0, * override the configure defines for serial API here. [Bug 497147] + *--------------------------------------------------------------------------- */ + # define USE_TERMIOS 1 -# undef USE_TERMIO -# undef USE_SGTTY +# undef USE_TERMIO +# undef USE_SGTTY + /* + *--------------------------------------------------------------------------- * Include AvailabilityMacros.h here (when available) to ensure any symbolic * MAC_OS_X_VERSION_* constants passed on the command line are translated. + *--------------------------------------------------------------------------- */ + # ifdef HAVE_AVAILABILITYMACROS_H -# include <AvailabilityMacros.h> +# include <AvailabilityMacros.h> # endif + /* + *--------------------------------------------------------------------------- * Support for weak import. + *--------------------------------------------------------------------------- */ + # ifdef HAVE_WEAK_IMPORT -# if !defined(HAVE_AVAILABILITYMACROS_H) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED) -# undef HAVE_WEAK_IMPORT -# else -# ifndef WEAK_IMPORT_ATTRIBUTE -# define WEAK_IMPORT_ATTRIBUTE __attribute__((weak_import)) -# endif -# endif +# if !defined(HAVE_AVAILABILITYMACROS_H) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED) +# undef HAVE_WEAK_IMPORT +# else +# ifndef WEAK_IMPORT_ATTRIBUTE +# define WEAK_IMPORT_ATTRIBUTE __attribute__((weak_import)) +# endif +# endif # endif /* HAVE_WEAK_IMPORT */ + /* + *--------------------------------------------------------------------------- * Support for MAC_OS_X_VERSION_MAX_ALLOWED define from AvailabilityMacros.h: * only use API available in the indicated OS version or earlier. + *--------------------------------------------------------------------------- */ + # ifdef MAC_OS_X_VERSION_MAX_ALLOWED -# if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 && defined(__LP64__) -# undef HAVE_COREFOUNDATION -# endif -# if MAC_OS_X_VERSION_MAX_ALLOWED < 1040 -# undef HAVE_OSSPINLOCKLOCK -# undef HAVE_PTHREAD_ATFORK -# undef HAVE_COPYFILE -# endif -# if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 -# ifdef TCL_THREADS +# if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 && defined(__LP64__) +# undef HAVE_COREFOUNDATION +# endif +# if MAC_OS_X_VERSION_MAX_ALLOWED < 1040 +# undef HAVE_OSSPINLOCKLOCK +# undef HAVE_PTHREAD_ATFORK +# undef HAVE_COPYFILE +# endif +# if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 +# ifdef TCL_THREADS /* prior to 10.3, realpath is not threadsafe, c.f. bug 711232 */ -# define NO_REALPATH 1 -# endif -# undef HAVE_LANGINFO -# endif +# define NO_REALPATH 1 +# endif +# undef HAVE_LANGINFO +# endif # endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ # if defined(HAVE_COREFOUNDATION) && defined(__LP64__) && \ defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -# warning "Weak import of 64-bit CoreFoundation is not supported, will not run on Mac OS X < 10.5." +# warning "Weak import of 64-bit CoreFoundation is not supported, will not run on Mac OS X < 10.5." # endif + /* + *--------------------------------------------------------------------------- * At present, using vfork() instead of fork() causes execve() to fail * intermittently on Darwin x86_64. rdar://4685553 + *--------------------------------------------------------------------------- */ + # if defined(__x86_64__) && !defined(FIXED_RDAR_4685553) -# undef USE_VFORK +# undef USE_VFORK # endif /* __x86_64__ */ /* Workaround problems with vfork() when building with llvm-gcc-4.2 */ # if defined (__llvm__) && \ (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 2 || \ (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 0)))) -# undef USE_VFORK +# undef USE_VFORK # endif /* __llvm__ */ #endif /* __APPLE__ */ - + /* *--------------------------------------------------------------------------- - * The following macros and declarations represent the interface between - * generic and unix-specific parts of Tcl. Some of the macros may override + * The following macros and declarations represent the interface between + * generic and unix-specific parts of Tcl. Some of the macros may override * functions declared in tclInt.h. *--------------------------------------------------------------------------- */ @@ -573,73 +655,72 @@ typedef int socklen_t; #else #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_LF #endif - + /* - * The following macros have trivial definitions, allowing generic code to + *--------------------------------------------------------------------------- + * The following macros have trivial definitions, allowing generic code to * address platform-specific issues. + *--------------------------------------------------------------------------- */ #define TclpGetPid(pid) ((unsigned long) (pid)) #define TclpReleaseFile(file) /* Nothing. */ - + /* + *--------------------------------------------------------------------------- * The following defines wrap the system memory allocation routines. + *--------------------------------------------------------------------------- */ -#define TclpSysAlloc(size, isBin) malloc((size_t)size) -#define TclpSysFree(ptr) free((char*)ptr) -#define TclpSysRealloc(ptr, size) realloc((char*)ptr, (size_t)size) - +#define TclpSysAlloc(size, isBin) malloc((size_t)(size)) +#define TclpSysFree(ptr) free((char *)(ptr)) +#define TclpSysRealloc(ptr, size) realloc((char *)(ptr), (size_t)(size)) + /* - * The following macros and declaration wrap the C runtime library - * functions. + *--------------------------------------------------------------------------- + * The following macros and declaration wrap the C runtime library functions. + *--------------------------------------------------------------------------- */ -#define TclpExit exit +#define TclpExit exit #ifdef TCL_THREADS -EXTERN struct tm * TclpLocaltime(CONST time_t *); -EXTERN struct tm * TclpGmtime(CONST time_t *); -EXTERN char * TclpInetNtoa(struct in_addr); -/* #define localtime(x) TclpLocaltime(x) - * #define gmtime(x) TclpGmtime(x) */ # undef inet_ntoa # define inet_ntoa(x) TclpInetNtoa(x) -# ifdef HAVE_PTHREAD_ATTR_GET_NP -# define TclpPthreadGetAttrs pthread_attr_get_np -# ifdef ATTRGETNP_NOT_DECLARED -/* - * Assume it is in pthread_np.h if it isn't in pthread.h. [Bug 1064882] - * We might need to revisit this in the future. :^( - */ -# include <pthread.h> -# include <pthread_np.h> -# endif -# else -# ifdef HAVE_PTHREAD_GETATTR_NP -# define TclpPthreadGetAttrs pthread_getattr_np -# ifdef GETATTRNP_NOT_DECLARED -EXTERN int pthread_getattr_np _ANSI_ARGS_((pthread_t, pthread_attr_t *)); -# endif -# endif /* HAVE_PTHREAD_GETATTR_NP */ -# endif /* HAVE_PTHREAD_ATTR_GET_NP */ #endif /* TCL_THREADS */ +/* FIXME - Hyper-enormous platform assumption! */ +#ifndef AF_INET6 +# define AF_INET6 10 +#endif + /* - * Set of MT-safe implementations of some - * known-to-be-MT-unsafe library calls. - * Instead of returning pointers to the - * static storage, those return pointers + *--------------------------------------------------------------------------- + * Set of MT-safe implementations of some known-to-be-MT-unsafe library calls. + * Instead of returning pointers to the static storage, those return pointers * to the TSD data. + *--------------------------------------------------------------------------- */ +#include <pwd.h> #include <grp.h> -MODULE_SCOPE struct passwd* TclpGetPwNam(const char *name); -MODULE_SCOPE struct group* TclpGetGrNam(const char *name); -MODULE_SCOPE struct passwd* TclpGetPwUid(uid_t uid); -MODULE_SCOPE struct group* TclpGetGrGid(gid_t gid); -MODULE_SCOPE struct hostent* TclpGetHostByName(const char *name); -MODULE_SCOPE struct hostent* TclpGetHostByAddr(const char *addr, int length, int type); +MODULE_SCOPE struct passwd * TclpGetPwNam(const char *name); +MODULE_SCOPE struct group * TclpGetGrNam(const char *name); +MODULE_SCOPE struct passwd * TclpGetPwUid(uid_t uid); +MODULE_SCOPE struct group * TclpGetGrGid(gid_t gid); +MODULE_SCOPE struct hostent * TclpGetHostByName(const char *name); +MODULE_SCOPE struct hostent * TclpGetHostByAddr(const char *addr, + int length, int type); +MODULE_SCOPE Tcl_Channel TclpMakeTcpClientChannelMode( + ClientData tcpSocket, int mode); #endif /* _TCLUNIXPORT */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index a2b4015..7b5c9e0 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -12,13 +12,152 @@ #include "tclInt.h" /* + * Helper macros to make parts of this file clearer. The macros do exactly + * what they say on the tin. :-) They also only ever refer to their arguments + * once, and so can be used without regard to side effects. + */ + +#define SET_BITS(var, bits) ((var) |= (bits)) +#define CLEAR_BITS(var, bits) ((var) &= ~(bits)) + +/* "sock" + a pointer in hex + \0 */ +#define SOCK_CHAN_LENGTH 4 + sizeof(void*) * 2 + 1 +#define SOCK_TEMPLATE "sock%lx" + +/* + * This is needed to comply with the strict aliasing rules of GCC, but it also + * simplifies casting between the different sockaddr types. + */ + +typedef union { + struct sockaddr sa; + struct sockaddr_in sa4; + struct sockaddr_in6 sa6; + struct sockaddr_storage sas; +} address; + +/* + * This structure describes per-instance state of a tcp based channel. + */ + +typedef struct TcpState TcpState; + +typedef struct TcpFdList { + TcpState *statePtr; + int fd; + struct TcpFdList *next; +} TcpFdList; + +struct TcpState { + Tcl_Channel channel; /* Channel associated with this file. */ + TcpFdList fds; /* The file descriptors of the sockets. */ + int flags; /* ORed combination of the bitfields defined + * below. */ + /* + * Only needed for server sockets + */ + Tcl_TcpAcceptProc *acceptProc; /* Proc to call on accept. */ + ClientData acceptProcData; /* The data for the accept proc. */ + /* + * Only needed for client sockets + */ + struct addrinfo *addrlist; /* addresses to connect to */ + struct addrinfo *addr; /* iterator over addrlist */ + struct addrinfo *myaddrlist; /* local address */ + struct addrinfo *myaddr; /* iterator over myaddrlist */ + int filehandlers; /* Caches FileHandlers that get set up while + * an async socket is not yet connected */ + int status; /* Cache status of async socket */ + int cachedBlocking; /* Cache blocking mode of async socket */ +}; + +/* + * These bits may be ORed together into the "flags" field of a TcpState + * structure. + */ + +#define TCP_ASYNC_SOCKET (1<<0) /* Asynchronous socket. */ +#define TCP_ASYNC_CONNECT (1<<1) /* Async connect in progress. */ + +/* + * The following defines the maximum length of the listen queue. This is the + * number of outstanding yet-to-be-serviced requests for a connection on a + * server socket, more than this number of outstanding requests and the + * connection request will fail. + */ + +#ifndef SOMAXCONN +# define SOMAXCONN 100 +#endif /* SOMAXCONN */ + +#if (SOMAXCONN < 100) +# undef SOMAXCONN +# define SOMAXCONN 100 +#endif /* SOMAXCONN < 100 */ + +/* + * The following defines how much buffer space the kernel should maintain for + * a socket. + */ + +#define SOCKET_BUFSIZE 4096 + +/* + * Static routines for this file: + */ + +static int CreateClientSocket(Tcl_Interp *interp, + TcpState *state); +static void TcpAccept(ClientData data, int mask); +static int TcpBlockModeProc(ClientData data, int mode); +static int TcpCloseProc(ClientData instanceData, + Tcl_Interp *interp); +static int TcpClose2Proc(ClientData instanceData, + Tcl_Interp *interp, int flags); +static int TcpGetHandleProc(ClientData instanceData, + int direction, ClientData *handlePtr); +static int TcpGetOptionProc(ClientData instanceData, + Tcl_Interp *interp, const char *optionName, + Tcl_DString *dsPtr); +static int TcpInputProc(ClientData instanceData, char *buf, + int toRead, int *errorCode); +static int TcpOutputProc(ClientData instanceData, + const char *buf, int toWrite, int *errorCode); +static void TcpWatchProc(ClientData instanceData, int mask); +static int WaitForConnect(TcpState *statePtr, int *errorCodePtr); + +/* + * This structure describes the channel type structure for TCP socket + * based IO: + */ + +static const Tcl_ChannelType tcpChannelType = { + "tcp", /* Type name. */ + TCL_CHANNEL_VERSION_5, /* v5 channel */ + TcpCloseProc, /* Close proc. */ + TcpInputProc, /* Input proc. */ + TcpOutputProc, /* Output proc. */ + NULL, /* Seek proc. */ + NULL, /* Set option proc. */ + TcpGetOptionProc, /* Get option proc. */ + TcpWatchProc, /* Initialize notifier. */ + TcpGetHandleProc, /* Get OS handles out of channel. */ + TcpClose2Proc, /* Close2 proc. */ + TcpBlockModeProc, /* Set blocking or non-blocking mode.*/ + NULL, /* flush proc. */ + NULL, /* handler proc. */ + NULL, /* wide seek proc. */ + NULL, /* thread action proc. */ + NULL /* truncate proc. */ +}; + +/* * The following variable holds the network name of this host. */ static TclInitProcessGlobalValueProc InitializeHostName; static ProcessGlobalValue hostName = {0, 0, NULL, NULL, InitializeHostName, NULL, NULL}; - /* *---------------------------------------------------------------------- @@ -40,7 +179,7 @@ InitializeHostName( int *lengthPtr, Tcl_Encoding *encodingPtr) { - CONST char *native = NULL; + const char *native = NULL; #ifndef NO_UNAME struct utsname u; @@ -59,7 +198,7 @@ InitializeHostName( char *dot = strchr(u.nodename, '.'); if (dot != NULL) { - char *node = ckalloc((unsigned) (dot - u.nodename + 1)); + char *node = ckalloc(dot - u.nodename + 1); memcpy(node, u.nodename, (size_t) (dot - u.nodename)); node[dot - u.nodename] = '\0'; @@ -92,7 +231,7 @@ InitializeHostName( * Fix suggested by Viktor Dukhovni (viktor@esm.com) */ -# if defined(SYS_NMLN) && SYS_NMLEN >= 256 +# if defined(SYS_NMLN) && (SYS_NMLEN >= 256) char buffer[SYS_NMLEN]; # else char buffer[256]; @@ -105,8 +244,8 @@ InitializeHostName( *encodingPtr = Tcl_GetEncoding(NULL, NULL); *lengthPtr = strlen(native); - *valuePtr = ckalloc((unsigned int) (*lengthPtr)+1); - memcpy(*valuePtr, (void *) native, (size_t)(*lengthPtr)+1); + *valuePtr = ckalloc((*lengthPtr) + 1); + memcpy(*valuePtr, native, (size_t)(*lengthPtr)+1); } /* @@ -127,7 +266,7 @@ InitializeHostName( *---------------------------------------------------------------------- */ -CONST char * +const char * Tcl_GetHostName(void) { return Tcl_GetString(TclGetProcessGlobalValue(&hostName)); @@ -179,9 +318,1136 @@ TclpFinalizeSockets(void) } /* + *---------------------------------------------------------------------- + * + * TcpBlockModeProc -- + * + * This function is invoked by the generic IO level to set blocking and + * nonblocking mode on a TCP socket based channel. + * + * Results: + * 0 if successful, errno when failed. + * + * Side effects: + * Sets the device into blocking or nonblocking mode. + * + *---------------------------------------------------------------------- + */ + + /* ARGSUSED */ +static int +TcpBlockModeProc( + ClientData instanceData, /* Socket state. */ + int mode) /* The mode to set. Can be one of + * TCL_MODE_BLOCKING or + * TCL_MODE_NONBLOCKING. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + + if (mode == TCL_MODE_BLOCKING) { + CLEAR_BITS(statePtr->flags, TCP_ASYNC_SOCKET); + } else { + SET_BITS(statePtr->flags, TCP_ASYNC_SOCKET); + } + if (statePtr->flags & TCP_ASYNC_CONNECT) { + statePtr->cachedBlocking = mode; + return 0; + } + if (TclUnixSetBlockingMode(statePtr->fds.fd, mode) < 0) { + return errno; + } + return 0; +} + +/* + *---------------------------------------------------------------------- + * + * WaitForConnect -- + * + * Wait for a connection on an asynchronously opened socket to be + * completed. In nonblocking mode, just test if the connection + * has completed without blocking. + * + * Results: + * 0 if the connection has completed, -1 if still in progress + * or there is an error. + * + *---------------------------------------------------------------------- + */ + +static int +WaitForConnect( + TcpState *statePtr, /* State of the socket. */ + int *errorCodePtr) /* Where to store errors? */ +{ + int timeOut; /* How long to wait. */ + int state; /* Of calling TclWaitForFile. */ + + /* + * If an asynchronous connect is in progress, attempt to wait for it to + * complete before reading. + */ + + if (statePtr->flags & TCP_ASYNC_CONNECT) { + if (statePtr->flags & TCP_ASYNC_SOCKET) { + timeOut = 0; + } else { + timeOut = -1; + } + errno = 0; + state = TclUnixWaitForFile(statePtr->fds.fd, + TCL_WRITABLE | TCL_EXCEPTION, timeOut); + if (state & TCL_EXCEPTION) { + return -1; + } + if (state & TCL_WRITABLE) { + CLEAR_BITS(statePtr->flags, TCP_ASYNC_CONNECT); + } else if (timeOut == 0) { + *errorCodePtr = errno = EWOULDBLOCK; + return -1; + } + } + return 0; +} + +/* + *---------------------------------------------------------------------- + * + * TcpInputProc -- + * + * This function is invoked by the generic IO level to read input from a + * TCP socket based channel. + * + * NOTE: We cannot share code with FilePipeInputProc because here we must + * use recv to obtain the input from the channel, not read. + * + * Results: + * The number of bytes read is returned or -1 on error. An output + * argument contains the POSIX error code on error, or zero if no error + * occurred. + * + * Side effects: + * Reads input from the input device of the channel. + * + *---------------------------------------------------------------------- + */ + + /* ARGSUSED */ +static int +TcpInputProc( + ClientData instanceData, /* Socket state. */ + char *buf, /* Where to store data read. */ + int bufSize, /* How much space is available in the + * buffer? */ + int *errorCodePtr) /* Where to store error code. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + int bytesRead; + + *errorCodePtr = 0; + if (WaitForConnect(statePtr, errorCodePtr) != 0) { + return -1; + } + bytesRead = recv(statePtr->fds.fd, buf, (size_t) bufSize, 0); + if (bytesRead > -1) { + return bytesRead; + } + if (errno == ECONNRESET) { + /* + * Turn ECONNRESET into a soft EOF condition. + */ + + return 0; + } + *errorCodePtr = errno; + return -1; +} + +/* + *---------------------------------------------------------------------- + * + * TcpOutputProc -- + * + * This function is invoked by the generic IO level to write output to a + * TCP socket based channel. + * + * NOTE: We cannot share code with FilePipeOutputProc because here we + * must use send, not write, to get reliable error reporting. + * + * Results: + * The number of bytes written is returned. An output argument is set to + * a POSIX error code if an error occurred, or zero. + * + * Side effects: + * Writes output on the output device of the channel. + * + *---------------------------------------------------------------------- + */ + +static int +TcpOutputProc( + ClientData instanceData, /* Socket state. */ + const char *buf, /* The data buffer. */ + int toWrite, /* How many bytes to write? */ + int *errorCodePtr) /* Where to store error code. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + int written; + + *errorCodePtr = 0; + if (WaitForConnect(statePtr, errorCodePtr) != 0) { + return -1; + } + written = send(statePtr->fds.fd, buf, (size_t) toWrite, 0); + if (written > -1) { + return written; + } + *errorCodePtr = errno; + return -1; +} + +/* + *---------------------------------------------------------------------- + * + * TcpCloseProc -- + * + * This function is invoked by the generic IO level to perform + * channel-type-specific cleanup when a TCP socket based channel is + * closed. + * + * Results: + * 0 if successful, the value of errno if failed. + * + * Side effects: + * Closes the socket of the channel. + * + *---------------------------------------------------------------------- + */ + + /* ARGSUSED */ +static int +TcpCloseProc( + ClientData instanceData, /* The socket to close. */ + Tcl_Interp *interp) /* For error reporting - unused. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + int errorCode = 0; + TcpFdList *fds; + + /* + * Delete a file handler that may be active for this socket if this is a + * server socket - the file handler was created automatically by Tcl as + * part of the mechanism to accept new client connections. Channel + * handlers are already deleted in the generic IO channel closing code + * that called this function, so we do not have to delete them here. + */ + + for (fds = &statePtr->fds; fds != NULL; fds = fds->next) { + Tcl_DeleteFileHandler(fds->fd); + if (close(fds->fd) < 0) { + errorCode = errno; + } + + } + fds = statePtr->fds.next; + while (fds != NULL) { + TcpFdList *next = fds->next; + ckfree(fds); + fds = next; + } + if (statePtr->addrlist != NULL) { + freeaddrinfo(statePtr->addrlist); + } + if (statePtr->myaddrlist != NULL) { + freeaddrinfo(statePtr->myaddrlist); + } + ckfree(statePtr); + return errorCode; +} + +/* + *---------------------------------------------------------------------- + * + * TcpClose2Proc -- + * + * This function is called by the generic IO level to perform the channel + * type specific part of a half-close: namely, a shutdown() on a socket. + * + * Results: + * 0 if successful, the value of errno if failed. + * + * Side effects: + * Shuts down one side of the socket. + * + *---------------------------------------------------------------------- + */ + +static int +TcpClose2Proc( + ClientData instanceData, /* The socket to close. */ + Tcl_Interp *interp, /* For error reporting. */ + int flags) /* Flags that indicate which side to close. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + int errorCode = 0; + int sd; + + /* + * Shutdown the OS socket handle. + */ + + switch(flags) { + case TCL_CLOSE_READ: + sd = SHUT_RD; + break; + case TCL_CLOSE_WRITE: + sd = SHUT_WR; + break; + default: + if (interp) { + Tcl_AppendResult(interp, + "Socket close2proc called bidirectionally", NULL); + } + return TCL_ERROR; + } + if (shutdown(statePtr->fds.fd,sd) < 0) { + errorCode = errno; + } + + return errorCode; +} + +/* + *---------------------------------------------------------------------- + * + * TcpGetOptionProc -- + * + * Computes an option value for a TCP socket based channel, or a list of + * all options and their values. + * + * Note: This code is based on code contributed by John Haxby. + * + * Results: + * A standard Tcl result. The value of the specified option or a list of + * all options and their values is returned in the supplied DString. Sets + * Error message if needed. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static int +TcpGetOptionProc( + ClientData instanceData, /* Socket state. */ + Tcl_Interp *interp, /* For error reporting - can be NULL. */ + const char *optionName, /* Name of the option to retrieve the value + * for, or NULL to get all options and their + * values. */ + Tcl_DString *dsPtr) /* Where to store the computed value; + * initialized by caller. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + char host[NI_MAXHOST], port[NI_MAXSERV]; + size_t len = 0; + int reverseDNS = 0; +#define SUPPRESS_RDNS_VAR "::tcl::unsupported::noReverseDNS" + + if (optionName != NULL) { + len = strlen(optionName); + } + + if ((len > 1) && (optionName[1] == 'e') && + (strncmp(optionName, "-error", len) == 0)) { + socklen_t optlen = sizeof(int); + int err, ret; + + if (statePtr->status == 0) { + ret = getsockopt(statePtr->fds.fd, SOL_SOCKET, SO_ERROR, + (char *)&err, &optlen); + if (ret < 0) { + err = errno; + } + } else { + err = statePtr->status; + statePtr->status = 0; + } + if (err != 0) { + Tcl_DStringAppend(dsPtr, Tcl_ErrnoMsg(err), -1); + } + return TCL_OK; + } + + if (interp != NULL && Tcl_GetVar(interp, SUPPRESS_RDNS_VAR, 0) != NULL) { + reverseDNS = NI_NUMERICHOST; + } + + if ((len == 0) || + ((len > 1) && (optionName[1] == 'p') && + (strncmp(optionName, "-peername", len) == 0))) { + address peername; + socklen_t size = sizeof(peername); + + if (getpeername(statePtr->fds.fd, &peername.sa, &size) >= 0) { + if (len == 0) { + Tcl_DStringAppendElement(dsPtr, "-peername"); + Tcl_DStringStartSublist(dsPtr); + } + + getnameinfo(&peername.sa, size, host, sizeof(host), NULL, 0, + NI_NUMERICHOST); + Tcl_DStringAppendElement(dsPtr, host); + getnameinfo(&peername.sa, size, host, sizeof(host), port, + sizeof(port), reverseDNS | NI_NUMERICSERV); + Tcl_DStringAppendElement(dsPtr, host); + Tcl_DStringAppendElement(dsPtr, port); + if (len) { + return TCL_OK; + } + Tcl_DStringEndSublist(dsPtr); + } else { + /* + * getpeername failed - but if we were asked for all the options + * (len==0), don't flag an error at that point because it could be + * an fconfigure request on a server socket (which have no peer). + * Same must be done on win&mac. + */ + + if (len) { + if (interp) { + Tcl_AppendResult(interp, "can't get peername: ", + Tcl_PosixError(interp), NULL); + } + return TCL_ERROR; + } + } + } + + if ((len == 0) || + ((len > 1) && (optionName[1] == 's') && + (strncmp(optionName, "-sockname", len) == 0))) { + TcpFdList *fds; + address sockname; + socklen_t size; + int found = 0; + + if (len == 0) { + Tcl_DStringAppendElement(dsPtr, "-sockname"); + Tcl_DStringStartSublist(dsPtr); + } + for (fds = &statePtr->fds; fds != NULL; fds = fds->next) { + size = sizeof(sockname); + if (getsockname(fds->fd, &(sockname.sa), &size) >= 0) { + int flags = reverseDNS; + + found = 1; + getnameinfo(&sockname.sa, size, host, sizeof(host), NULL, 0, + NI_NUMERICHOST); + Tcl_DStringAppendElement(dsPtr, host); + + /* + * We don't want to resolve INADDR_ANY and sin6addr_any; they + * can sometimes cause problems (and never have a name). + */ + + flags |= NI_NUMERICSERV; + if (sockname.sa.sa_family == AF_INET) { + if (sockname.sa4.sin_addr.s_addr == INADDR_ANY) { + flags |= NI_NUMERICHOST; + } +#ifndef NEED_FAKE_RFC2553 + } else if (sockname.sa.sa_family == AF_INET6) { + if ((IN6_ARE_ADDR_EQUAL(&sockname.sa6.sin6_addr, + &in6addr_any)) + || (IN6_IS_ADDR_V4MAPPED(&sockname.sa6.sin6_addr) && + sockname.sa6.sin6_addr.s6_addr[12] == 0 && + sockname.sa6.sin6_addr.s6_addr[13] == 0 && + sockname.sa6.sin6_addr.s6_addr[14] == 0 && + sockname.sa6.sin6_addr.s6_addr[15] == 0)) { + flags |= NI_NUMERICHOST; + } +#endif + } + getnameinfo(&sockname.sa, size, host, sizeof(host), port, + sizeof(port), flags); + Tcl_DStringAppendElement(dsPtr, host); + Tcl_DStringAppendElement(dsPtr, port); + } + } + if (found) { + if (len) { + return TCL_OK; + } + Tcl_DStringEndSublist(dsPtr); + } else { + if (interp) { + Tcl_AppendResult(interp, "can't get sockname: ", + Tcl_PosixError(interp), NULL); + } + return TCL_ERROR; + } + } + + if (len > 0) { + return Tcl_BadChannelOption(interp, optionName, "peername sockname"); + } + + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * TcpWatchProc -- + * + * Initialize the notifier to watch the fd from this channel. + * + * Results: + * None. + * + * Side effects: + * Sets up the notifier so that a future event on the channel will be + * seen by Tcl. + * + *---------------------------------------------------------------------- + */ + +static void +TcpWatchProc( + ClientData instanceData, /* The socket state. */ + int mask) /* Events of interest; an OR-ed combination of + * TCL_READABLE, TCL_WRITABLE and + * TCL_EXCEPTION. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + + if (statePtr->acceptProc != NULL) { + /* + * Make sure we don't mess with server sockets since they will never + * be readable or writable at the Tcl level. This keeps Tcl scripts + * from interfering with the -accept behavior (bug #3394732). + */ + return; + } + + if (statePtr->flags & TCP_ASYNC_CONNECT) { + /* Async sockets use a FileHandler internally while connecting, so we + * need to cache this request until the connection has succeeded. */ + statePtr->filehandlers = mask; + } else if (mask) { + Tcl_CreateFileHandler(statePtr->fds.fd, mask, + (Tcl_FileProc *) Tcl_NotifyChannel, + (ClientData) statePtr->channel); + } else { + Tcl_DeleteFileHandler(statePtr->fds.fd); + } +} + +/* + *---------------------------------------------------------------------- + * + * TcpGetHandleProc -- + * + * Called from Tcl_GetChannelHandle to retrieve OS handles from inside a + * TCP socket based channel. + * + * Results: + * Returns TCL_OK with the fd in handlePtr, or TCL_ERROR if there is no + * handle for the specified direction. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + /* ARGSUSED */ +static int +TcpGetHandleProc( + ClientData instanceData, /* The socket state. */ + int direction, /* Not used. */ + ClientData *handlePtr) /* Where to store the handle. */ +{ + TcpState *statePtr = (TcpState *) instanceData; + + *handlePtr = INT2PTR(statePtr->fds.fd); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * TcpAsyncCallback -- + * + * Called by the event handler that CreateClientSocket sets up + * internally for [socket -async] to get notified when the + * asyncronous connection attempt has succeeded or failed. + * + *---------------------------------------------------------------------- + */ +static void +TcpAsyncCallback( + ClientData clientData, /* The socket state. */ + int mask) /* Events of interest; an OR-ed combination of + * TCL_READABLE, TCL_WRITABLE and + * TCL_EXCEPTION. */ +{ + CreateClientSocket(NULL, clientData); +} + +/* + *---------------------------------------------------------------------- + * + * CreateClientSocket -- + * + * This function opens a new socket in client mode. + * + * Results: + * TCL_OK, if the socket was successfully connected or an asynchronous + * connection is in progress. If an error occurs, TCL_ERROR is returned + * and an error message is left in interp. + * + * Side effects: + * Opens a socket. + * + * Remarks: + * A single host name may resolve to more than one IP address, e.g. for + * an IPv4/IPv6 dual stack host. For handling asyncronously connecting + * sockets in the background for such hosts, this function can act as a + * coroutine. On the first call, it sets up the control variables for the + * two nested loops over the local and remote addresses. Once the first + * connection attempt is in progress, it sets up itself as a writable + * event handler for that socket, and returns. When the callback occurs, + * control is transferred to the "reenter" label, right after the initial + * return and the loops resume as if they had never been interrupted. + * For syncronously connecting sockets, the loops work the usual way. + * + *---------------------------------------------------------------------- + */ + +static int +CreateClientSocket( + Tcl_Interp *interp, /* For error reporting; can be NULL. */ + TcpState *state) +{ + socklen_t optlen; + int async_callback = (state->addr != NULL); + int status; + int async = state->flags & TCP_ASYNC_CONNECT; + + if (async_callback) { + goto reenter; + } + + for (state->addr = state->addrlist; state->addr != NULL; + state->addr = state->addr->ai_next) { + + status = -1; + + for (state->myaddr = state->myaddrlist; state->myaddr != NULL; + state->myaddr = state->myaddr->ai_next) { + int reuseaddr; + + /* + * No need to try combinations of local and remote addresses of + * different families. + */ + + if (state->myaddr->ai_family != state->addr->ai_family) { + continue; + } + + /* + * Close the socket if it is still open from the last unsuccessful + * iteration. + */ + if (state->fds.fd >= 0) { + close(state->fds.fd); + state->fds.fd = -1; + } + + state->fds.fd = socket(state->addr->ai_family, SOCK_STREAM, 0); + if (state->fds.fd < 0) { + continue; + } + + /* + * Set the close-on-exec flag so that the socket will not get + * inherited by child processes. + */ + + fcntl(state->fds.fd, F_SETFD, FD_CLOEXEC); + + /* + * Set kernel space buffering + */ + + TclSockMinimumBuffers(INT2PTR(state->fds.fd), SOCKET_BUFSIZE); + + if (async) { + status = TclUnixSetBlockingMode(state->fds.fd, TCL_MODE_NONBLOCKING); + if (status < 0) { + continue; + } + } + + reuseaddr = 1; + (void) setsockopt(state->fds.fd, SOL_SOCKET, SO_REUSEADDR, + (char *) &reuseaddr, sizeof(reuseaddr)); + status = bind(state->fds.fd, state->myaddr->ai_addr, + state->myaddr->ai_addrlen); + if (status < 0) { + continue; + } + + /* + * Attempt to connect. The connect may fail at present with an + * EINPROGRESS but at a later time it will complete. The caller + * will set up a file handler on the socket if she is interested + * in being informed when the connect completes. + */ + + status = connect(state->fds.fd, state->addr->ai_addr, + state->addr->ai_addrlen); + if (status < 0 && errno == EINPROGRESS) { + Tcl_CreateFileHandler(state->fds.fd, + TCL_WRITABLE | TCL_EXCEPTION, + TcpAsyncCallback, state); + return TCL_OK; + + reenter: + Tcl_DeleteFileHandler(state->fds.fd); + /* + * Read the error state from the socket to see if the async + * connection has succeeded or failed. As this clears the + * error condition, we cache the status in the socket state + * struct for later retrieval by [fconfigure -error]. + */ + optlen = sizeof(int); + getsockopt(state->fds.fd, SOL_SOCKET, SO_ERROR, + (char *)&status, &optlen); + state->status = status; + } + if (status == 0) { + goto out; + } + } + } + +out: + + if (async_callback) { + /* + * An asynchonous connection has finally succeeded or failed. + */ + CLEAR_BITS(state->flags, TCP_ASYNC_CONNECT); + TcpWatchProc(state, state->filehandlers); + TclUnixSetBlockingMode(state->fds.fd, state->cachedBlocking); + + /* + * We need to forward the writable event that brought us here, bcasue + * upon reading of getsockopt(SO_ERROR), at least some OSes clear the + * writable state from the socket, and so a subsequent select() on + * behalf of a script level [fileevent] would not fire. It doesn't + * hurt that this is also called in the successful case and will save + * the event mechanism one roundtrip through select(). + */ + Tcl_NotifyChannel(state->channel, TCL_WRITABLE); + + } else if (status != 0) { + /* + * Failure for either a synchronous connection, or an async one that + * failed before it could enter background mode, e.g. because an + * invalid -myaddr was given. + */ + if (interp != NULL) { + Tcl_AppendResult(interp, "couldn't open socket: ", + Tcl_PosixError(interp), NULL); + } + return TCL_ERROR; + } + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Tcl_OpenTcpClient -- + * + * Opens a TCP client socket and creates a channel around it. + * + * Results: + * The channel or NULL if failed. An error message is returned in the + * interpreter on failure. + * + * Side effects: + * Opens a client socket and creates a new channel. + * + *---------------------------------------------------------------------- + */ + +Tcl_Channel +Tcl_OpenTcpClient( + Tcl_Interp *interp, /* For error reporting; can be NULL. */ + int port, /* Port number to open. */ + const char *host, /* Host on which to open port. */ + const char *myaddr, /* Client-side address */ + int myport, /* Client-side port */ + int async) /* If nonzero, attempt to do an asynchronous + * connect. Otherwise we do a blocking + * connect. */ +{ + TcpState *state; + const char *errorMsg = NULL; + struct addrinfo *addrlist = NULL, *myaddrlist = NULL; + char channelName[SOCK_CHAN_LENGTH]; + + /* + * Do the name lookups for the local and remote addresses. + */ + if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg) || + !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1, &errorMsg)) { + if (addrlist != NULL) { + freeaddrinfo(addrlist); + } + if (interp != NULL) { + Tcl_AppendResult(interp, "couldn't open socket: ", + Tcl_PosixError(interp), NULL); + if (errorMsg != NULL) { + Tcl_AppendResult(interp, " (", errorMsg, ")", NULL); + } + } + return NULL; + } + + /* + * Allocate a new TcpState for this socket. + */ + state = ckalloc(sizeof(TcpState)); + memset(state, 0, sizeof(TcpState)); + state->flags = async ? TCP_ASYNC_CONNECT : 0; + state->cachedBlocking = TCL_MODE_BLOCKING; + state->addrlist = addrlist; + state->myaddrlist = myaddrlist; + state->fds.fd = -1; + + /* + * Create a new client socket and wrap it in a channel. + */ + if (CreateClientSocket(interp, state) != TCL_OK) { + TcpCloseProc(state, NULL); + return NULL; + } + + sprintf(channelName, SOCK_TEMPLATE, (long)state); + + state->channel = Tcl_CreateChannel(&tcpChannelType, channelName, + state, (TCL_READABLE | TCL_WRITABLE)); + if (Tcl_SetChannelOption(interp, state->channel, "-translation", + "auto crlf") == TCL_ERROR) { + Tcl_Close(NULL, state->channel); + return NULL; + } + return state->channel; +} + +/* + *---------------------------------------------------------------------- + * + * Tcl_MakeTcpClientChannel -- + * + * Creates a Tcl_Channel from an existing client TCP socket. + * + * Results: + * The Tcl_Channel wrapped around the preexisting TCP socket. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +Tcl_Channel +Tcl_MakeTcpClientChannel( + ClientData sock) /* The socket to wrap up into a channel. */ +{ + return TclpMakeTcpClientChannelMode(sock, (TCL_READABLE | TCL_WRITABLE)); +} + +/* + *---------------------------------------------------------------------- + * + * TclpMakeTcpClientChannelMode -- + * + * Creates a Tcl_Channel from an existing client TCP socket + * with given mode. + * + * Results: + * The Tcl_Channel wrapped around the preexisting TCP socket. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +Tcl_Channel +TclpMakeTcpClientChannelMode( + ClientData sock, /* The socket to wrap up into a channel. */ + int mode) /* ORed combination of TCL_READABLE and + * TCL_WRITABLE to indicate file mode. */ +{ + TcpState *statePtr; + char channelName[SOCK_CHAN_LENGTH]; + + statePtr = ckalloc(sizeof(TcpState)); + memset(statePtr, 0, sizeof(TcpState)); + statePtr->fds.fd = PTR2INT(sock); + statePtr->flags = 0; + + sprintf(channelName, SOCK_TEMPLATE, (long)statePtr); + + statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, + statePtr, mode); + if (Tcl_SetChannelOption(NULL, statePtr->channel, "-translation", + "auto crlf") == TCL_ERROR) { + Tcl_Close(NULL, statePtr->channel); + return NULL; + } + return statePtr->channel; +} + +/* + *---------------------------------------------------------------------- + * + * Tcl_OpenTcpServer -- + * + * Opens a TCP server socket and creates a channel around it. + * + * Results: + * The channel or NULL if failed. If an error occurred, an error message + * is left in the interp's result if interp is not NULL. + * + * Side effects: + * Opens a server socket and creates a new channel. + * + *---------------------------------------------------------------------- + */ + +Tcl_Channel +Tcl_OpenTcpServer( + Tcl_Interp *interp, /* For error reporting - may be NULL. */ + int port, /* Port number to open. */ + const char *myHost, /* Name of local host. */ + Tcl_TcpAcceptProc *acceptProc, + /* Callback for accepting connections from new + * clients. */ + ClientData acceptProcData) /* Data for the callback. */ +{ + int status = 0, sock = -1, reuseaddr = 1, chosenport = 0; + struct addrinfo *addrlist = NULL, *addrPtr; /* socket address */ + TcpState *statePtr = NULL; + char channelName[SOCK_CHAN_LENGTH]; + const char *errorMsg = NULL; + TcpFdList *fds = NULL, *newfds; + + if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) { + goto error; + } + + for (addrPtr = addrlist; addrPtr != NULL; addrPtr = addrPtr->ai_next) { + sock = socket(addrPtr->ai_family, SOCK_STREAM, 0); + if (sock == -1) { + continue; + } + + /* + * Set the close-on-exec flag so that the socket will not get + * inherited by child processes. + */ + + fcntl(sock, F_SETFD, FD_CLOEXEC); + + /* + * Set kernel space buffering + */ + + TclSockMinimumBuffers(INT2PTR(sock), SOCKET_BUFSIZE); + + /* + * Set up to reuse server addresses automatically and bind to the + * specified port. + */ + + (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + (char *) &reuseaddr, sizeof(reuseaddr)); + + /* + * Make sure we use the same port number when opening two server + * sockets for IPv4 and IPv6 on a random port. + * + * As sockaddr_in6 uses the same offset and size for the port member + * as sockaddr_in, we can handle both through the IPv4 API. + */ + + if (port == 0 && chosenport != 0) { + ((struct sockaddr_in *) addrPtr->ai_addr)->sin_port = + htons(chosenport); + } + +#ifdef IPV6_V6ONLY + /* Missing on: Solaris 2.8 */ + if (addrPtr->ai_family == AF_INET6) { + int v6only = 1; + + (void) setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, + &v6only, sizeof(v6only)); + } +#endif + + status = bind(sock, addrPtr->ai_addr, addrPtr->ai_addrlen); + if (status == -1) { + close(sock); + continue; + } + if (port == 0 && chosenport == 0) { + address sockname; + socklen_t namelen = sizeof(sockname); + + /* + * Synchronize port numbers when binding to port 0 of multiple + * addresses. + */ + + if (getsockname(sock, &sockname.sa, &namelen) >= 0) { + chosenport = ntohs(sockname.sa4.sin_port); + } + } + status = listen(sock, SOMAXCONN); + if (status < 0) { + close(sock); + continue; + } + if (statePtr == NULL) { + /* + * Allocate a new TcpState for this socket. + */ + + statePtr = ckalloc(sizeof(TcpState)); + memset(statePtr, 0, sizeof(TcpState)); + statePtr->acceptProc = acceptProc; + statePtr->acceptProcData = acceptProcData; + sprintf(channelName, SOCK_TEMPLATE, (long)statePtr); + newfds = &statePtr->fds; + } else { + newfds = ckalloc(sizeof(TcpFdList)); + memset(newfds, (int) 0, sizeof(TcpFdList)); + fds->next = newfds; + } + newfds->fd = sock; + newfds->statePtr = statePtr; + fds = newfds; + + /* + * Set up the callback mechanism for accepting connections from new + * clients. + */ + + Tcl_CreateFileHandler(sock, TCL_READABLE, TcpAccept, fds); + } + + error: + if (addrlist != NULL) { + freeaddrinfo(addrlist); + } + if (statePtr != NULL) { + statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, + statePtr, 0); + return statePtr->channel; + } + if (interp != NULL) { + Tcl_AppendResult(interp, "couldn't open socket: ", + Tcl_PosixError(interp), NULL); + if (errorMsg != NULL) { + Tcl_AppendResult(interp, " (", errorMsg, ")", NULL); + } + } + if (sock != -1) { + close(sock); + } + return NULL; +} + +/* + *---------------------------------------------------------------------- + * + * TcpAccept -- + * Accept a TCP socket connection. This is called by the event loop. + * + * Results: + * None. + * + * Side effects: + * Creates a new connection socket. Calls the registered callback for the + * connection acceptance mechanism. + * + *---------------------------------------------------------------------- + */ + + /* ARGSUSED */ +static void +TcpAccept( + ClientData data, /* Callback token. */ + int mask) /* Not used. */ +{ + TcpFdList *fds = data; /* Client data of server socket. */ + int newsock; /* The new client socket */ + TcpState *newSockState; /* State for new socket. */ + address addr; /* The remote address */ + socklen_t len; /* For accept interface */ + char channelName[SOCK_CHAN_LENGTH]; + char host[NI_MAXHOST], port[NI_MAXSERV]; + + len = sizeof(addr); + newsock = accept(fds->fd, &(addr.sa), &len); + if (newsock < 0) { + return; + } + + /* + * Set close-on-exec flag to prevent the newly accepted socket from being + * inherited by child processes. + */ + + (void) fcntl(newsock, F_SETFD, FD_CLOEXEC); + + newSockState = ckalloc(sizeof(TcpState)); + memset(newSockState, 0, sizeof(TcpState)); + newSockState->flags = 0; + newSockState->fds.fd = newsock; + + sprintf(channelName, SOCK_TEMPLATE, (long)newSockState); + newSockState->channel = Tcl_CreateChannel(&tcpChannelType, channelName, + newSockState, (TCL_READABLE | TCL_WRITABLE)); + + Tcl_SetChannelOption(NULL, newSockState->channel, "-translation", + "auto crlf"); + + if (fds->statePtr->acceptProc != NULL) { + getnameinfo(&(addr.sa), len, host, sizeof(host), port, sizeof(port), + NI_NUMERICHOST|NI_NUMERICSERV); + fds->statePtr->acceptProc(fds->statePtr->acceptProcData, + newSockState->channel, host, atoi(port)); + } +} + +/* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 + * tab-width: 8 + * indent-tabs-mode: nil * End: */ diff --git a/unix/tclUnixTest.c b/unix/tclUnixTest.c index b6529c2..0d79e47 100644 --- a/unix/tclUnixTest.c +++ b/unix/tclUnixTest.c @@ -6,10 +6,13 @@ * Copyright (c) 1996-1997 Sun Microsystems, Inc. * Copyright (c) 1998 by Scriptics Corporation. * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#ifndef USE_TCL_STUBS +# define USE_TCL_STUBS +#endif #include "tclInt.h" /* @@ -53,33 +56,23 @@ static Pipe testPipes[MAX_PIPES]; * The stuff below is used by the testalarm and testgotsig ommands. */ -static char *gotsig = "0"; +static const char *gotsig = "0"; /* * Forward declarations of functions defined later in this file: */ -static void TestFileHandlerProc(ClientData clientData, int mask); -static int TestfilehandlerCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -static int TestfilewaitCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -static int TestfindexecutableCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -static int TestgetopenfileCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -static int TestgetdefencdirCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -static int TestsetdefencdirCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -int TclplatformtestInit(Tcl_Interp *interp); -static int TestalarmCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -static int TestgotsigCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); -static void AlarmHandler(int signum); -static int TestchmodCmd(ClientData dummy, - Tcl_Interp *interp, int argc, CONST char **argv); +static Tcl_CmdProc TestalarmCmd; +static Tcl_CmdProc TestchmodCmd; +static Tcl_CmdProc TestfilehandlerCmd; +static Tcl_CmdProc TestfilewaitCmd; +static Tcl_CmdProc TestfindexecutableCmd; +static Tcl_CmdProc TestgetdefencdirCmd; +static Tcl_CmdProc TestgetopenfileCmd; +static Tcl_CmdProc TestgotsigCmd; +static Tcl_CmdProc TestsetdefencdirCmd; +static Tcl_FileProc TestFileHandlerProc; +static void AlarmHandler(int signum); /* *---------------------------------------------------------------------- @@ -103,23 +96,23 @@ TclplatformtestInit( Tcl_Interp *interp) /* Interpreter to add commands to. */ { Tcl_CreateCommand(interp, "testchmod", TestchmodCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testfilehandler", TestfilehandlerCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testfilewait", TestfilewaitCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testfindexecutable", TestfindexecutableCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testgetopenfile", TestgetopenfileCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testgetdefenc", TestgetdefencdirCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testsetdefenc", TestsetdefencdirCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testalarm", TestalarmCmd, - (ClientData) 0, NULL); + NULL, NULL); Tcl_CreateCommand(interp, "testgotsig", TestgotsigCmd, - (ClientData) 0, NULL); + NULL, NULL); return TCL_OK; } @@ -145,7 +138,7 @@ TestfilehandlerCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { Pipe *pipePtr; int i, mask, timeout; @@ -167,7 +160,7 @@ TestfilehandlerCmd( if (argc < 2) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], - " option ... \"", NULL); + " option ... \"", NULL); return TCL_ERROR; } pipePtr = NULL; @@ -194,7 +187,7 @@ TestfilehandlerCmd( } else if (strcmp(argv[1], "clear") == 0) { if (argc != 3) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", - argv[0], " clear index\"", NULL); + argv[0], " clear index\"", NULL); return TCL_ERROR; } pipePtr->readCount = pipePtr->writeCount = 0; @@ -203,7 +196,7 @@ TestfilehandlerCmd( if (argc != 3) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", - argv[0], " counts index\"", NULL); + argv[0], " counts index\"", NULL); return TCL_ERROR; } sprintf(buf, "%d %d", pipePtr->readCount, pipePtr->writeCount); @@ -211,7 +204,7 @@ TestfilehandlerCmd( } else if (strcmp(argv[1], "create") == 0) { if (argc != 5) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", - argv[0], " create index readMode writeMode\"", NULL); + argv[0], " create index readMode writeMode\"", NULL); return TCL_ERROR; } if (pipePtr->readFile == NULL) { @@ -234,24 +227,24 @@ TestfilehandlerCmd( if (strcmp(argv[3], "readable") == 0) { Tcl_CreateFileHandler(GetFd(pipePtr->readFile), TCL_READABLE, - TestFileHandlerProc, (ClientData) pipePtr); + TestFileHandlerProc, pipePtr); } else if (strcmp(argv[3], "off") == 0) { Tcl_DeleteFileHandler(GetFd(pipePtr->readFile)); } else if (strcmp(argv[3], "disabled") == 0) { Tcl_CreateFileHandler(GetFd(pipePtr->readFile), 0, - TestFileHandlerProc, (ClientData) pipePtr); + TestFileHandlerProc, pipePtr); } else { Tcl_AppendResult(interp, "bad read mode \"", argv[3], "\"", NULL); return TCL_ERROR; } if (strcmp(argv[4], "writable") == 0) { Tcl_CreateFileHandler(GetFd(pipePtr->writeFile), TCL_WRITABLE, - TestFileHandlerProc, (ClientData) pipePtr); + TestFileHandlerProc, pipePtr); } else if (strcmp(argv[4], "off") == 0) { Tcl_DeleteFileHandler(GetFd(pipePtr->writeFile)); } else if (strcmp(argv[4], "disabled") == 0) { Tcl_CreateFileHandler(GetFd(pipePtr->writeFile), 0, - TestFileHandlerProc, (ClientData) pipePtr); + TestFileHandlerProc, pipePtr); } else { Tcl_AppendResult(interp, "bad read mode \"", argv[4], "\"", NULL); return TCL_ERROR; @@ -259,30 +252,30 @@ TestfilehandlerCmd( } else if (strcmp(argv[1], "empty") == 0) { if (argc != 3) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", - argv[0], " empty index\"", NULL); + argv[0], " empty index\"", NULL); return TCL_ERROR; } while (read(GetFd(pipePtr->readFile), buffer, 4000) > 0) { - /* Empty loop body. */ + /* Empty loop body. */ } } else if (strcmp(argv[1], "fill") == 0) { if (argc != 3) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", - argv[0], " fill index\"", NULL); + argv[0], " fill index\"", NULL); return TCL_ERROR; } memset(buffer, 'a', 4000); while (write(GetFd(pipePtr->writeFile), buffer, 4000) > 0) { - /* Empty loop body. */ + /* Empty loop body. */ } } else if (strcmp(argv[1], "fillpartial") == 0) { char buf[TCL_INTEGER_SPACE]; if (argc != 3) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", - argv[0], " fillpartial index\"", NULL); + argv[0], " fillpartial index\"", NULL); return TCL_ERROR; } @@ -294,7 +287,7 @@ TestfilehandlerCmd( } else if (strcmp(argv[1], "wait") == 0) { if (argc != 5) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", - argv[0], " wait index readable|writable timeout\"", NULL); + argv[0], " wait index readable|writable timeout\"", NULL); return TCL_ERROR; } if (pipePtr->readFile == NULL) { @@ -335,7 +328,7 @@ TestFileHandlerProc( int mask) /* Indicates which events happened: * TCL_READABLE or TCL_WRITABLE. */ { - Pipe *pipePtr = (Pipe *) clientData; + Pipe *pipePtr = clientData; if (mask & TCL_READABLE) { pipePtr->readCount++; @@ -367,7 +360,7 @@ TestfilewaitCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { int mask, result, timeout; Tcl_Channel channel; @@ -436,7 +429,7 @@ TestfindexecutableCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { Tcl_Obj *saveName; @@ -479,22 +472,22 @@ TestgetopenfileCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { ClientData filePtr; if (argc != 3) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " channelName forWriting\"", NULL); + " channelName forWriting\"", NULL); return TCL_ERROR; } if (Tcl_GetOpenFile(interp, argv[1], atoi(argv[2]), 1, &filePtr) - == TCL_ERROR) { + == TCL_ERROR) { return TCL_ERROR; } - if (filePtr == (ClientData) NULL) { + if (filePtr == NULL) { Tcl_AppendResult(interp, - "Tcl_GetOpenFile succeeded but FILE * NULL!", NULL); + "Tcl_GetOpenFile succeeded but FILE * NULL!", NULL); return TCL_ERROR; } return TCL_OK; @@ -522,11 +515,11 @@ TestsetdefencdirCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { if (argc != 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " defaultDir\"", NULL); + " defaultDir\"", NULL); return TCL_ERROR; } @@ -556,7 +549,7 @@ TestgetdefencdirCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { if (argc != 1) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], NULL); @@ -590,7 +583,7 @@ TestalarmCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { #ifdef SA_RESTART unsigned int sec; @@ -669,7 +662,7 @@ TestgotsigCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { Tcl_AppendResult(interp, gotsig, NULL); gotsig = "0"; @@ -700,7 +693,7 @@ TestchmodCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { int i, mode; char *rest; @@ -719,7 +712,7 @@ TestchmodCmd( for (i = 2; i < argc; i++) { Tcl_DString buffer; - CONST char *translated; + const char *translated; translated = Tcl_TranslateFileName(interp, argv[i], &buffer); if (translated == NULL) { diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index fd2cd8f..1f0281d 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -5,6 +5,7 @@ * * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. + * Copyright (c) 2008 by George Peter Staplin * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -14,7 +15,7 @@ #ifdef TCL_THREADS -#include "pthread.h" +#include <pthread.h> typedef struct ThreadSpecificData { char nabuf[16]; @@ -53,7 +54,6 @@ static pthread_mutex_t *allocLockPtr = &allocLock; #define MASTER_UNLOCK pthread_mutex_unlock(&masterLock) #endif /* TCL_THREADS */ - /* *---------------------------------------------------------------------- @@ -75,7 +75,7 @@ static pthread_mutex_t *allocLockPtr = &allocLock; int TclpThreadCreate( Tcl_ThreadId *idPtr, /* Return, the ID of the thread */ - Tcl_ThreadCreateProc proc, /* Main() function of the thread */ + Tcl_ThreadCreateProc *proc, /* Main() function of the thread */ ClientData clientData, /* The one argument to Main() */ int stackSize, /* Size of stack for the new thread */ int flags) /* Flags controlling behaviour of the new @@ -107,18 +107,19 @@ TclpThreadCreate( */ size_t size; + result = pthread_attr_getstacksize(&attr, &size); if (!result && (size < TCL_THREAD_STACK_MIN)) { pthread_attr_setstacksize(&attr, (size_t) TCL_THREAD_STACK_MIN); } -#endif +#endif /* TCL_THREAD_STACK_MIN */ } -#endif +#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */ + if (! (flags & TCL_THREAD_JOINABLE)) { pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); } - if (pthread_create(&theThread, &attr, (void * (*)(void *))proc, (void *)clientData) && pthread_create(&theThread, NULL, @@ -197,99 +198,6 @@ TclpThreadExit( } #endif /* TCL_THREADS */ -#ifdef TCL_THREADS -/* - *---------------------------------------------------------------------- - * - * TclpThreadGetStackSize -- - * - * This procedure returns the size of the current thread's stack. - * - * Results: - * Stack size (in bytes?) or -1 for error or 0 for undeterminable. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -size_t -TclpThreadGetStackSize(void) -{ - size_t stackSize = 0; -#if defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && defined(TclpPthreadGetAttrs) - pthread_attr_t threadAttr; /* This will hold the thread attributes for - * the current thread. */ -#ifdef __GLIBC__ - /* - * Fix for [Bug 1815573] - * - * DESCRIPTION: - * On linux TclpPthreadGetAttrs (which is pthread_attr_get_np) may return - * bogus values on the initial thread. - * - * ASSUMPTIONS: - * There seems to be no api to determine if we are on the initial - * thread. The simple scheme implemented here assumes: - * 1. The first Tcl interp to be created lives in the initial thread. If - * this assumption is not true, the fix is to call - * TclpThreadGetStackSize from the initial thread previous to - * creating any Tcl interpreter. In this case, especially if another - * Tcl interpreter may be created in the initial thread, it might be - * better to enable the second branch in the #if below - * 2. There will be no races in creating the first Tcl interp - ie, the - * second Tcl interp will be created only after the first call to - * Tcl_CreateInterp returns. - * - * These assumptions are satisfied by tclsh. Embedders on linux may want - * to check their validity, and possibly adapt the code on failing to meet - * them. - */ - - static int initialized = 0; - - if (!initialized) { - initialized = 1; - return 0; - } else { -#else - { -#endif - if (pthread_attr_init(&threadAttr) != 0) { - return -1; - } - if (TclpPthreadGetAttrs(pthread_self(), &threadAttr) != 0) { - pthread_attr_destroy(&threadAttr); - return (size_t)-1; - } - } - - - if (pthread_attr_getstacksize(&threadAttr, &stackSize) != 0) { - pthread_attr_destroy(&threadAttr); - return (size_t)-1; - } - pthread_attr_destroy(&threadAttr); -#elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP) -#ifdef __APPLE__ - /* - * On Darwin, the API below does not return the correct stack size for the - * main thread (which is not a real pthread), so fallback to getrlimit(). - */ - if (!pthread_main_np()) -#endif - stackSize = pthread_get_stacksize_np(pthread_self()); -#else - /* - * Cannot determine the real stack size of this thread. The caller might - * want to try looking at the process accounting limits instead. - */ -#endif - return stackSize; -} -#endif /* TCL_THREADS */ - /* *---------------------------------------------------------------------- * @@ -514,6 +422,7 @@ Tcl_MutexLock( Tcl_Mutex *mutexPtr) /* Really (pthread_mutex_t **) */ { pthread_mutex_t *pmutexPtr; + if (*mutexPtr == NULL) { MASTER_LOCK; if (*mutexPtr == NULL) { @@ -521,7 +430,7 @@ Tcl_MutexLock( * Double inside master lock check to avoid a race condition. */ - pmutexPtr = (pthread_mutex_t *)ckalloc(sizeof(pthread_mutex_t)); + pmutexPtr = ckalloc(sizeof(pthread_mutex_t)); pthread_mutex_init(pmutexPtr, NULL); *mutexPtr = (Tcl_Mutex)pmutexPtr; TclRememberMutex(mutexPtr); @@ -553,7 +462,8 @@ void Tcl_MutexUnlock( Tcl_Mutex *mutexPtr) /* Really (pthread_mutex_t **) */ { - pthread_mutex_t *pmutexPtr = *(pthread_mutex_t **)mutexPtr; + pthread_mutex_t *pmutexPtr = *(pthread_mutex_t **) mutexPtr; + pthread_mutex_unlock(pmutexPtr); } @@ -580,10 +490,11 @@ void TclpFinalizeMutex( Tcl_Mutex *mutexPtr) { - pthread_mutex_t *pmutexPtr = *(pthread_mutex_t **)mutexPtr; + pthread_mutex_t *pmutexPtr = *(pthread_mutex_t **) mutexPtr; + if (pmutexPtr != NULL) { pthread_mutex_destroy(pmutexPtr); - ckfree((char *) pmutexPtr); + ckfree(pmutexPtr); *mutexPtr = NULL; } } @@ -614,7 +525,7 @@ void Tcl_ConditionWait( Tcl_Condition *condPtr, /* Really (pthread_cond_t **) */ Tcl_Mutex *mutexPtr, /* Really (pthread_mutex_t **) */ - Tcl_Time *timePtr) /* Timeout on waiting period */ + const Tcl_Time *timePtr) /* Timeout on waiting period */ { pthread_cond_t *pcondPtr; pthread_mutex_t *pmutexPtr; @@ -629,9 +540,9 @@ Tcl_ConditionWait( */ if (*condPtr == NULL) { - pcondPtr = (pthread_cond_t *) ckalloc(sizeof(pthread_cond_t)); + pcondPtr = ckalloc(sizeof(pthread_cond_t)); pthread_cond_init(pcondPtr, NULL); - *condPtr = (Tcl_Condition)pcondPtr; + *condPtr = (Tcl_Condition) pcondPtr; TclRememberCondition(condPtr); } MASTER_UNLOCK; @@ -713,9 +624,10 @@ TclpFinalizeCondition( Tcl_Condition *condPtr) { pthread_cond_t *pcondPtr = *(pthread_cond_t **)condPtr; + if (pcondPtr != NULL) { pthread_cond_destroy(pcondPtr); - ckfree((char *) pcondPtr); + ckfree(pcondPtr); *condPtr = NULL; } } @@ -849,6 +761,58 @@ TclpSetAllocCache( pthread_setspecific(key, arg); } #endif /* USE_THREAD_ALLOC */ + +void * +TclpThreadCreateKey(void) +{ + pthread_key_t *ptkeyPtr; + + ptkeyPtr = TclpSysAlloc(sizeof *ptkeyPtr, 0); + if (NULL == ptkeyPtr) { + Tcl_Panic("unable to allocate thread key!"); + } + + if (pthread_key_create(ptkeyPtr, NULL)) { + Tcl_Panic("unable to create pthread key!"); + } + + return ptkeyPtr; +} + +void +TclpThreadDeleteKey( + void *keyPtr) +{ + pthread_key_t *ptkeyPtr = keyPtr; + + if (pthread_key_delete(*ptkeyPtr)) { + Tcl_Panic("unable to delete key!"); + } + + TclpSysFree(keyPtr); +} + +void +TclpThreadSetMasterTSD( + void *tsdKeyPtr, + void *ptr) +{ + pthread_key_t *ptkeyPtr = tsdKeyPtr; + + if (pthread_setspecific(*ptkeyPtr, ptr)) { + Tcl_Panic("unable to set master TSD value"); + } +} + +void * +TclpThreadGetMasterTSD( + void *tsdKeyPtr) +{ + pthread_key_t *ptkeyPtr = tsdKeyPtr; + + return pthread_getspecific(*ptkeyPtr); +} + #endif /* TCL_THREADS */ /* diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c index b98f2e1..02a90a5 100644 --- a/unix/tclUnixTime.c +++ b/unix/tclUnixTime.c @@ -112,7 +112,7 @@ TclpGetClicks(void) if (tclGetTimeProcPtr != NativeGetTime) { Tcl_Time time; - (*tclGetTimeProcPtr) (&time, tclTimeClientData); + tclGetTimeProcPtr(&time, tclTimeClientData); now = time.sec*1000000 + time.usec; } else { /* @@ -125,7 +125,7 @@ TclpGetClicks(void) #else Tcl_Time time; - (*tclGetTimeProcPtr) (&time, tclTimeClientData); + tclGetTimeProcPtr(&time, tclTimeClientData); now = time.sec*1000000 + time.usec; #endif @@ -134,7 +134,7 @@ TclpGetClicks(void) #ifdef TCL_WIDE_CLICKS /* - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- * * TclpGetWideClicks -- * @@ -149,7 +149,7 @@ TclpGetClicks(void) * Side effects: * None. * - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- */ Tcl_WideInt @@ -160,7 +160,7 @@ TclpGetWideClicks(void) if (tclGetTimeProcPtr != NativeGetTime) { Tcl_Time time; - (*tclGetTimeProcPtr) (&time, tclTimeClientData); + tclGetTimeProcPtr(&time, tclTimeClientData); now = (Tcl_WideInt) (time.sec*1000000 + time.usec); } else { #ifdef MAC_OSX_TCL @@ -174,7 +174,7 @@ TclpGetWideClicks(void) } /* - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- * * TclpWideClicksToNanoseconds -- * @@ -187,7 +187,7 @@ TclpGetWideClicks(void) * Side effects: * None. * - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- */ double @@ -361,7 +361,7 @@ void Tcl_GetTime( Tcl_Time *timePtr) /* Location to store time information. */ { - (*tclGetTimeProcPtr) (timePtr, tclTimeClientData); + tclGetTimeProcPtr(timePtr, tclTimeClientData); } /* @@ -384,7 +384,7 @@ Tcl_GetTime( struct tm * TclpGetDate( - CONST time_t *time, + const time_t *time, int useGMT) { if (useGMT) { @@ -412,7 +412,7 @@ TclpGetDate( struct tm * TclpGmtime( - CONST time_t *timePtr) /* Pointer to the number of seconds since the + const time_t *timePtr) /* Pointer to the number of seconds since the * local system's epoch */ { /* @@ -422,14 +422,14 @@ TclpGmtime( ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&tmKey); #ifdef HAVE_GMTIME_R - gmtime_r(timePtr, &(tsdPtr->gmtime_buf)); + gmtime_r(timePtr, &tsdPtr->gmtime_buf); #else Tcl_MutexLock(&tmMutex); - memcpy(&(tsdPtr->gmtime_buf), gmtime(timePtr), sizeof(struct tm)); + memcpy(&tsdPtr->gmtime_buf, gmtime(timePtr), sizeof(struct tm)); Tcl_MutexUnlock(&tmMutex); #endif - return &(tsdPtr->gmtime_buf); + return &tsdPtr->gmtime_buf; } /* @@ -451,7 +451,7 @@ TclpGmtime( struct tm * TclpLocaltime( - CONST time_t *timePtr) /* Pointer to the number of seconds since the + const time_t *timePtr) /* Pointer to the number of seconds since the * local system's epoch */ { /* @@ -462,14 +462,14 @@ TclpLocaltime( SetTZIfNecessary(); #ifdef HAVE_LOCALTIME_R - localtime_r(timePtr, &(tsdPtr->localtime_buf)); + localtime_r(timePtr, &tsdPtr->localtime_buf); #else Tcl_MutexLock(&tmMutex); - memcpy(&(tsdPtr->localtime_buf), localtime(timePtr), sizeof(struct tm)); + memcpy(&tsdPtr->localtime_buf, localtime(timePtr), sizeof(struct tm)); Tcl_MutexUnlock(&tmMutex); #endif - return &(tsdPtr->localtime_buf); + return &tsdPtr->localtime_buf; } /* @@ -608,7 +608,7 @@ NativeGetTime( static void SetTZIfNecessary(void) { - CONST char *newTZ = getenv("TZ"); + const char *newTZ = getenv("TZ"); Tcl_MutexLock(&tmMutex); if (newTZ == NULL) { @@ -617,7 +617,7 @@ SetTZIfNecessary(void) if (lastTZ == NULL || strcmp(lastTZ, newTZ)) { tzset(); if (lastTZ == NULL) { - Tcl_CreateExitHandler(CleanupMemory, (ClientData) NULL); + Tcl_CreateExitHandler(CleanupMemory, NULL); } else { Tcl_Free(lastTZ); } diff --git a/unix/tclXtNotify.c b/unix/tclXtNotify.c index 6a11c0d..50eb4a2 100644 --- a/unix/tclXtNotify.c +++ b/unix/tclXtNotify.c @@ -10,9 +10,15 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#ifndef USE_TCL_STUBS +# define USE_TCL_STUBS +#endif #include <X11/Intrinsic.h> #include "tclInt.h" +#ifndef CONST86 +# define CONST86 +#endif /* * This structure is used to keep track of the notifier info for a a * registered file. @@ -74,22 +80,22 @@ static int initialized = 0; */ static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); -static void FileProc(caddr_t clientData, int *source, +static void FileProc(ClientData clientData, int *source, XtInputId *id); -void InitNotifier(void); static void NotifierExitHandler(ClientData clientData); -static void TimerProc(caddr_t clientData, XtIntervalId *id); +static void TimerProc(ClientData clientData, XtIntervalId *id); static void CreateFileHandler(int fd, int mask, - Tcl_FileProc * proc, ClientData clientData); + Tcl_FileProc *proc, ClientData clientData); static void DeleteFileHandler(int fd); -static void SetTimer(Tcl_Time * timePtr); -static int WaitForEvent(Tcl_Time * timePtr); +static void SetTimer(CONST86 Tcl_Time * timePtr); +static int WaitForEvent(CONST86 Tcl_Time * timePtr); /* * Functions defined in this file for use by users of the Xt Notifier: */ -EXTERN XtAppContext TclSetAppContext(XtAppContext ctx); +MODULE_SCOPE void InitNotifier(void); +MODULE_SCOPE XtAppContext TclSetAppContext(XtAppContext ctx); /* *---------------------------------------------------------------------- @@ -259,7 +265,7 @@ NotifierExitHandler( static void SetTimer( - Tcl_Time *timePtr) /* Timeout value, may be NULL. */ + CONST86 Tcl_Time *timePtr) /* Timeout value, may be NULL. */ { long timeout; @@ -298,7 +304,7 @@ SetTimer( static void TimerProc( - caddr_t data, /* Not used. */ + ClientData clientData, /* Not used. */ XtIntervalId *id) { if (*id != notifier.currentTimeout) { @@ -352,7 +358,7 @@ CreateFileHandler( } } if (filePtr == NULL) { - filePtr = (FileHandler*) ckalloc(sizeof(FileHandler)); + filePtr = ckalloc(sizeof(FileHandler)); filePtr->fd = fd; filePtr->read = 0; filePtr->write = 0; @@ -372,7 +378,7 @@ CreateFileHandler( if (mask & TCL_READABLE) { if (!(filePtr->mask & TCL_READABLE)) { filePtr->read = XtAppAddInput(notifier.appContext, fd, - XtInputReadMask, FileProc, filePtr); + INT2PTR(XtInputReadMask), FileProc, filePtr); } } else { if (filePtr->mask & TCL_READABLE) { @@ -382,7 +388,7 @@ CreateFileHandler( if (mask & TCL_WRITABLE) { if (!(filePtr->mask & TCL_WRITABLE)) { filePtr->write = XtAppAddInput(notifier.appContext, fd, - XtInputWriteMask, FileProc, filePtr); + INT2PTR(XtInputWriteMask), FileProc, filePtr); } } else { if (filePtr->mask & TCL_WRITABLE) { @@ -392,7 +398,7 @@ CreateFileHandler( if (mask & TCL_EXCEPTION) { if (!(filePtr->mask & TCL_EXCEPTION)) { filePtr->except = XtAppAddInput(notifier.appContext, fd, - XtInputExceptMask, FileProc, filePtr); + INT2PTR(XtInputExceptMask), FileProc, filePtr); } } else { if (filePtr->mask & TCL_EXCEPTION) { @@ -463,7 +469,7 @@ DeleteFileHandler( if (filePtr->mask & TCL_EXCEPTION) { XtRemoveInput(filePtr->except); } - ckfree((char *) filePtr); + ckfree(filePtr); } /* @@ -485,7 +491,7 @@ DeleteFileHandler( static void FileProc( - caddr_t clientData, + ClientData clientData, int *fd, XtInputId *id) { @@ -518,7 +524,7 @@ FileProc( */ filePtr->readyMask |= mask; - fileEvPtr = (FileHandlerEvent *) ckalloc(sizeof(FileHandlerEvent)); + fileEvPtr = ckalloc(sizeof(FileHandlerEvent)); fileEvPtr->header.proc = FileHandlerEventProc; fileEvPtr->fd = filePtr->fd; Tcl_QueueEvent((Tcl_Event *) fileEvPtr, TCL_QUEUE_TAIL); @@ -594,7 +600,7 @@ FileHandlerEventProc( mask = filePtr->readyMask & filePtr->mask; filePtr->readyMask = 0; if (mask != 0) { - (*filePtr->proc)(filePtr->clientData, mask); + filePtr->proc(filePtr->clientData, mask); } break; } @@ -623,7 +629,7 @@ FileHandlerEventProc( static int WaitForEvent( - Tcl_Time *timePtr) /* Maximum block time, or NULL. */ + CONST86 Tcl_Time *timePtr) /* Maximum block time, or NULL. */ { int timeout; diff --git a/unix/tclXtTest.c b/unix/tclXtTest.c index 8437f2a..93bcc81 100644 --- a/unix/tclXtTest.c +++ b/unix/tclXtTest.c @@ -1,20 +1,29 @@ -/* +/* * tclXtTest.c -- * * Contains commands for Xt notifier specific tests on Unix. * * Copyright (c) 1997 by Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#ifndef USE_TCL_STUBS +# define USE_TCL_STUBS +#endif #include <X11/Intrinsic.h> #include "tcl.h" -static int TesteventloopCmd(ClientData clientData, - Tcl_Interp *interp, int argc, CONST char **argv); +static Tcl_CmdProc TesteventloopCmd; +extern DLLEXPORT Tcl_PackageInitProc Tclxttest_Init; + +/* + * Functions defined in tclXtNotify.c for use by users of the Xt Notifier: + */ + extern void InitNotifier(void); +extern XtAppContext TclSetAppContext(XtAppContext ctx); /* *---------------------------------------------------------------------- @@ -39,13 +48,13 @@ int Tclxttest_Init( Tcl_Interp *interp) /* Interpreter for application. */ { - if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + if (Tcl_InitStubs(interp, "8.1", 0) == NULL) { return TCL_ERROR; } XtToolkitInitialize(); InitNotifier(); Tcl_CreateCommand(interp, "testeventloop", TesteventloopCmd, - (ClientData) 0, NULL); + NULL, NULL); return TCL_OK; } @@ -72,16 +81,16 @@ TesteventloopCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - CONST char **argv) /* Argument strings. */ + const char **argv) /* Argument strings. */ { static int *framePtr = NULL;/* Pointer to integer on stack frame of * innermost invocation of the "wait" * subcommand. */ - if (argc < 2) { + if (argc < 2) { Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], - " option ... \"", NULL); - return TCL_ERROR; + " option ... \"", NULL); + return TCL_ERROR; } if (strcmp(argv[1], "done") == 0) { *framePtr = 1; diff --git a/unix/tclooConfig.sh b/unix/tclooConfig.sh new file mode 100644 index 0000000..68de106 --- /dev/null +++ b/unix/tclooConfig.sh @@ -0,0 +1,19 @@ +# tclooConfig.sh -- +# +# This shell script (for sh) is generated automatically by TclOO's configure +# script, or would be except it has no values that we substitute. It will +# create shell variables for most of the configuration options discovered by +# the configure script. This script is intended to be included by TEA-based +# configure scripts for TclOO extensions so that they don't have to figure +# this all out for themselves. +# +# The information in this file is specific to a single platform. + +# These are mostly empty because no special steps are ever needed from Tcl 8.6 +# onwards; all libraries and include files are just part of Tcl. +TCLOO_LIB_SPEC="" +TCLOO_STUB_LIB_SPEC="" +TCLOO_INCLUDE_SPEC="" +TCLOO_PRIVATE_INCLUDE_SPEC="" +TCLOO_CFLAGS=-DUSE_TCLOO_STUBS +TCLOO_VERSION=0.6.3 |