From d07c6e8a0ede3114ebfd8c3ea6cc161cf009f072 Mon Sep 17 00:00:00 2001 From: Lenny222 Date: Thu, 29 Dec 2011 21:24:03 +0100 Subject: list: use predicate to enforce non-empty requirement --- src/libstd/list.rs | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/list.rs b/src/libstd/list.rs index c6a24d275eb..f6b46ed7d2e 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -97,6 +97,27 @@ fn has(ls: list, elt: T) -> bool { ret false; } +/* +Function: is_empty + +Returns true if the list is empty. +*/ +pure fn is_empty(ls: list) -> bool { + alt ls { + nil. { true } + _ { false } + } +} + +/* +Function: is_not_empty + +Returns true if the list is not empty. +*/ +pure fn is_not_empty(ls: list) -> bool { + ret !is_empty(ls); +} + /* Function: len @@ -112,8 +133,11 @@ Function: tail Returns all but the first element of a list */ -pure fn tail(ls: list) -> list { - alt ls { cons(_, tl) { ret *tl; } nil. { fail "list empty" } } +pure fn tail(ls: list) : is_not_empty(ls) -> list { + alt ls { + cons(_, tl) { ret *tl; } + nil. { fail "list empty" } + } } /* @@ -121,8 +145,11 @@ Function: head Returns the first element of a list */ -pure fn head(ls: list) -> T { - alt ls { cons(hd, _) { ret hd; } nil. { fail "list empty" } } +pure fn head(ls: list) : is_not_empty(ls) -> T { + alt ls { + cons(hd, _) { ret hd; } + nil. { fail "list empty" } + } } /* -- cgit 1.4.1-3-g733a5 From a59c4b1b47b84879edfc43e7278553105930f0e2 Mon Sep 17 00:00:00 2001 From: User Jyyou Date: Fri, 30 Dec 2011 16:18:55 +0800 Subject: freebsd support --- configure | 2 +- mk/libuv/x86_64/freebsd/Makefile | 353 +++++++++++++++++++++ .../freebsd/src/libuv/run-benchmarks.target.mk | 83 +++++ .../x86_64/freebsd/src/libuv/run-tests.target.mk | 117 +++++++ mk/libuv/x86_64/freebsd/src/libuv/uv.Makefile | 6 + mk/libuv/x86_64/freebsd/src/libuv/uv.target.mk | 138 ++++++++ mk/platform.mk | 17 +- mk/rt.mk | 9 + src/comp/back/link.rs | 15 +- src/comp/back/rpath.rs | 10 + src/comp/back/x86.rs | 6 + src/comp/back/x86_64.rs | 8 + src/comp/driver/driver.rs | 3 + src/comp/driver/session.rs | 2 +- src/comp/metadata/creader.rs | 1 + src/comp/middle/trans.rs | 2 + src/compiletest/procsrv.rs | 1 + src/compiletest/runtest.rs | 1 + src/compiletest/util.rs | 2 + src/libcore/cmath.rs | 6 + src/libcore/f32.rs | 5 + src/libcore/f64.rs | 5 + src/libstd/freebsd_os.rs | 155 +++++++++ src/libstd/fs.rs | 4 + src/libstd/generic_os.rs | 2 + src/libstd/run_program.rs | 3 + src/libstd/std.rc | 7 + src/libstd/uv.rs | 5 +- src/rt/arch/i386/ccall.S | 10 +- src/rt/arch/i386/morestack.S | 14 +- src/rt/arch/i386/record_sp.S | 2 +- src/rt/arch/x86_64/ccall.S | 8 +- src/rt/arch/x86_64/context.h | 4 + src/rt/arch/x86_64/morestack.S | 10 +- src/rt/arch/x86_64/record_sp.S | 2 +- src/rt/rust_abi.cpp | 2 +- src/rt/rust_task.cpp | 10 + src/rt/rust_upcall.cpp | 2 +- src/test/run-pass/dupe-first-attr.rc | 5 +- src/test/run-pass/x86stdcall.rs | 1 + src/test/run-pass/x86stdcall2.rs | 1 + src/test/stdtest/uv.rs | 3 +- 42 files changed, 1003 insertions(+), 39 deletions(-) create mode 100644 mk/libuv/x86_64/freebsd/Makefile create mode 100644 mk/libuv/x86_64/freebsd/src/libuv/run-benchmarks.target.mk create mode 100644 mk/libuv/x86_64/freebsd/src/libuv/run-tests.target.mk create mode 100644 mk/libuv/x86_64/freebsd/src/libuv/uv.Makefile create mode 100644 mk/libuv/x86_64/freebsd/src/libuv/uv.target.mk create mode 100644 src/libstd/freebsd_os.rs (limited to 'src/libstd') diff --git a/configure b/configure index c634805759c..927fc62c4af 100755 --- a/configure +++ b/configure @@ -212,7 +212,7 @@ case $CFG_CPUTYPE in CFG_CPUTYPE=arm ;; - x86_64 | x86-64 | x64) + x86_64 | x86-64 | x64 | amd64) CFG_CPUTYPE=x86_64 ;; diff --git a/mk/libuv/x86_64/freebsd/Makefile b/mk/libuv/x86_64/freebsd/Makefile new file mode 100644 index 00000000000..98a175dd3f0 --- /dev/null +++ b/mk/libuv/x86_64/freebsd/Makefile @@ -0,0 +1,353 @@ +# We borrow heavily from the kernel build setup, though we are simpler since +# we don't have Kconfig tweaking settings on us. + +# The implicit make rules have it looking for RCS files, among other things. +# We instead explicitly write all the rules we care about. +# It's even quicker (saves ~200ms) to pass -r on the command line. +MAKEFLAGS=-r + +# The source directory tree. +srcdir := ../../../.. + +# The name of the builddir. +builddir_name ?= out + +# The V=1 flag on command line makes us verbosely print command lines. +ifdef V + quiet= +else + quiet=quiet_ +endif + +# Specify BUILDTYPE=Release on the command line for a release build. +BUILDTYPE ?= Default + +# Directory all our build output goes into. +# Note that this must be two directories beneath src/ for unit tests to pass, +# as they reach into the src/ directory for data with relative paths. +builddir ?= $(builddir_name)/$(BUILDTYPE) +abs_builddir := $(abspath $(builddir)) +depsdir := $(builddir)/.deps + +# Object output directory. +obj := $(builddir)/obj +abs_obj := $(abspath $(obj)) + +# We build up a list of every single one of the targets so we can slurp in the +# generated dependency rule Makefiles in one pass. +all_deps := + + + +# C++ apps need to be linked with g++. +# +# Note: flock is used to seralize linking. Linking is a memory-intensive +# process so running parallel links can often lead to thrashing. To disable +# the serialization, override LINK via an envrionment variable as follows: +# +# export LINK=g++ +# +# This will allow make to invoke N linker processes as specified in -jN. +LINK ?= lockf $(builddir)/linker.lock $(CXX) + +CC.target ?= $(CC) +CFLAGS.target ?= $(CFLAGS) +CXX.target ?= $(CXX) +CXXFLAGS.target ?= $(CXXFLAGS) +LINK.target ?= $(LINK) +LDFLAGS.target ?= $(LDFLAGS) +AR.target ?= $(AR) +ARFLAGS.target ?= crs + +# N.B.: the logic of which commands to run should match the computation done +# in gyp's make.py where ARFLAGS.host etc. is computed. +# TODO(evan): move all cross-compilation logic to gyp-time so we don't need +# to replicate this environment fallback in make as well. +CC.host ?= gcc +CFLAGS.host ?= +CXX.host ?= g++ +CXXFLAGS.host ?= +LINK.host ?= g++ +LDFLAGS.host ?= +AR.host ?= ar +ARFLAGS.host := crs + +# Define a dir function that can handle spaces. +# http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions +# "leading spaces cannot appear in the text of the first argument as written. +# These characters can be put into the argument value by variable substitution." +empty := +space := $(empty) $(empty) + +# http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces +replace_spaces = $(subst $(space),?,$1) +unreplace_spaces = $(subst ?,$(space),$1) +dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1))) + +# Flags to make gcc output dependency info. Note that you need to be +# careful here to use the flags that ccache and distcc can understand. +# We write to a dep file on the side first and then rename at the end +# so we can't end up with a broken dep file. +depfile = $(depsdir)/$(call replace_spaces,$@).d +DEPFLAGS = -MMD -MF $(depfile).raw + +# We have to fixup the deps output in a few ways. +# (1) the file output should mention the proper .o file. +# ccache or distcc lose the path to the target, so we convert a rule of +# the form: +# foobar.o: DEP1 DEP2 +# into +# path/to/foobar.o: DEP1 DEP2 +# (2) we want missing files not to cause us to fail to build. +# We want to rewrite +# foobar.o: DEP1 DEP2 \ +# DEP3 +# to +# DEP1: +# DEP2: +# DEP3: +# so if the files are missing, they're just considered phony rules. +# We have to do some pretty insane escaping to get those backslashes +# and dollar signs past make, the shell, and sed at the same time. +# Doesn't work with spaces, but that's fine: .d files have spaces in +# their names replaced with other characters. +define fixup_dep +# The depfile may not exist if the input file didn't have any #includes. +touch $(depfile).raw +# Fixup path as in (1). +sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile) +# Add extra rules as in (2). +# We remove slashes and replace spaces with new lines; +# remove blank lines; +# delete the first line and append a colon to the remaining lines. +sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\ + grep -v '^$$' |\ + sed -e 1d -e 's|$$|:|' \ + >> $(depfile) +rm $(depfile).raw +endef + +# Command definitions: +# - cmd_foo is the actual command to run; +# - quiet_cmd_foo is the brief-output summary of the command. + +quiet_cmd_cc = CC($(TOOLSET)) $@ +cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_cxx = CXX($(TOOLSET)) $@ +cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_touch = TOUCH $@ +cmd_touch = touch $@ + +quiet_cmd_copy = COPY $@ +# send stderr to /dev/null to ignore messages when linking directories. +cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@") + +quiet_cmd_alink = AR($(TOOLSET)) $@ +cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) $(ARFLAGS.$(TOOLSET)) $@ $(filter %.o,$^) + +# Due to circular dependencies between libraries :(, we wrap the +# special "figure out circular dependencies" flags around the entire +# input list during linking. +quiet_cmd_link = LINK($(TOOLSET)) $@ +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) + +# We support two kinds of shared objects (.so): +# 1) shared_library, which is just bundling together many dependent libraries +# into a link line. +# 2) loadable_module, which is generating a module intended for dlopen(). +# +# They differ only slightly: +# In the former case, we want to package all dependent code into the .so. +# In the latter case, we want to package just the API exposed by the +# outermost module. +# This means shared_library uses --whole-archive, while loadable_module doesn't. +# (Note that --whole-archive is incompatible with the --start-group used in +# normal linking.) + +# Other shared-object link notes: +# - Set SONAME to the library filename so our binaries don't reference +# the local, absolute paths used on the link command-line. +quiet_cmd_solink = SOLINK($(TOOLSET)) $@ +cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS) + +quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@ +cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS) + + +# Define an escape_quotes function to escape single quotes. +# This allows us to handle quotes properly as long as we always use +# use single quotes and escape_quotes. +escape_quotes = $(subst ','\'',$(1)) +# This comment is here just to include a ' to unconfuse syntax highlighting. +# Define an escape_vars function to escape '$' variable syntax. +# This allows us to read/write command lines with shell variables (e.g. +# $LD_LIBRARY_PATH), without triggering make substitution. +escape_vars = $(subst $$,$$$$,$(1)) +# Helper that expands to a shell command to echo a string exactly as it is in +# make. This uses printf instead of echo because printf's behaviour with respect +# to escape sequences is more portable than echo's across different shells +# (e.g., dash, bash). +exact_echo = printf '%s\n' '$(call escape_quotes,$(1))' + +# Helper to compare the command we're about to run against the command +# we logged the last time we ran the command. Produces an empty +# string (false) when the commands match. +# Tricky point: Make has no string-equality test function. +# The kernel uses the following, but it seems like it would have false +# positives, where one string reordered its arguments. +# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ +# $(filter-out $(cmd_$@), $(cmd_$(1)))) +# We instead substitute each for the empty string into the other, and +# say they're equal if both substitutions produce the empty string. +# .d files contain ? instead of spaces, take that into account. +command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\ + $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1)))) + +# Helper that is non-empty when a prerequisite changes. +# Normally make does this implicitly, but we force rules to always run +# so we can check their command lines. +# $? -- new prerequisites +# $| -- order-only dependencies +prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?)) + +# Helper that executes all postbuilds, and deletes the output file when done +# if any of the postbuilds failed. +define do_postbuilds + @E=0;\ + for p in $(POSTBUILDS); do\ + eval $$p;\ + F=$$?;\ + if [ $$F -ne 0 ]; then\ + E=$$F;\ + fi;\ + done;\ + if [ $$E -ne 0 ]; then\ + rm -rf "$@";\ + exit $$E;\ + fi +endef + +# do_cmd: run a command via the above cmd_foo names, if necessary. +# Should always run for a given target to handle command-line changes. +# Second argument, if non-zero, makes it do asm/C/C++ dependency munging. +# Third argument, if non-zero, makes it do POSTBUILDS processing. +# Note: We intentionally do NOT call dirx for depfile, since it contains ? for +# spaces already and dirx strips the ? characters. +define do_cmd +$(if $(or $(command_changed),$(prereq_changed)), + @$(call exact_echo, $($(quiet)cmd_$(1))) + @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))" + $(if $(findstring flock,$(word 1,$(cmd_$1))), + @$(cmd_$(1)) + @echo " $(quiet_cmd_$(1)): Finished", + @$(cmd_$(1)) + ) + @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile) + @$(if $(2),$(fixup_dep)) + $(if $(and $(3), $(POSTBUILDS)), + $(call do_postbuilds) + ) +) +endef + +# Declare the "all" target first so it is the default, +# even though we don't have the deps yet. +.PHONY: all +all: + +# Use FORCE_DO_CMD to force a target to run. Should be coupled with +# do_cmd. +.PHONY: FORCE_DO_CMD +FORCE_DO_CMD: + +TOOLSET := target +# Suffix rules, putting all outputs into $(obj). +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + + +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,src/libuv/run-benchmarks.target.mk)))),) + include src/libuv/run-benchmarks.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,src/libuv/run-tests.target.mk)))),) + include src/libuv/run-tests.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,src/libuv/uv.target.mk)))),) + include src/libuv/uv.target.mk +endif + +quiet_cmd_regen_makefile = ACTION Regenerating $@ +cmd_regen_makefile = ./src/libuv/build/gyp/gyp -fmake --ignore-environment "--toplevel-dir=." "--depth=." "--generator-output=mk/libuv/x86_64/unix" "-Dlibrary=static_library" "-Dtarget_arch=x86_64" "-DOS=freebsd" src/libuv/uv.gyp +Makefile: $(srcdir)/src/libuv/uv.gyp +# $(call do_cmd,regen_makefile) + +# "all" is a concatenation of the "all" targets from all the included +# sub-makefiles. This is just here to clarify. +all: + +# Add in dependency-tracking rules. $(all_deps) is the list of every single +# target in our tree. Only consider the ones with .d (dependency) info: +d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d)) +ifneq ($(d_files),) + # Rather than include each individual .d file, concatenate them into a + # single file which make is able to load faster. We split this into + # commands that take 1000 files at a time to avoid overflowing the + # command line. + $(shell cat $(wordlist 1,1000,$(d_files)) > $(depsdir)/all.deps) + + ifneq ($(word 1001,$(d_files)),) + $(error Found unprocessed dependency files (gyp didn't generate enough rules!)) + endif + + # make looks for ways to re-generate included makefiles, but in our case, we + # don't have a direct way. Explicitly telling make that it has nothing to do + # for them makes it go faster. + $(depsdir)/all.deps: ; + + include $(depsdir)/all.deps +endif diff --git a/mk/libuv/x86_64/freebsd/src/libuv/run-benchmarks.target.mk b/mk/libuv/x86_64/freebsd/src/libuv/run-benchmarks.target.mk new file mode 100644 index 00000000000..333d5e04a23 --- /dev/null +++ b/mk/libuv/x86_64/freebsd/src/libuv/run-benchmarks.target.mk @@ -0,0 +1,83 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := run-benchmarks +DEFS_Default := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' + +# Flags passed to all source files. +CFLAGS_Default := -pthread + +# Flags passed to only C files. +CFLAGS_C_Default := + +# Flags passed to only C++ files. +CFLAGS_CC_Default := + +INCS_Default := -I$(srcdir)/src/libuv/include + +OBJS := $(obj).target/$(TARGET)/src/libuv/test/benchmark-ares.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-getaddrinfo.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-ping-pongs.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-pound.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-pump.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-sizes.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-spawn.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-tcp-write-batch.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-udp-packet-storm.o \ + $(obj).target/$(TARGET)/src/libuv/test/dns-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/echo-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/blackhole-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/run-benchmarks.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner-unix.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# Make sure our dependencies are built before any of us. +$(OBJS): | $(obj).target/src/libuv/libuv.a + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Default := + +LIBS := + +$(builddir)/run-benchmarks: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(builddir)/run-benchmarks: LIBS := $(LIBS) +$(builddir)/run-benchmarks: LD_INPUTS := $(OBJS) $(obj).target/src/libuv/libuv.a +$(builddir)/run-benchmarks: TOOLSET := $(TOOLSET) +$(builddir)/run-benchmarks: $(OBJS) $(obj).target/src/libuv/libuv.a FORCE_DO_CMD + $(call do_cmd,link) + +all_deps += $(builddir)/run-benchmarks +# Add target alias +.PHONY: run-benchmarks +run-benchmarks: $(builddir)/run-benchmarks + +# Add executable to "all" target. +.PHONY: all +all: $(builddir)/run-benchmarks + diff --git a/mk/libuv/x86_64/freebsd/src/libuv/run-tests.target.mk b/mk/libuv/x86_64/freebsd/src/libuv/run-tests.target.mk new file mode 100644 index 00000000000..7eb08d192d1 --- /dev/null +++ b/mk/libuv/x86_64/freebsd/src/libuv/run-tests.target.mk @@ -0,0 +1,117 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := run-tests +DEFS_Default := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' + +# Flags passed to all source files. +CFLAGS_Default := -pthread + +# Flags passed to only C files. +CFLAGS_C_Default := + +# Flags passed to only C++ files. +CFLAGS_CC_Default := + +INCS_Default := -I$(srcdir)/src/libuv/include + +OBJS := $(obj).target/$(TARGET)/src/libuv/test/blackhole-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/echo-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/run-tests.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-get-loadavg.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-async.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-callback-stack.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-connection-fail.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-delayed-accept.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-fail-always.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-fs.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-fs-event.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-get-currentexe.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-get-memory.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-getaddrinfo.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-gethostbyname.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-getsockname.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-hrtime.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-idle.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-ipc.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-loop-handles.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-multiple-listen.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-pass-always.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-ping-pong.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-pipe-bind-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-pipe-connect-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-ref.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-shutdown-eof.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-spawn.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-stdio-over-pipes.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-bind-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-bind6-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-close.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-flags.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-connect-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-connect6-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-write-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-write-to-half-open-connection.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-writealot.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-threadpool.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-timer-again.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-timer.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tty.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-dgram-too-big.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-ipv6.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-send-and-recv.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-multicast-join.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner-unix.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# Make sure our dependencies are built before any of us. +$(OBJS): | $(obj).target/src/libuv/libuv.a + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Default := + +LIBS := + +$(builddir)/run-tests: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(builddir)/run-tests: LIBS := $(LIBS) +$(builddir)/run-tests: LD_INPUTS := $(OBJS) $(obj).target/src/libuv/libuv.a +$(builddir)/run-tests: TOOLSET := $(TOOLSET) +$(builddir)/run-tests: $(OBJS) $(obj).target/src/libuv/libuv.a FORCE_DO_CMD + $(call do_cmd,link) + +all_deps += $(builddir)/run-tests +# Add target alias +.PHONY: run-tests +run-tests: $(builddir)/run-tests + +# Add executable to "all" target. +.PHONY: all +all: $(builddir)/run-tests + diff --git a/mk/libuv/x86_64/freebsd/src/libuv/uv.Makefile b/mk/libuv/x86_64/freebsd/src/libuv/uv.Makefile new file mode 100644 index 00000000000..3842bae54b9 --- /dev/null +++ b/mk/libuv/x86_64/freebsd/src/libuv/uv.Makefile @@ -0,0 +1,6 @@ +# This file is generated by gyp; do not edit. + +export builddir_name ?= mk/libuv/x86_64/unix/./src/libuv/out +.PHONY: all +all: + $(MAKE) -C ../.. uv run-benchmarks run-tests diff --git a/mk/libuv/x86_64/freebsd/src/libuv/uv.target.mk b/mk/libuv/x86_64/freebsd/src/libuv/uv.target.mk new file mode 100644 index 00000000000..f1b02252a03 --- /dev/null +++ b/mk/libuv/x86_64/freebsd/src/libuv/uv.target.mk @@ -0,0 +1,138 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := uv +DEFS_Default := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' \ + '-DHAVE_CONFIG_H' \ + '-DEV_CONFIG_H="config_freebsd.h"' \ + '-DEIO_CONFIG_H="config_freebsd.h"' + +# Flags passed to all source files. +CFLAGS_Default := -pthread \ + -g \ + --std=gnu89 \ + -pedantic \ + -Wall \ + -Wextra \ + -Wno-unused-parameter + +# Flags passed to only C files. +CFLAGS_C_Default := + +# Flags passed to only C++ files. +CFLAGS_CC_Default := + +INCS_Default := -I$(srcdir)/src/libuv/include \ + -I$(srcdir)/src/libuv/include/uv-private \ + -I$(srcdir)/src/libuv/src \ + -I$(srcdir)/src/libuv/src/unix/ev \ + -I$(srcdir)/src/libuv/src/ares/config_freebsd + +OBJS := $(obj).target/$(TARGET)/src/libuv/src/uv-common.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_cancel.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__close_sockets.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_data.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_destroy.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_expand_name.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_expand_string.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_fds.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_free_hostent.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_free_string.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_gethostbyaddr.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_gethostbyname.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__get_hostent.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_getnameinfo.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_getopt.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_getsock.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_init.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_library_init.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_llist.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_mkquery.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_nowarn.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_options.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_aaaa_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_a_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_mx_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_ns_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_ptr_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_srv_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_txt_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_process.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_query.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__read_line.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_search.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_send.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_strcasecmp.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_strdup.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_strerror.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_timeout.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__timeval.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_version.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_writev.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/bitncmp.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/inet_net_pton.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/inet_ntop.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/windows_port.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/core.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/uv-eio.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/fs.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/udp.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/tcp.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/pipe.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/tty.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/stream.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/cares.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/dl.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/error.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/process.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/eio/eio.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/ev/ev.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/freebsd.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/kqueue.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Default := + +LIBS := -lm + +$(obj).target/src/libuv/libuv.a: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(obj).target/src/libuv/libuv.a: LIBS := $(LIBS) +$(obj).target/src/libuv/libuv.a: TOOLSET := $(TOOLSET) +$(obj).target/src/libuv/libuv.a: $(OBJS) FORCE_DO_CMD + $(call do_cmd,alink) + +all_deps += $(obj).target/src/libuv/libuv.a +# Add target alias +.PHONY: uv +uv: $(obj).target/src/libuv/libuv.a + +# Add target alias to "all" target. +.PHONY: all +all: uv + diff --git a/mk/platform.mk b/mk/platform.mk index da3727c67eb..40a3dd8ebc6 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -24,14 +24,15 @@ endif ifneq ($(findstring freebsd,$(CFG_OSTYPE)),) CFG_LIB_NAME=lib$(1).so CFG_LIB_GLOB=lib$(1)-*.so - CFG_GCCISH_CFLAGS += -fPIC -march=i686 -I/usr/local/include + CFG_GCCISH_CFLAGS += -fPIC -I/usr/local/include CFG_GCCISH_LINK_FLAGS += -shared -fPIC -lpthread -lrt - ifeq ($(CFG_CPUTYPE), x86_64) - CFG_GCCISH_CFLAGS_i386 += -m32 - CFG_GCCISH_LINK_FLAGS_i386 += -m32 - CFG_GCCISH_CFLAGS_x86_64 += -m32 - CFG_GCCISH_LINK_FLAGS_x86_64 += -m32 - endif + CFG_GCCISH_DEF_FLAG := -Wl,--export-dynamic,--dynamic-list= + CFG_GCCISH_PRE_LIB_FLAGS := -Wl,-whole-archive + CFG_GCCISH_POST_LIB_FLAGS := -Wl,-no-whole-archive + CFG_GCCISH_CFLAGS_i386 += -m32 + CFG_GCCISH_LINK_FLAGS_i386 += -m32 + CFG_GCCISH_CFLAGS_x86_64 += -m64 + CFG_GCCISH_LINK_FLAGS_x86_64 += -m64 CFG_UNIXY := 1 CFG_LDENV := LD_LIBRARY_PATH CFG_DEF_SUFFIX := .bsd.def @@ -246,4 +247,4 @@ define CFG_MAKE_ASSEMBLER endef $(foreach target,$(CFG_TARGET_TRIPLES),\ - $(eval $(call CFG_MAKE_ASSEMBLER,$(target)))) \ No newline at end of file + $(eval $(call CFG_MAKE_ASSEMBLER,$(target)))) diff --git a/mk/rt.mk b/mk/rt.mk index a9c35572dc3..2eae4208729 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -119,6 +119,9 @@ ifeq ($$(CFG_WINDOWSY), 1) else ifeq ($(CFG_OSTYPE), apple-darwin) LIBUV_OSTYPE_$(1) := mac LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/libuv.a +else ifeq ($(CFG_OSTYPE), unknown-freebsd) + LIBUV_OSTYPE_$(1) := freebsd + LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/libuv/libuv.a else LIBUV_OSTYPE_$(1) := unix LIBUV_LIB_$(1) := rt/$(1)/libuv/Default/obj.target/src/libuv/libuv.a @@ -174,6 +177,12 @@ $$(LIBUV_LIB_$(1)): $$(wildcard \ # These could go in rt.mk or rustllvm.mk, they're needed for both. # This regexp has a single $, escaped twice +%.bsd.def: %.def.in $$(MKFILE_DEPS) + @$$(call E, def: $$@) + $$(Q)echo "{" > $$@ + $$(Q)sed 's/.$$$$/&;/' $$< >> $$@ + $$(Q)echo "};" >> $$@ + %.linux.def: %.def.in $$(MKFILE_DEPS) @$$(call E, def: $$@) $$(Q)echo "{" > $$@ diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 98917342c2d..34f58b60aa9 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -220,6 +220,7 @@ mod write { } else { FileType = LLVMAssemblyFile; } // Write optimized bitcode if --save-temps was on. + let seg_stack = sess.get_targ_cfg().os != session::os_freebsd; if opts.save_temps { // Always output the bitcode file with --save-temps @@ -244,7 +245,7 @@ mod write { buf_o, LLVMAssemblyFile, CodeGenOptLevel, - true)})}); + seg_stack)})}); } @@ -264,7 +265,7 @@ mod write { buf_o, LLVMObjectFile, CodeGenOptLevel, - true)})}); + seg_stack)})}); } } else { // If we aren't saving temps then just output the file @@ -282,7 +283,7 @@ mod write { buf_o, FileType, CodeGenOptLevel, - true)})}); + seg_stack)})}); } // Clean up and return @@ -566,7 +567,8 @@ fn link_binary(sess: session::session, let rmlib = bind fn (config: @session::config, filename: str) -> str { if config.os == session::os_macos || - config.os == session::os_linux && + (config.os == session::os_linux || + config.os == session::os_freebsd) && str::find(filename, "lib") == 0 { ret str::slice(filename, 3u, str::byte_len(filename)); @@ -580,6 +582,7 @@ fn link_binary(sess: session::session, ret alt config.os { session::os_macos. { rmext(rmlib(filename)) } session::os_linux. { rmext(rmlib(filename)) } + session::os_freebsd. { rmext(rmlib(filename)) } _ { rmext(filename) } }; } @@ -657,6 +660,10 @@ fn link_binary(sess: session::session, gcc_args += ["-lrt", "-ldl"]; } + if sess.get_targ_cfg().os == session::os_freebsd { + gcc_args += ["-lrt"]; + } + // OS X 10.6 introduced 'compact unwind info', which is produced by the // linker from the dwarf unwind info. Unfortunately, it does not seem to // understand how to unwind our __morestack frame, so we have to turn it diff --git a/src/comp/back/rpath.rs b/src/comp/back/rpath.rs index d7eaa083bfb..fccacdcba80 100644 --- a/src/comp/back/rpath.rs +++ b/src/comp/back/rpath.rs @@ -105,6 +105,7 @@ fn get_rpath_relative_to_output(os: session::os, // Mac doesn't appear to support $ORIGIN let prefix = alt os { session::os_linux. { "$ORIGIN" + fs::path_sep() } + session::os_freebsd. { "$ORIGIN" + fs::path_sep() } session::os_macos. { "@executable_path" + fs::path_sep() } }; @@ -191,6 +192,7 @@ fn minimize_rpaths(rpaths: [str]) -> [str] { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] #[cfg(test)] mod test { #[test] @@ -315,6 +317,14 @@ mod test { assert res == "$ORIGIN/../lib"; } + #[test] + #[cfg(target_os = "freebsd")] + fn test_rpath_relative() { + let res = get_rpath_relative_to_output(session::os_freebsd, + "/usr", "bin/rustc", "lib/libstd.so"); + assert res == "$ORIGIN/../lib"; + } + #[test] #[cfg(target_os = "macos")] fn test_rpath_relative() { diff --git a/src/comp/back/x86.rs b/src/comp/back/x86.rs index 1e5b61739d4..6e668b4c967 100644 --- a/src/comp/back/x86.rs +++ b/src/comp/back/x86.rs @@ -8,6 +8,7 @@ fn get_target_strs(target_os: session::os) -> target_strs::t { session::os_macos. { "__DATA,__note.rustc" } session::os_win32. { ".note.rustc" } session::os_linux. { ".note.rustc" } + session::os_freebsd. { ".note.rustc" } }, data_layout: alt target_os { @@ -24,12 +25,17 @@ fn get_target_strs(target_os: session::os) -> target_strs::t { session::os_linux. { "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32" } + + session::os_freebsd. { + "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32" + } }, target_triple: alt target_os { session::os_macos. { "i686-apple-darwin" } session::os_win32. { "i686-pc-mingw32" } session::os_linux. { "i686-unknown-linux-gnu" } + session::os_freebsd. { "i686-unknown-freebsd" } }, gcc_args: ["-m32"] diff --git a/src/comp/back/x86_64.rs b/src/comp/back/x86_64.rs index 98d33d0a8b7..b02910be489 100644 --- a/src/comp/back/x86_64.rs +++ b/src/comp/back/x86_64.rs @@ -8,6 +8,7 @@ fn get_target_strs(target_os: session::os) -> target_strs::t { session::os_macos. { "__DATA,__note.rustc" } session::os_win32. { ".note.rustc" } session::os_linux. { ".note.rustc" } + session::os_freebsd. { ".note.rustc" } }, data_layout: alt target_os { @@ -29,12 +30,19 @@ fn get_target_strs(target_os: session::os) -> target_strs::t { "f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+ "s0:64:64-f80:128:128-n8:16:32:64-S128" } + + session::os_freebsd. { + "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+ + "f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+ + "s0:64:64-f80:128:128-n8:16:32:64-S128" + } }, target_triple: alt target_os { session::os_macos. { "x86_64-apple-darwin" } session::os_win32. { "x86_64-pc-mingw32" } session::os_linux. { "x86_64-unknown-linux-gnu" } + session::os_freebsd. { "x86_64-unknown-freebsd" } }, gcc_args: ["-m64"] diff --git a/src/comp/driver/driver.rs b/src/comp/driver/driver.rs index d67b7bd7cf3..ee8c36c3c8d 100644 --- a/src/comp/driver/driver.rs +++ b/src/comp/driver/driver.rs @@ -26,6 +26,7 @@ fn default_configuration(sess: session::session, argv0: str, input: str) -> session::os_win32. { "msvcrt.dll" } session::os_macos. { "libc.dylib" } session::os_linux. { "libc.so.6" } + session::os_freebsd. { "libc.so.7" } _ { "libc.so" } }; @@ -294,6 +295,8 @@ fn get_os(triple: str) -> session::os { session::os_macos } else if str::find(triple, "linux") >= 0 { session::os_linux + } else if str::find(triple, "freebsd") >= 0 { + session::os_freebsd } else { early_error("Unknown operating system!") }; } diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs index 1bedbf87f7e..55f25a14f1d 100644 --- a/src/comp/driver/session.rs +++ b/src/comp/driver/session.rs @@ -9,7 +9,7 @@ import syntax::parse::parser::parse_sess; import util::filesearch; import back::target_strs; -tag os { os_win32; os_macos; os_linux; } +tag os { os_win32; os_macos; os_linux; os_freebsd; } tag arch { arch_x86; arch_x86_64; arch_arm; } diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 618de096773..2536e2efcb5 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -129,6 +129,7 @@ fn default_native_lib_naming(sess: session::session, static: bool) -> session::os_win32. { ret {prefix: "", suffix: ".dll"}; } session::os_macos. { ret {prefix: "lib", suffix: ".dylib"}; } session::os_linux. { ret {prefix: "lib", suffix: ".so"}; } + session::os_freebsd. { ret {prefix: "lib", suffix: ".so"}; } } } diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 26a9a29b685..a9564f87eb1 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -5152,6 +5152,8 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef, fn main_name() -> str { ret "main"; } #[cfg(target_os = "linux")] fn main_name() -> str { ret "main"; } + #[cfg(target_os = "freebsd")] + fn main_name() -> str { ret "main"; } let llfty = T_fn([ccx.int_type, ccx.int_type], ccx.int_type); let llfn = decl_cdecl_fn(ccx.llmod, main_name(), llfty); let llbb = str::as_buf("top", {|buf| diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index 17f2c739062..39ecb909a85 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -163,6 +163,7 @@ fn maybe_with_lib_path(path: str, f: fn@() -> T) -> T { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] fn maybe_with_lib_path(_path: str, f: fn@() -> T) -> T { f() } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index a97253119fb..fefa9d7e617 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -309,6 +309,7 @@ fn program_output(cx: cx, testfile: str, lib_path: str, prog: str, // Linux and mac don't require adjusting the library search path #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] fn make_cmdline(_libpath: str, prog: str, args: [str]) -> str { #fmt["%s %s", prog, str::connect(args, " ")] } diff --git a/src/compiletest/util.rs b/src/compiletest/util.rs index 6ffe1bda6b8..eb846037482 100644 --- a/src/compiletest/util.rs +++ b/src/compiletest/util.rs @@ -17,6 +17,7 @@ fn make_new_path(path: str) -> str { } #[cfg(target_os = "linux")] +#[cfg(target_os = "freebsd")] fn lib_path_env_var() -> str { "LD_LIBRARY_PATH" } #[cfg(target_os = "macos")] @@ -27,6 +28,7 @@ fn lib_path_env_var() -> str { "PATH" } #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] fn path_div() -> str { ":" } #[cfg(target_os = "win32")] diff --git a/src/libcore/cmath.rs b/src/libcore/cmath.rs index f0fc6f87dc5..d62476a632e 100644 --- a/src/libcore/cmath.rs +++ b/src/libcore/cmath.rs @@ -22,6 +22,9 @@ native mod f64 { #[link_name="log"] pure fn ln(n: f64) -> f64; #[link_name="log1p"] pure fn ln1p(n: f64) -> f64; pure fn log10(n: f64) -> f64; + #[cfg(target_os="linux")] + #[cfg(target_os="macos")] + #[cfg(target_os="win32")] pure fn log2(n: f64) -> f64; pure fn modf(n: f64, iptr: *f64) -> f64; pure fn pow(n: f64, e: f64) -> f64; @@ -56,6 +59,9 @@ native mod f32 { #[link_name="ldexpf"] pure fn ldexp(x: f32, n: c_int) -> f32; #[link_name="logf"] pure fn ln(n: f32) -> f32; #[link_name="log1p"] pure fn ln1p(n: f64) -> f64; + #[cfg(target_os="linux")] + #[cfg(target_os="macos")] + #[cfg(target_os="win32")] #[link_name="log2f"] pure fn log2(n: f32) -> f32; #[link_name="log10f"] pure fn log10(n: f32) -> f32; #[link_name="modff"] pure fn modf(n: f32, iptr: *f32) -> f32; diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs index 41110fbd7f5..a91708580c1 100644 --- a/src/libcore/f32.rs +++ b/src/libcore/f32.rs @@ -114,6 +114,11 @@ mod consts { const ln_10: f32 = 2.30258509299404568401799145468436421f32; } +#[cfg(target_os="freebsd")] +pure fn log2(n: f32) -> f32 { + ret ln(n) / ln(2f32) +} + // // Local Variables: // mode: rust diff --git a/src/libcore/f64.rs b/src/libcore/f64.rs index 7784933f452..73f807a4285 100644 --- a/src/libcore/f64.rs +++ b/src/libcore/f64.rs @@ -114,6 +114,11 @@ mod consts { const ln_10: f64 = 2.30258509299404568401799145468436421f64; } +#[cfg(target_os="freebsd")] +pure fn log2(n: f64) -> f64 { + ret ln(n) / ln(2f64) +} + // // Local Variables: // mode: rust diff --git a/src/libstd/freebsd_os.rs b/src/libstd/freebsd_os.rs new file mode 100644 index 00000000000..4fecf418213 --- /dev/null +++ b/src/libstd/freebsd_os.rs @@ -0,0 +1,155 @@ +/* +Module: os + +TODO: Restructure and document +*/ + +import core::option; +import core::ctypes::*; + +export libc; +export libc_constants; +export pipe; +export fd_FILE; +export close; +export fclose; +export waitpid; +export getcwd; +export exec_suffix; +export target_os; +export dylib_filename; +export get_exe_path; +export fsync_fd; + +// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult +// by https://github.com/graydon/rust/issues#issue/268 + +#[link_name = ""] // FIXME remove after #[nolink] is snapshotted +#[nolink] +#[abi = "cdecl"] +native mod libc { + fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t; + fn write(fd: fd_t, buf: *u8, count: size_t) -> ssize_t; + fn fread(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t; + fn fwrite(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t; + fn open(s: str::sbuf, flags: c_int, mode: unsigned) -> fd_t; + fn close(fd: fd_t) -> c_int; + type FILE; + fn fopen(path: str::sbuf, mode: str::sbuf) -> FILE; + fn fdopen(fd: fd_t, mode: str::sbuf) -> FILE; + fn fclose(f: FILE); + fn fflush(f: FILE) -> c_int; + fn fsync(fd: fd_t) -> c_int; + fn fileno(f: FILE) -> fd_t; + fn fgetc(f: FILE) -> c_int; + fn ungetc(c: c_int, f: FILE); + fn feof(f: FILE) -> c_int; + fn fseek(f: FILE, offset: long, whence: c_int) -> c_int; + fn ftell(f: FILE) -> long; + type dir; + fn opendir(d: str::sbuf) -> dir; + fn closedir(d: dir) -> c_int; + type dirent; + fn readdir(d: dir) -> dirent; + fn getenv(n: str::sbuf) -> str::sbuf; + fn setenv(n: str::sbuf, v: str::sbuf, overwrite: c_int) -> c_int; + fn unsetenv(n: str::sbuf) -> c_int; + fn pipe(buf: *mutable fd_t) -> c_int; + fn waitpid(pid: pid_t, &status: c_int, options: c_int) -> pid_t; + fn readlink(path: str::sbuf, buf: str::sbuf, bufsize: size_t) -> ssize_t; + fn mkdir(path: str::sbuf, mode: c_int) -> c_int; + fn rmdir(path: str::sbuf) -> c_int; + fn chdir(path: str::sbuf) -> c_int; + + fn sysctl(name: *c_int, namelen: c_uint, + oldp: *u8, &oldlenp: size_t, + newp: *u8, newlen: size_t) -> c_int; +} + +mod libc_constants { + const O_RDONLY: c_int = 0i32; + const O_WRONLY: c_int = 1i32; + const O_RDWR: c_int = 2i32; + const O_APPEND: c_int = 8i32; + const O_CREAT: c_int = 512i32; + const O_EXCL: c_int = 2048i32; + const O_TRUNC: c_int = 1024i32; + const O_TEXT: c_int = 0i32; // nonexistent in FreeBSD libc + const O_BINARY: c_int = 0i32; // nonexistent in FreeBSD libc + + const S_IRUSR: unsigned = 256u32; + const S_IWUSR: unsigned = 128u32; + + const CTL_KERN: c_int = 1i32; + const KERN_PROC: c_int = 14i32; + const KERN_PROC_PATHNAME: c_int = 12i32; +} + +fn pipe() -> {in: fd_t, out: fd_t} { + let fds = {mutable in: 0i32, mutable out: 0i32}; + assert (os::libc::pipe(ptr::mut_addr_of(fds.in)) == 0i32); + ret {in: fds.in, out: fds.out}; +} + +fn fd_FILE(fd: fd_t) -> libc::FILE { + ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) }); +} + +fn close(fd: fd_t) -> c_int { + libc::close(fd) +} + +fn fclose(file: libc::FILE) { + libc::fclose(file) +} + +fn fsync_fd(fd: fd_t, _l: io::fsync::level) -> c_int { + ret libc::fsync(fd); +} + +fn waitpid(pid: pid_t) -> i32 { + let status = 0i32; + assert (os::libc::waitpid(pid, status, 0i32) != -1i32); + ret status; +} + +#[abi = "cdecl"] +native mod rustrt { + fn rust_getcwd() -> str; +} + +fn getcwd() -> str { ret rustrt::rust_getcwd(); } + +fn exec_suffix() -> str { ret ""; } + +fn target_os() -> str { ret "freebsd"; } + +fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; } + +/// Returns the directory containing the running program +/// followed by a path separator +fn get_exe_path() -> option::t unsafe { + let bufsize = 1023u; + let path = str::unsafe_from_bytes(vec::init_elt(0u8, bufsize)); + let mib = [libc_constants::CTL_KERN, + libc_constants::KERN_PROC, + libc_constants::KERN_PROC_PATHNAME, -1i32]; + ret str::as_buf(path, { |path_buf| + if libc::sysctl(vec::unsafe::to_ptr(mib), + vec::len(mib) as c_uint, + path_buf, bufsize, + ptr::null(), 0u) == 0i32 { + option::some(fs::dirname(path) + fs::path_sep()) + } else { + option::none + } + }); +} + +// Local Variables: +// mode: rust; +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// End: diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 6c8c614ab55..33030565143 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -148,6 +148,7 @@ fn make_dir(p: path, mode: ctypes::c_int) -> bool { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] fn mkdir(_p: path, _mode: ctypes::c_int) -> bool { ret str::as_buf(_p, {|buf| os::libc::mkdir(buf, _mode) == 0i32 }); } @@ -186,6 +187,7 @@ fn remove_dir(p: path) -> bool { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] fn rmdir(_p: path) -> bool { ret str::as_buf(_p, {|buf| os::libc::rmdir(buf) == 0i32 }); } @@ -201,6 +203,7 @@ fn change_dir(p: path) -> bool { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] fn chdir(_p: path) -> bool { ret str::as_buf(_p, {|buf| os::libc::chdir(buf) == 0i32 }); } @@ -367,6 +370,7 @@ fn normalize(p: path) -> path { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] fn reabsolute(orig: path, new: path) -> path { if path_is_absolute(orig) { path_sep() + new diff --git a/src/libstd/generic_os.rs b/src/libstd/generic_os.rs index babfd0281ba..6ffcb75c977 100644 --- a/src/libstd/generic_os.rs +++ b/src/libstd/generic_os.rs @@ -28,6 +28,7 @@ fn setenv(n: str, v: str) { } #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] fn getenv(n: str) -> option::t unsafe { let s = str::as_buf(n, {|buf| os::libc::getenv(buf) }); ret if unsafe::reinterpret_cast(s) == 0 { @@ -40,6 +41,7 @@ fn getenv(n: str) -> option::t unsafe { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] fn setenv(n: str, v: str) { // FIXME (868) str::as_buf( diff --git a/src/libstd/run_program.rs b/src/libstd/run_program.rs index 55163696579..11bc15d578f 100644 --- a/src/libstd/run_program.rs +++ b/src/libstd/run_program.rs @@ -266,6 +266,7 @@ fn waitpid(pid: pid_t) -> int { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] fn waitpid_os(pid: pid_t) -> int { #[cfg(target_os = "linux")] fn WIFEXITED(status: i32) -> bool { @@ -273,6 +274,7 @@ fn waitpid(pid: pid_t) -> int { } #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] fn WIFEXITED(status: i32) -> bool { (status & 0x7fi32) == 0i32 } @@ -283,6 +285,7 @@ fn waitpid(pid: pid_t) -> int { } #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] fn WEXITSTATUS(status: i32) -> i32 { status >> 8i32 } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index bcd2b82cf1a..8acb1ac9ef9 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -98,6 +98,13 @@ mod os; #[path = "posix_fs.rs"] mod os_fs; +#[cfg(target_os = "freebsd")] +#[path = "freebsd_os.rs"] +mod os; +#[cfg(target_os = "freebsd")] +#[path = "posix_fs.rs"] +mod os_fs; + // Local Variables: // mode: rust; // fill-column: 78; diff --git a/src/libstd/uv.rs b/src/libstd/uv.rs index a12fdc8cecc..b24008448bb 100644 --- a/src/libstd/uv.rs +++ b/src/libstd/uv.rs @@ -5,6 +5,7 @@ the C libuv API. Does very little right now pending scheduler improvements. #[cfg(target_os = "linux")]; #[cfg(target_os = "macos")]; +#[cfg(target_os = "freebsd")]; export sanity_check; export loop_t, idle_t; @@ -39,6 +40,7 @@ type idle_cb = opaque_cb; #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] type handle_private_fields = { a00: ctypes::c_int, a01: ctypes::c_int, @@ -121,6 +123,7 @@ fn sanity_check() { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] +#[cfg(target_os = "freebsd")] fn handle_fields_new() -> handle_fields { { loop: ptr::null(), @@ -149,4 +152,4 @@ fn idle_new() -> idle_t { { fields: handle_fields_new() } -} \ No newline at end of file +} diff --git a/src/rt/arch/i386/ccall.S b/src/rt/arch/i386/ccall.S index a8b89dc6b0f..c04c3e01c7e 100644 --- a/src/rt/arch/i386/ccall.S +++ b/src/rt/arch/i386/ccall.S @@ -16,20 +16,20 @@ ___morestack: __morestack: #endif -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_startproc #endif pushl %ebp -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_def_cfa_offset 8 .cfi_offset %ebp, -8 #endif movl %esp,%ebp // save esp -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_def_cfa_register %ebp #endif @@ -42,6 +42,6 @@ __morestack: ret -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_endproc -#endif \ No newline at end of file +#endif diff --git a/src/rt/arch/i386/morestack.S b/src/rt/arch/i386/morestack.S index 6b2e55022c6..d1433213b2d 100644 --- a/src/rt/arch/i386/morestack.S +++ b/src/rt/arch/i386/morestack.S @@ -72,7 +72,7 @@ #define UPCALL_DEL_STACK L_upcall_del_stack$stub #define MORESTACK ___morestack #else -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #define UPCALL_NEW_STACK upcall_new_stack #define UPCALL_DEL_STACK upcall_del_stack #define RUST_GET_TASK rust_get_task @@ -93,7 +93,7 @@ .globl MORESTACK // FIXME: What about _WIN32? -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) .hidden MORESTACK #else #if defined(__APPLE__) @@ -106,7 +106,7 @@ #endif MORESTACK: -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_startproc #endif @@ -125,7 +125,7 @@ MORESTACK: // __morestack, and an extra return address. pushl %ebp -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) // The CFA is 20 bytes above the register that it is // associated with for this frame (which will be %ebp) .cfi_def_cfa_offset 20 @@ -133,7 +133,7 @@ MORESTACK: .cfi_offset %ebp, -20 #endif movl %esp, %ebp -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) // Calculate the CFA as an offset from %ebp .cfi_def_cfa_register %ebp #endif @@ -216,7 +216,7 @@ MORESTACK: // FIXME: I don't think these rules are necessary // since the unwinder should never encounter an instruction // pointer pointing here. -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) // Restore the rule for how to find %ebp .cfi_restore %ebp // Tell the unwinder how to find the CFA in terms of %esp @@ -234,7 +234,7 @@ MORESTACK: jmpl *%eax -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_endproc #endif diff --git a/src/rt/arch/i386/record_sp.S b/src/rt/arch/i386/record_sp.S index b9c42a650d8..1b698ed74bf 100644 --- a/src/rt/arch/i386/record_sp.S +++ b/src/rt/arch/i386/record_sp.S @@ -14,7 +14,7 @@ .globl GET_SP .globl CHECK_STACK -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) RECORD_SP: movl 4(%esp), %eax movl %eax, %gs:48 diff --git a/src/rt/arch/x86_64/ccall.S b/src/rt/arch/x86_64/ccall.S index c208c7ae643..42415e84a52 100644 --- a/src/rt/arch/x86_64/ccall.S +++ b/src/rt/arch/x86_64/ccall.S @@ -23,19 +23,19 @@ ___morestack: __morestack: #endif -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_startproc #endif push %rbp -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_def_cfa_offset 16 .cfi_offset %rbp, -16 #endif mov %rsp,%rbp // save rsp -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_def_cfa_register %rbp #endif @@ -46,6 +46,6 @@ __morestack: ret -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) .cfi_endproc #endif diff --git a/src/rt/arch/x86_64/context.h b/src/rt/arch/x86_64/context.h index 75902fd7954..b19092c4aa6 100644 --- a/src/rt/arch/x86_64/context.h +++ b/src/rt/arch/x86_64/context.h @@ -31,7 +31,11 @@ extern "C" void __morestack(void *args, void *fn_ptr, uintptr_t stack_ptr); class context { public: +#ifdef __FreeBSD__ + registers_t regs __attribute__(aligned(16)); +#else registers_t regs; +#endif context(); diff --git a/src/rt/arch/x86_64/morestack.S b/src/rt/arch/x86_64/morestack.S index 3f25f786b6c..89ca9d21452 100644 --- a/src/rt/arch/x86_64/morestack.S +++ b/src/rt/arch/x86_64/morestack.S @@ -20,7 +20,7 @@ .globl UPCALL_DEL_STACK .globl MORESTACK -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) .hidden MORESTACK #else #if defined(__APPLE__) @@ -33,7 +33,7 @@ #endif -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) MORESTACK: .cfi_startproc @@ -92,6 +92,9 @@ MORESTACK: #ifdef __linux__ call UPCALL_NEW_STACK@PLT #endif +#ifdef __FreeBSD__ + call UPCALL_NEW_STACK@PLT +#endif // Pop the saved arguments movdqa (%rsp), %xmm0 @@ -135,6 +138,9 @@ MORESTACK: #ifdef __linux__ call UPCALL_DEL_STACK@PLT #endif +#ifdef __FreeBSD__ + call UPCALL_DEL_STACK@PLT +#endif popq %rax // Restore the return value popq %rbp diff --git a/src/rt/arch/x86_64/record_sp.S b/src/rt/arch/x86_64/record_sp.S index af217d0f37f..4330d4cfb76 100644 --- a/src/rt/arch/x86_64/record_sp.S +++ b/src/rt/arch/x86_64/record_sp.S @@ -14,7 +14,7 @@ .globl GET_SP .globl CHECK_STACK -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) RECORD_SP: movq %rdi, %fs:112 ret diff --git a/src/rt/rust_abi.cpp b/src/rt/rust_abi.cpp index e17abde7bd7..b533ab1f673 100644 --- a/src/rt/rust_abi.cpp +++ b/src/rt/rust_abi.cpp @@ -7,7 +7,7 @@ #include #include "rust_abi.h" -#if defined(__APPLE__) || defined(__linux__) +#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__) #define HAVE_DLFCN_H #include #elif defined(_WIN32) diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 2e6c41a8e79..92f24c8c7fa 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -23,6 +23,8 @@ #define RZ_MAC_32 (1024*20) #define RZ_MAC_64 (1024*20) #define RZ_WIN_32 (1024*20) +#define RZ_BSD_32 (1024*20) +#define RZ_BSD_64 (1024*20) #ifdef __linux__ #ifdef __i386__ @@ -48,6 +50,14 @@ #define RED_ZONE_SIZE RZ_WIN_64 #endif #endif +#ifdef __FreeBSD__ +#ifdef __i386__ +#define RED_ZONE_SIZE RZ_BSD_32 +#endif +#ifdef __x86_64__ +#define RED_ZONE_SIZE RZ_BSD_64 +#endif +#endif // A value that goes at the end of the stack and must not be touched const uint8_t stack_canary[] = {0xAB, 0xCD, 0xAB, 0xCD, diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 4eafb8fcbba..7d64842994e 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -20,7 +20,7 @@ // the rust stack and happen frequently enough to catch most stack changes, // including at the beginning of all landing pads. // FIXME: Enable this for windows -#if defined __linux__ || defined __APPLE__ +#if defined __linux__ || defined __APPLE__ || defined __FreeBSD__ extern "C" void check_stack_alignment() __attribute__ ((aligned (16))); #else diff --git a/src/test/run-pass/dupe-first-attr.rc b/src/test/run-pass/dupe-first-attr.rc index 65798b048f9..663bc50fd02 100644 --- a/src/test/run-pass/dupe-first-attr.rc +++ b/src/test/run-pass/dupe-first-attr.rc @@ -8,4 +8,7 @@ mod hello; mod hello; #[cfg(target_os = "win32")] -mod hello; \ No newline at end of file +mod hello; + +#[cfg(target_os = "freebsd")] +mod hello; diff --git a/src/test/run-pass/x86stdcall.rs b/src/test/run-pass/x86stdcall.rs index 765f87de7b2..b9d9b84a526 100644 --- a/src/test/run-pass/x86stdcall.rs +++ b/src/test/run-pass/x86stdcall.rs @@ -19,4 +19,5 @@ fn main() { #[cfg(target_os = "macos")] #[cfg(target_os = "linux")] +#[cfg(target_os = "freebsd")] fn main() { } diff --git a/src/test/run-pass/x86stdcall2.rs b/src/test/run-pass/x86stdcall2.rs index 6c5093a1329..e58656a73a4 100644 --- a/src/test/run-pass/x86stdcall2.rs +++ b/src/test/run-pass/x86stdcall2.rs @@ -24,4 +24,5 @@ fn main() { #[cfg(target_os = "macos")] #[cfg(target_os = "linux")] +#[cfg(target_os = "freebsd")] fn main() { } diff --git a/src/test/stdtest/uv.rs b/src/test/stdtest/uv.rs index 5529ee7a2bb..a7f6e0a8f15 100644 --- a/src/test/stdtest/uv.rs +++ b/src/test/stdtest/uv.rs @@ -1,6 +1,7 @@ #[cfg(target_os = "linux")]; #[cfg(target_os = "macos")]; +#[cfg(target_os = "freebsd")]; import core::*; @@ -44,4 +45,4 @@ mod test_ref { uv::loop_delete(loop); */ } -} \ No newline at end of file +} -- cgit 1.4.1-3-g733a5 From 15be2fc73a4cbed9ac121a91b683812fd3cf1d8a Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 2 Jan 2012 15:31:58 +0100 Subject: Add 'copy' bounds to functions that were faultily accepted without Issue #1390 --- src/libcore/option.rs | 6 +++--- src/libcore/result.rs | 4 ++-- src/libstd/deque.rs | 2 +- src/libstd/util.rs | 2 +- src/test/run-pass/expr-alt-generic-box2.rs | 2 +- src/test/run-pass/expr-alt-generic-unique1.rs | 2 +- src/test/run-pass/expr-alt-generic-unique2.rs | 2 +- src/test/run-pass/expr-alt-generic.rs | 2 +- src/test/run-pass/expr-fn.rs | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index aaaf82eb7cd..e0a137ca9e8 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -36,7 +36,7 @@ pure fn get(opt: t) -> T { /* */ -fn map(opt: t, f: block(T) -> U) -> t { +fn map(opt: t, f: block(T) -> U) -> t { alt opt { some(x) { some(f(x)) } none. { none } } } @@ -61,7 +61,7 @@ Function: from_maybe Returns the contained value or a default */ -pure fn from_maybe(def: T, opt: t) -> T { +pure fn from_maybe(def: T, opt: t) -> T { alt opt { some(x) { x } none. { def } } } @@ -70,7 +70,7 @@ Function: maybe Applies a function to the contained value or returns a default */ -fn maybe(def: U, opt: t, f: block(T) -> U) -> U { +fn maybe(def: U, opt: t, f: block(T) -> U) -> U { alt opt { none. { def } some(t) { f(t) } } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 84fbc3b7f90..91038474ead 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -37,7 +37,7 @@ Failure: If the result is an error */ -fn get(res: t) -> T { +fn get(res: t) -> T { alt res { ok(t) { t } err(_) { @@ -57,7 +57,7 @@ Failure: If the result is not an error */ -fn get_err(res: t) -> U { +fn get_err(res: t) -> U { alt res { err(u) { u } ok(_) { diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 7c0a13bb5f8..8da26c55b10 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -57,7 +57,7 @@ fn create() -> t { ret rv; } - fn get(elts: [mutable cell], i: uint) -> T { + fn get(elts: [mutable cell], i: uint) -> T { ret alt elts[i] { option::some(t) { t } _ { fail } }; } obj deque(mutable nelts: uint, diff --git a/src/libstd/util.rs b/src/libstd/util.rs index a15b5291546..f4d984a8937 100644 --- a/src/libstd/util.rs +++ b/src/libstd/util.rs @@ -7,7 +7,7 @@ Function: id The identity function */ -pure fn id(x: T) -> T { x } +pure fn id(x: T) -> T { x } /* Function: unreachable diff --git a/src/test/run-pass/expr-alt-generic-box2.rs b/src/test/run-pass/expr-alt-generic-box2.rs index 53cab4546e2..bc19200e323 100644 --- a/src/test/run-pass/expr-alt-generic-box2.rs +++ b/src/test/run-pass/expr-alt-generic-box2.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: compare) { let actual: T = alt true { true { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic-unique1.rs b/src/test/run-pass/expr-alt-generic-unique1.rs index e8b949e9410..301d56389b1 100644 --- a/src/test/run-pass/expr-alt-generic-unique1.rs +++ b/src/test/run-pass/expr-alt-generic-unique1.rs @@ -3,7 +3,7 @@ // -*- rust -*- type compare = fn@(~T, ~T) -> bool; -fn test_generic(expected: ~T, eq: compare) { +fn test_generic(expected: ~T, eq: compare) { let actual: ~T = alt true { true { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic-unique2.rs b/src/test/run-pass/expr-alt-generic-unique2.rs index ee0be17ffa2..5640dca0b4e 100644 --- a/src/test/run-pass/expr-alt-generic-unique2.rs +++ b/src/test/run-pass/expr-alt-generic-unique2.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: compare) { let actual: T = alt true { true { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic.rs b/src/test/run-pass/expr-alt-generic.rs index c3df90f7fdc..5a2f7d8b71c 100644 --- a/src/test/run-pass/expr-alt-generic.rs +++ b/src/test/run-pass/expr-alt-generic.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: compare) { let actual: T = alt true { true { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-fn.rs b/src/test/run-pass/expr-fn.rs index 30ba5fa79e4..5cd3f2a178b 100644 --- a/src/test/run-pass/expr-fn.rs +++ b/src/test/run-pass/expr-fn.rs @@ -9,7 +9,7 @@ fn test_vec() { } fn test_generic() { - fn f(t: T) -> T { t } + fn f(t: T) -> T { t } assert (f(10) == 10); } -- cgit 1.4.1-3-g733a5 From 72a3667eb30705826a99bfa2b9478c4037589dbc Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 29 Dec 2011 12:03:39 -0800 Subject: Allow tail expressions even in no_value blocks. Type checker will guarantee they have unit type. --- src/comp/middle/typeck.rs | 41 +++++++++++++++------- src/comp/syntax/parse/eval.rs | 4 +-- src/comp/syntax/parse/parser.rs | 40 ++++++++------------- src/comp/syntax/print/pprust.rs | 32 +++++++++++++++-- src/libstd/rope.rs | 2 +- .../compile-fail/block-must-not-have-result-do.rs | 2 +- .../compile-fail/block-must-not-have-result-for.rs | 2 +- .../compile-fail/block-must-not-have-result-res.rs | 2 +- .../block-must-not-have-result-while.rs | 2 +- src/test/compile-fail/forgot-ret.rs | 2 +- src/test/compile-fail/if-without-else-result.rs | 2 +- src/test/compile-fail/missing-return2.rs | 2 +- src/test/pretty/disamb-stmt-expr.rs | 8 +++++ src/test/run-pass/early-ret-binop-add.rs | 2 +- src/test/run-pass/early-ret-binop.rs | 2 +- src/test/stdtest/os.rs | 7 ++-- 16 files changed, 97 insertions(+), 55 deletions(-) create mode 100644 src/test/pretty/disamb-stmt-expr.rs (limited to 'src/libstd') diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index f5b6f0f736a..9c3c206f593 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1741,7 +1741,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, let element_ty = demand::simple(fcx, local.span, element_ty, ty::mk_var(fcx.ccx.tcx, locid)); let bot = check_decl_local(fcx, local); - check_block(fcx, body); + check_block_no_value(fcx, body); // Unify type of decl with element type of the seq demand::simple(fcx, local.span, ty::node_id_to_type(fcx.ccx.tcx, local.node.id), @@ -1756,22 +1756,27 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, fn check_then_else(fcx: @fn_ctxt, thn: ast::blk, elsopt: option::t<@ast::expr>, id: ast::node_id, _sp: span) -> bool { - let then_bot = check_block(fcx, thn); - let els_bot = false; - let if_t = + let (if_t, if_bot) = alt elsopt { some(els) { + let thn_bot = check_block(fcx, thn); let thn_t = block_ty(fcx.ccx.tcx, thn); - els_bot = check_expr_with(fcx, els, thn_t); - let elsopt_t = expr_ty(fcx.ccx.tcx, els); - if !ty::type_is_bot(fcx.ccx.tcx, elsopt_t) { - elsopt_t - } else { thn_t } + let els_bot = check_expr_with(fcx, els, thn_t); + let els_t = expr_ty(fcx.ccx.tcx, els); + let if_t = if !ty::type_is_bot(fcx.ccx.tcx, els_t) { + els_t + } else { + thn_t + }; + (if_t, thn_bot & els_bot) + } + none. { + check_block_no_value(fcx, thn); + (ty::mk_nil(fcx.ccx.tcx), false) } - none. { ty::mk_nil(fcx.ccx.tcx) } }; write::ty_only_fixup(fcx, id, if_t); - ret then_bot & els_bot; + ret if_bot; } // Checks the compatibility @@ -1993,12 +1998,12 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, } ast::expr_while(cond, body) { bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)); - check_block(fcx, body); + check_block_no_value(fcx, body); write::ty_only_fixup(fcx, id, ty::mk_nil(tcx)); } ast::expr_do_while(body, cond) { bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)) | - check_block(fcx, body); + check_block_no_value(fcx, body); write::ty_only_fixup(fcx, id, block_ty(tcx, body)); } ast::expr_alt(expr, arms) { @@ -2490,6 +2495,16 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool { ret bot; } +fn check_block_no_value(fcx: @fn_ctxt, blk: ast::blk) -> bool { + let bot = check_block(fcx, blk); + if !bot { + let blkty = ty::node_id_to_monotype(fcx.ccx.tcx, blk.node.id); + let nilty = ty::mk_nil(fcx.ccx.tcx); + demand::simple(fcx, blk.span, nilty, blkty); + } + ret bot; +} + fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool { let fcx = alt blk.node.rules { ast::unchecked_blk. { @{purity: ast::impure_fn with *fcx0} } diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs index 1b1713aff33..b13f0cff92a 100644 --- a/src/comp/syntax/parse/eval.rs +++ b/src/comp/syntax/parse/eval.rs @@ -56,10 +56,10 @@ fn parse_companion_mod(cx: ctx, prefix: str, suffix: option::t) -> ([@ast::view_item], [@ast::item], [ast::attribute]) { fn companion_file(prefix: str, suffix: option::t) -> str { - alt suffix { + ret alt suffix { option::some(s) { fs::connect(prefix, s) } option::none. { prefix } - } + ".rs" + } + ".rs"; } fn file_exists(path: str) -> bool { diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 0ce5f8628dc..a1e4ddbe502 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1232,11 +1232,6 @@ fn parse_if_expr_1(p: parser) -> let elexpr = parse_else_expr(p); els = some(elexpr); hi = elexpr.span.hi; - } else if !option::is_none(thn.node.expr) { - let sp = option::get(thn.node.expr).span; - p.span_fatal(sp, "`if` without `else` can not produce a result"); - //TODO: If a suggestion mechanism appears, suggest that the - //user may have forgotten a ';' } ret {cond: cond, then: thn, els: els, lo: lo, hi: hi}; } @@ -1596,32 +1591,29 @@ fn parse_stmt(p: parser) -> @ast::stmt { } fn expr_is_complete(p: parser, e: @ast::expr) -> bool { + log(debug, ("expr_is_complete", p.get_restriction(), + print::pprust::expr_to_str(e), + expr_requires_semi_to_be_stmt(e))); ret p.get_restriction() == RESTRICT_STMT_EXPR && !expr_requires_semi_to_be_stmt(e); } fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { alt e.node { - ast::expr_if(_, th, els) | ast::expr_if_check(_, th, els) { - if option::is_none(els) { false } - else { !option::is_none(th.node.expr) || - expr_requires_semi_to_be_stmt(option::get(els)) } + ast::expr_if(_, _, _) | ast::expr_if_check(_, _, _) + | ast::expr_alt(_, _) | ast::expr_block(_) + | ast::expr_do_while(_, _) | ast::expr_while(_, _) + | ast::expr_for(_, _, _) + | ast::expr_call(_, _, true) { + false } - ast::expr_alt(_, arms) { - vec::any(arms, {|arm| !option::is_none(arm.body.node.expr)}) - } - ast::expr_block(blk) | ast::expr_while(_, blk) | - ast::expr_for(_, _, blk) | ast::expr_do_while(blk, _) { - !option::is_none(blk.node.expr) - } - ast::expr_call(_, _, true) { false } _ { true } } } fn stmt_to_expr(stmt: @ast::stmt) -> option::t<@ast::expr> { alt stmt.node { - ast::stmt_expr(e, _) when expr_requires_semi_to_be_stmt(e) { some(e) } + ast::stmt_expr(e, _) { some(e) } _ { none } } } @@ -1655,14 +1647,10 @@ fn parse_block(p: parser) -> ast::blk { } fn parse_block_no_value(p: parser) -> ast::blk { - let blk = parse_block(p); - if !option::is_none(blk.node.expr) { - let sp = option::get(blk.node.expr).span; - p.span_fatal(sp, "this block must not have a result"); - //TODO: If a suggestion mechanism appears, suggest that the - //user may have forgotten a ';' - } - ret blk; + // We parse blocks that cannot have a value the same as any other block; + // the type checker will make sure that the tail expression (if any) has + // unit type. + ret parse_block(p); } // Precondition: already parsed the '{' or '#{' diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 72e0879e4bf..da592b6d3c1 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -558,11 +558,39 @@ fn print_attribute(s: ps, attr: ast::attribute) { word(s.s, "]"); } +// An expression that begins with a dual-form statement/expression like `{ +// ... }-10` would be parsed as `{ ... };-10` unless parentheses are used (ie, +// `({...}-10)`). These parentheses are not, however, preserved by the +// parser. This function specifies whether parentheses must be inserted. +fn stmt_expr_requires_parens(ex: @ast::expr) -> bool { + fn helper(ex: @ast::expr, inner: bool) -> bool { + alt ex.node { + ast::expr_call(subex, _, _) | ast::expr_binary(_, subex, _) { + be helper(subex, true); + } + _ when !inner { ret false; } + _ { ret !parse::parser::expr_requires_semi_to_be_stmt(ex); } + } + } + ret helper(ex, false); +} + fn print_stmt(s: ps, st: ast::stmt) { maybe_print_comment(s, st.span.lo); alt st.node { - ast::stmt_decl(decl, _) { print_decl(s, decl); } - ast::stmt_expr(expr, _) { space_if_not_bol(s); print_expr(s, expr); } + ast::stmt_decl(decl, _) { + print_decl(s, decl); + } + ast::stmt_expr(expr, _) { + space_if_not_bol(s); + if stmt_expr_requires_parens(expr) { + popen(s); + print_expr(s, expr); + pclose(s); + } else { + print_expr(s, expr); + } + } } if parse::parser::stmt_ends_with_semi(st) { word(s.s, ";"); } maybe_print_trailing_comment(s, st.span, none::); diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index dea9d187110..6b821dc6223 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -443,7 +443,7 @@ fn iter_chars(rope: rope, it: block(char)) { loop_chars(rope) {|x| it(x); ret true - } + }; } /* diff --git a/src/test/compile-fail/block-must-not-have-result-do.rs b/src/test/compile-fail/block-must-not-have-result-do.rs index 7a1a384e64b..f842b0f02b4 100644 --- a/src/test/compile-fail/block-must-not-have-result-do.rs +++ b/src/test/compile-fail/block-must-not-have-result-do.rs @@ -1,4 +1,4 @@ -// error-pattern:this block must not have a result +// error-pattern:mismatched types: expected `()` but found `bool` fn main() { do { diff --git a/src/test/compile-fail/block-must-not-have-result-for.rs b/src/test/compile-fail/block-must-not-have-result-for.rs index 5b5e1fafca2..d2e7edbfc0f 100644 --- a/src/test/compile-fail/block-must-not-have-result-for.rs +++ b/src/test/compile-fail/block-must-not-have-result-for.rs @@ -1,4 +1,4 @@ -// error-pattern:this block must not have a result +// error-pattern:mismatched types: expected `()` but found `bool` fn main() { for i in [0] { diff --git a/src/test/compile-fail/block-must-not-have-result-res.rs b/src/test/compile-fail/block-must-not-have-result-res.rs index 4e0a1a54232..d617aba2fde 100644 --- a/src/test/compile-fail/block-must-not-have-result-res.rs +++ b/src/test/compile-fail/block-must-not-have-result-res.rs @@ -1,4 +1,4 @@ -// error-pattern:this block must not have a result +// error-pattern:mismatched types: expected `()` but found `bool` resource r(i: int) { true diff --git a/src/test/compile-fail/block-must-not-have-result-while.rs b/src/test/compile-fail/block-must-not-have-result-while.rs index d0417fc27ec..7f172998c28 100644 --- a/src/test/compile-fail/block-must-not-have-result-while.rs +++ b/src/test/compile-fail/block-must-not-have-result-while.rs @@ -1,4 +1,4 @@ -// error-pattern:this block must not have a result +// error-pattern:mismatched types: expected `()` but found `bool` fn main() { while true { diff --git a/src/test/compile-fail/forgot-ret.rs b/src/test/compile-fail/forgot-ret.rs index 0f780f1b335..4e422c970c6 100644 --- a/src/test/compile-fail/forgot-ret.rs +++ b/src/test/compile-fail/forgot-ret.rs @@ -3,6 +3,6 @@ fn god_exists(a: int) -> bool { be god_exists(a); } -fn f(a: int) -> int { if god_exists(a) { ret 5; } } +fn f(a: int) -> int { if god_exists(a) { ret 5; }; } fn main() { f(12); } diff --git a/src/test/compile-fail/if-without-else-result.rs b/src/test/compile-fail/if-without-else-result.rs index 0ff469a871c..2454f4f37bf 100644 --- a/src/test/compile-fail/if-without-else-result.rs +++ b/src/test/compile-fail/if-without-else-result.rs @@ -1,4 +1,4 @@ -// error-pattern:`if` without `else` can not produce a result +// error-pattern:mismatched types: expected `()` but found `bool` fn main() { let a = if true { true }; diff --git a/src/test/compile-fail/missing-return2.rs b/src/test/compile-fail/missing-return2.rs index a73db075196..26a9febd3c7 100644 --- a/src/test/compile-fail/missing-return2.rs +++ b/src/test/compile-fail/missing-return2.rs @@ -3,7 +3,7 @@ fn f() -> int { // Make sure typestate doesn't interpret this alt expression // as the function result - alt true { true { } } + alt true { true { } }; } fn main() { } diff --git a/src/test/pretty/disamb-stmt-expr.rs b/src/test/pretty/disamb-stmt-expr.rs new file mode 100644 index 00000000000..5f9d57f94a7 --- /dev/null +++ b/src/test/pretty/disamb-stmt-expr.rs @@ -0,0 +1,8 @@ +// pp-exact + +// Here we check that the parentheses around the body of `wsucc()` are +// preserved. They are needed to disambiguate `{ret n+1}; - 0` from +// `({ret n+1}-0)`. + +fn wsucc(n: int) -> int { ({ ret n + 1 } - 0); } +fn main() { } diff --git a/src/test/run-pass/early-ret-binop-add.rs b/src/test/run-pass/early-ret-binop-add.rs index f7719afc591..21eca8fefac 100644 --- a/src/test/run-pass/early-ret-binop-add.rs +++ b/src/test/run-pass/early-ret-binop-add.rs @@ -1,2 +1,2 @@ -fn wsucc(n: int) -> int { { ret n + 1 } + 0; } +fn wsucc(n: int) -> int { ({ ret n + 1 } + 0); } fn main() { } diff --git a/src/test/run-pass/early-ret-binop.rs b/src/test/run-pass/early-ret-binop.rs index ffa6efb4e80..118bec708b8 100644 --- a/src/test/run-pass/early-ret-binop.rs +++ b/src/test/run-pass/early-ret-binop.rs @@ -1,2 +1,2 @@ -fn wsucc(n: int) -> int { { ret n + 1 } == 0; } +fn wsucc(n: int) -> int { ({ ret n + 1 } == 0); } fn main() { } diff --git a/src/test/stdtest/os.rs b/src/test/stdtest/os.rs index 7f7b2c4f3b3..fd773063e8d 100644 --- a/src/test/stdtest/os.rs +++ b/src/test/stdtest/os.rs @@ -14,6 +14,7 @@ fn test_setenv() { } #[test] +#[ignore(reason = "fails periodically on mac")] fn test_setenv_overwrite() { setenv("NAME2", "1"); setenv("NAME2", "2"); @@ -23,12 +24,14 @@ fn test_setenv_overwrite() { // Windows GetEnvironmentVariable requires some extra work to make sure // the buffer the variable is copied into is the right size #[test] +#[ignore(reason = "fails periodically on mac")] fn test_getenv_big() { let s = ""; let i = 0; while i < 100 { s += "aaaaaaaaaa"; i += 1; } - setenv("NAME3", s); - assert (getenv("NAME3") == option::some(s)); + setenv("test_getenv_big", s); + log(debug, s); + assert (getenv("test_getenv_big") == option::some(s)); } #[test] -- cgit 1.4.1-3-g733a5 From d1ffe5034b341a9a522c01705cafdb19bac9cedb Mon Sep 17 00:00:00 2001 From: Lenny222 Date: Tue, 3 Jan 2012 19:08:13 +0100 Subject: "str": rename "str_from_cstr" to "from_cstr" (analogous to the other "from_*") --- src/comp/back/link.rs | 2 +- src/comp/metadata/creader.rs | 2 +- src/libcore/str.rs | 6 +++--- src/libstd/generic_os.rs | 2 +- src/test/stdtest/str.rs | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/libstd') diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 86974f3f3be..8950618c2e6 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -34,7 +34,7 @@ fn llvm_err(sess: session::session, msg: str) unsafe { let buf = llvm::LLVMRustGetLastError(); if buf == ptr::null() { sess.fatal(msg); - } else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); } + } else { sess.fatal(msg + ": " + str::from_cstr(buf)); } } fn load_intrinsics_bc(sess: session::session) -> option::t { diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 2536e2efcb5..21ead604d31 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -216,7 +216,7 @@ fn get_metadata_section(sess: session::session, let si = mk_section_iter(of.llof); while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False { let name_buf = llvm::LLVMGetSectionName(si.llsi); - let name = unsafe { str::str_from_cstr(name_buf) }; + let name = unsafe { str::from_cstr(name_buf) }; if str::eq(name, sess.get_targ_cfg().target_strs.meta_sect_name) { let cbuf = llvm::LLVMGetSectionContents(si.llsi); let csz = llvm::LLVMGetSectionSize(si.llsi); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 1872d0ae674..cba9b11cb3d 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -12,7 +12,7 @@ export eq, lteq, hash, is_empty, is_not_empty, is_whitespace, byte_len, push_char, is_utf8, from_chars, to_chars, char_len, char_len_range, char_at, bytes, is_ascii, shift_byte, pop_byte, unsafe_from_byte, unsafe_from_bytes, from_char, char_range_at, - str_from_cstr, sbuf, as_buf, push_byte, utf8_char_width, safe_slice, + from_cstr, sbuf, as_buf, push_byte, utf8_char_width, safe_slice, contains, iter_chars, loop_chars, loop_chars_sub, escape; @@ -973,11 +973,11 @@ fn as_buf(s: str, f: block(sbuf) -> T) -> T unsafe { } /* -Function: str_from_cstr +Function: from_cstr Create a Rust string from a null-terminated C string */ -unsafe fn str_from_cstr(cstr: sbuf) -> str { +unsafe fn from_cstr(cstr: sbuf) -> str { let res = ""; let start = cstr; let curr = start; diff --git a/src/libstd/generic_os.rs b/src/libstd/generic_os.rs index 6ffcb75c977..c1312ad4608 100644 --- a/src/libstd/generic_os.rs +++ b/src/libstd/generic_os.rs @@ -35,7 +35,7 @@ fn getenv(n: str) -> option::t unsafe { option::none:: } else { let s = unsafe::reinterpret_cast(s); - option::some::(str::str_from_cstr(s)) + option::some::(str::from_cstr(s)) }; } diff --git a/src/test/stdtest/str.rs b/src/test/stdtest/str.rs index c3f0e53bac5..39217fb8a8b 100644 --- a/src/test/stdtest/str.rs +++ b/src/test/stdtest/str.rs @@ -287,10 +287,10 @@ fn unsafe_from_bytes() { } #[test] -fn str_from_cstr() unsafe { +fn from_cstr() unsafe { let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; let b = vec::to_ptr(a); - let c = str::str_from_cstr(b); + let c = str::from_cstr(b); assert (c == "AAAAAAA"); } @@ -312,7 +312,7 @@ fn as_buf_small() unsafe { fn as_buf2() unsafe { let s = "hello"; let sb = str::as_buf(s, {|b| b }); - let s_cstr = str::str_from_cstr(sb); + let s_cstr = str::from_cstr(sb); assert (str::eq(s_cstr, s)); } -- cgit 1.4.1-3-g733a5