Commit Graph

112 Commits

Author SHA1 Message Date
Daniel Rodríguez Troitiño
19a1e2c07d [windows] Fix usage of strtof/d/ld function usage.
The error conditions for underflow or overflow weren't being checked,
which caused problems in some tests.
2019-06-06 13:09:15 -07:00
Saleem Abdulrasool
6da949dda7 stdlib: address a compiler warning
Explicit template specialization may not have a storage class.  Remove
the extraneous storage class.
2019-02-28 23:56:12 -08:00
Saleem Abdulrasool
a227273ff4 stdlib: correct floating point parsing behaviour
These are supposed to be processed in the C locale always, irrespective
of the current locale.  We were not doing this and so we would parse the
value incorrectly.
2019-02-28 23:56:12 -08:00
Ben Rimmington
7c65c14df7 [stdlib] Fix memory leaks in readLine()
<https://bugs.swift.org/browse/SR-6127>
2019-02-05 03:43:00 +00:00
Saleem Abdulrasool
1d22ee886c stubs: add workaround for Windows c++ runtime behaviour
The conversion routines in MSVCPRT return "0" for the conversion of
"-inf" et al.  Provde template specializations for `float`, `double`,
and `long double` to use `strtof`, `strtod`, and `strtold` respectively.
This fixes the lossless conversion of floating point constants.
2018-12-27 21:23:01 -08:00
Mike Ash
5391abbf4b [Stdlib] Clean up includes in LibcShims and Random. 2018-10-03 11:16:37 -04:00
Azoy
b8fc8b333c Remove _interface 2018-07-29 10:41:22 -04:00
Saleem Abdulrasool
302ce638eb stubs: silence unused function warning
When building on Linux, the definition of `swift_snprintf_l` would cause
an unused function warning.  Expand the scope of the preprocessor guard
to encompass the function for the single use.  This avoids the unused
function warning.
2018-04-13 18:07:07 -07:00
Saleem Abdulrasool
a34ac086d4 stubs: clean up android support routines
Some of the previously used stubs are no longer needed in newer releases
of the Android API.  Android L and Android O provide the functions in
their associated versions of bionic.  This is needed to build against a
newer version of the SDK.
2018-04-13 18:06:50 -07:00
Saleem Abdulrasool
dfa8a3113f Merge pull request #15912 from compnerd/compiler-rt
stubs: split up compiler-rt routines
2018-04-13 15:15:39 -07:00
Saleem Abdulrasool
9f045add2c stdlib: silence truncation warning on Windows
The returned type `std::streamoff` on Windows x64 is a `long long`
rather than `int`.  This results in a 64-to-32 bit shortening of the
value.  Use the appropriate type to avoid the truncation.

`strlen` returns a unsigned value, but `std::streamoff` is an signed
value.  Explicitly cast the value to avoid the warning about the
implicit signed conversion.
2018-04-13 10:28:17 -07:00
Saleem Abdulrasool
0a1352efff stubs: split up compiler-rt routines
Move the duplicated compiler-rt support routines into its own source
file.  This will need to be expanded for Windows.  As on Linux, there
are certain builtin routines which are not available from the standard
runtime and need to be augmented for now.
2018-04-13 09:44:42 -07:00
tbkka
97a934c412 SR-106: New floating-point description implementation (#15474)
* SR-106: New floating-point `description` implementation

This replaces the current implementation of `description` and
`debugDescription` for the standard floating-point types with a new
formatting routine based on a variation of Florian Loitsch' Grisu2
algorithm with changes suggested by Andrysco, Jhala, and Lerner's 2016
paper describing Errol3.

Unlike the earlier code based on `sprintf` with a fixed number of
digits, this version always chooses the optimal number of digits.  As
such, we can now use the exact same output for both `description` and
`debugDescription` (except of course that `debugDescription` provides
full detail for NaNs).

The implementation has been extensively commented; people familiar with
Grisu-style algorithms should find the code easy to understand.

This implementation is:

* Fast.  It uses only fixed-width integer arithmetic and has constant
  memory and time requirements.

* Simple. It is only a little more complex than Loitsch' original
  implementation of Grisu2.  The digit decomposition logic for double is
  less than 300 lines of standard C (half of which is common arithmetic
  support routines).

* Always Accurate. Converting the decimal form back to binary (using an
  accurate algorithm such as Clinger's) will always yield exactly the
  original binary value.  For the IEEE 754 formats, the round-trip will
  produce exactly the same bit pattern in memory.  This is an essential
  requirement for JSON serialization, debugging, and logging.

* Always Short.  This always selects an accurate result with the minimum
  number of decimal digits.  (So that `1.0 / 10.0` will always print
  `0.1`.)

* Always Close.  Among all accurate, short results, this always chooses
  the result that is closest to the exact floating-point value. (In case
  of an exact tie, it rounds the last digit even.)

This resolves SR-106 and related issues that have complained
about the floating-point `description` properties being inexact.

* Remove duplicate infinity handling

* Use defined(__SIZEOF_INT128__) to detect uint128_t support

* Separate `extracting` the integer part from `clearing` the integer part

The previous code was unnecessarily obfuscated by the attempt to combine
these two operations.

* Use `UINT32_MAX` to mask off 32 bits of a larger integer

* Correct the expected NaN results for 32-bit i386

* Make the C++ exceptions here consistent

Adding a C source file somehow exposed an issue in an unrelated C++ file.
Thanks to Joe Groff for the fix.

* Rename SwiftDtoa to ".cpp"

Having a C file in stdlib/public/runtime causes strange
build failures on Linux in unrelated C++ files.

As a workaround, rename SwiftDtoa.c to .cpp to see
if that avoids the problems.

* Revert "Make the C++ exceptions here consistent"

This reverts commit 6cd5c20566.
2018-04-01 16:52:48 -07:00
Thomas Roughton
7422973c70 [stdlib] Fix bug in Windows FloatingPoint parsing
On `istringstream`, `tellg()` returns -1 if the stream is at the end of the file. This indicates success in this circumstance, so we should update `pos` to reflect that the whole string has been read.

NFC on platforms other than Windows, Cygwin, and Haiku.
2018-02-13 18:50:15 +13:00
David Zarzycki
6a93b07cfb NFC: Use standardized locale header
On Linux, glibc removed xlocale.h, which was non-standard.
2017-11-25 13:09:06 -05:00
David Zarzycki
56a3aa97ac [Cross compile] Add missing standard include from C++ 2017-11-11 14:55:15 -05:00
Greg Parker
bba9d4c652 [runtime] Delete unused _swift_fmod*().
These were once used by some func %() implementations.
2017-10-24 02:22:01 -07:00
Calvin Hill
aee81d272f Add Initial platform support for Haiku. (#11583) 2017-09-22 21:06:56 -04:00
Saleem Abdulrasool
8b3bff8277 stubs: match return type to header declaration
Because of differences in the definition of ssize_t, swift uses
`__swift_ssize_t` in the headers.  Make the definition match the
declaration.  NFC.
2017-07-18 10:36:23 -07:00
Joe Groff
101788dbd4 IRGen: Support for computed properties with dependent generic context.
Use the KeyPath implementation's new support for instantiating and dealing with captures to lower the generic context required to dispatch computed accessors with dependent generics.
2017-07-06 20:07:41 -07:00
David Hart
66131c01d3 [SR-2626] Fix String to Float/Double “snan” conversion (#8036)
Adds an explicit check for `[+-]snan` to create an sNaN from a string.
2017-03-13 21:07:31 -04:00
Gonzalo Larralde
85f3fd1ebf [SR-4166] Change on how __mode__ attribute presence is checked to fix compilation issue. 2017-03-05 21:23:39 -03:00
Hugh Bellamy
6564a8b3b5 Use std::thread::hardware_concurrency instead of our own solution 2017-02-21 11:46:32 +07:00
Hugh Bellamy
3a96ded085 Don't use certain attributes in shims or stubs if the attribute doesn't exist 2017-02-20 10:16:30 +07:00
Hugh Bellamy
05a50fd978 Remove extern "C" from uses of SWIFT_RUNTIME_STDLIB_INTERFACE 2017-01-22 18:32:17 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Hugh Bellamy
eca5b3da34 Change _MSC_VER conditions to _WIN32 conditions in stubs 2016-12-13 14:15:39 +00:00
Saleem Abdulrasool
d4b5ceabfd stubs: match types in the stubs
The various uses where using `unsigned char` rather than `char`.  Adjust the one
instance accordingly.  Noticed when building the stubs for Windows.
2016-11-27 17:01:39 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Andrew Trick
0b75ee975e Remove "illegal" UnsafePointer casts from the stdlib.
Update for SE-0107: UnsafeRawPointer

This adds a "mutating" initialize to UnsafePointer to make
Immutable -> Mutable conversions explicit.

These are quick fixes to stdlib, overlays, and test cases that are necessary
in order to remove arbitrary UnsafePointer conversions.

Many cases can be expressed better up by reworking the surrounding
code, but we first need a working starting point.
2016-07-28 20:42:23 -07:00
practicalswift
7e89679404 [gardening] Fix recently introduced typos. 2016-07-24 22:32:40 +02:00
Saleem Abdulrasool
5e170ebcb5 build: support cross-compiling to windows 2016-07-13 21:37:04 -07:00
Saleem Abdulrasool
e3c2c863d1 stdlib: define WIN32_LEAN_AND_MEAN and NOMINMAX
`WIN32_LEAN_AND_MEAN` prevents "rarely-used" headers from being pulled in.  This
significantly reduced preprocessor pressure, speeding up compile.  It also
reduces the amount of cruft pulled in by the Windows.h.

`NOMINMAX` ensures that the `min` and `max` macros are not defined.  These
macros collide with the use of `min` and `max` from C++ in certain cases: e.g.
`std::limits<T>`.
2016-06-16 07:34:17 -07:00
Han Sangjin
e6ecc9a3ec Modified for some reviews 2016-06-10 06:26:47 +09:00
Han Sangjin
198441bee9 stdlib/msvc: Runtime with MSVC library
This patch is for libswiftCore.lib, linking with the library set of Visual Studio 2015. Clang with the option -fms-extension is used to build.
2016-06-04 05:16:41 +09:00
Bryan Chan
85fde8b1fb Add support for Linux s390x. LLVM's Swift calling convention support is used to ensure correct operations of C++ code in the runtime. This patch also includes some (incomplete) changes to enum handling to make enums work in most common cases. 2016-05-24 20:03:28 -04:00
Saleem Abdulrasool
81661fca61 stdlib: use the reserved attribute spellings
This is a purely mechanical change replacing the attributes with the reserved
spelling.  Compilers are to not error when they encounter a reserved spelling
for an attribute which they do not support.
2016-05-11 11:30:24 -07:00
John McCall
50d58b2732 Add a lot of calling-convention annotations to the standard library / runtime.
The general rule here is that something needs to be SWIFT_CC(swift)
if it's just declared in Swift code using _silgen_name, as opposed to
importing something via a header.

Of course, SWIFT_CC(swift) expands to nothing by default for now, and
I haven't made an effort yet to add the indirect-result / context
parameter ABI attributes.  This is just a best-effort first pass.

I also took the opportunity to shift a few files to just implement
their shims header and to demote a few things to be private stdlib
interfaces.
2016-05-04 10:31:23 -07:00
Zhuowei Zhang
7c502b6344 Port to Android
This adds an Android target for the stdlib. It is also the first
example of cross-compiling outside of Darwin.

Mailing list discussions:

1. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151207/000171.html
2. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000492.html

The Android variant of Swift may be built using the following `build-script`
invocation:

```
$ utils/build-script \
  -R \                                           # Build in ReleaseAssert mode.
  --android \                                    # Build for Android.
  --android-ndk ~/android-ndk-r10e \             # Path to an Android NDK.
  --android-ndk-version 21 \
  --android-icu-uc ~/libicu-android/armeabi-v7a/libicuuc.so \
  --android-icu-uc-include ~/libicu-android/armeabi-v7a/icu/source/common \
  --android-icu-i18n ~/libicu-android/armeabi-v7a/libicui18n.so \
  --android-icu-i18n-include ~/libicu-android/armeabi-v7a/icu/source/i18n/
```

Android builds have the following dependencies, as can be seen in
the build script invocation:

1. An Android NDK of version 21 or greater, available to download
   here: http://developer.android.com/ndk/downloads/index.html.
2. A libicu compatible with android-armv7.
2016-04-12 19:26:21 -04:00
practicalswift
ea0ac3ac67 [gardening] Remove all tabs in C++ code 2016-04-08 21:22:57 +02:00
Nadav Rotem
6a11924038 Revert "Revert "Build the Swift runtime using the locally built clang compliler."" 2016-03-30 17:26:35 -07:00
Nadav Rotem
0c1a8f308a Revert "Build the Swift runtime using the locally built clang compliler." 2016-03-30 11:08:21 -07:00
Nadav Rotem
dab0095932 Don't build muloti4 on Apple-ARM64.
It looks like it's already included in:
lib/clang/3.8.0/lib/darwin/libclang_rt.ios.a(muloti4.c.o)
2016-03-29 14:29:32 -07:00
practicalswift
b61b6c8f42 [gardening] Fix two recently introduced accidental double spaces 2016-02-23 16:53:17 +01:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
Joe Groff
f7291b21ec Runtime: Build with -fvisibility=hidden.
...and explicitly mark symbols we export, either for use by executables or for runtime-stdlib interaction. Until the stdlib supports resilience we have to allow programs to link to these SPI symbols.
2016-02-08 08:06:02 -08:00
Anton Blanchard
b1827d8a8f Add powerpc64le Linux support
This patch adds powerpc64le Linux support. While the patch also adds
the matching powerpc64 bits, there are endian issues that need to be
sorted out.

The PowerPC LLVM changes for the swift ABI (eg returning three element
non-homogeneous aggregates) are still in the works, but a simple LLVM
fix to allow those aggregates results in swift passing all but 8
test cases.
2016-01-15 06:48:31 +00:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Daniel Duan
ae601d2744 replace NULL with nullptr 2015-12-20 13:28:21 -08:00