summary refs log tree commit diff stats
path: root/lib/pure/asyncftpclient.nim
Commit message (Expand)AuthorAgeFilesLines
* Merge branch 'asyncftp-add-removeDir' of https://github.com/pyloor/Nim into p...Dominik Picheta2016-09-251-0/+6
|\
| * Asyncftpclient: adding removeDir procpyloor2016-09-211-0/+6
* | Merge branch 'asyncftp-add-removeFile' of https://github.com/pyloor/Nim into ...Dominik Picheta2016-09-251-0/+6
|\ \
| * | adding a test for removing a filepyloor2016-09-211-0/+2
| * | adding removeFile proc to asyncftpclientpyloor2016-09-211-0/+4
| |/
* / adding rename proc to asyncftpclientpyloor2016-09-211-0/+7
|/
* fix missing procvar pragmapyloor2016-09-161-1/+1
* fixes calling convention for the callbacksAndreas Rumpf2016-01-081-2/+2
* Added examples to asyncftpclient module.Dominik Picheta2015-09-171-12/+63
* Moved handling of multi-line FTP replies to `expectReply`.Dominik Picheta2015-07-011-5/+14
* remove unnecessary functionLuca2015-06-271-1/+1
* Remove redundant 220 checkLuca2015-06-271-4/+3
* Allow AsyncFtpClient and ftpclient to check 220 messagesLuca2015-06-261-1/+7
* Don't run non-test code when defined(testing)Oleh Prypin2015-04-211-1/+1
* Use `^` instead of `-` in slicesdef2015-03-281-2/+2
* Fix a few more warningsdef2015-02-171-3/+3
* Happy new year!Guillaume Gelin2015-01-061-1/+1
* Lots of documentation improvements for asyncdispatch.Dominik Picheta2014-09-121-0/+18
* 'nimfix' improvements; FdSet is TFdSet againAraq2014-09-081-1/+1
* s/storeFile/store/Dominik Picheta2014-08-311-2/+2
* Case fixes for network modules.Dominik Picheta2014-08-301-39/+39
* Add asyncftpclient module.Dominik Picheta2014-08-291-0/+295
id='n93' href='#n93'>93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
126
127
128
129
130
131
132













                                                   
                                                

                                                
                                               


                                                                 
                                           






































































































                                                                             
                                                                     


                                                                
                                                                     
       
                                                                        
#
#
#            Nim's Runtime Library
#        (c) Copyright 2020 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# Integer arithmetic with overflow checking. Uses
# intrinsics or inline assembler.

proc raiseOverflow {.compilerproc, noinline.} =
  # a single proc to reduce code size to a minimum
  sysFatal(OverflowDefect, "over- or underflow")

proc raiseDivByZero {.compilerproc, noinline.} =
  sysFatal(DivByZeroDefect, "division by zero")

{.pragma: nimbaseH, importc, nodecl, noSideEffect, compilerproc.}

when not defined(nimEmulateOverflowChecks):
  # take the #define from nimbase.h

  proc nimAddInt(a, b: int, res: ptr int): bool {.nimbaseH.}
  proc nimSubInt(a, b: int, res: ptr int): bool {.nimbaseH.}
  proc nimMulInt(a, b: int, res: ptr int): bool {.nimbaseH.}

  proc nimAddInt64(a, b: int64; res: ptr int64): bool {.nimbaseH.}
  proc nimSubInt64(a, b: int64; res: ptr int64): bool {.nimbaseH.}
  proc nimMulInt64(a, b: int64; res: ptr int64): bool {.nimbaseH.}

# unary minus and 'abs' not required here anymore and are directly handled
# in the code generator.
# 'nimModInt' does exist in nimbase.h without check as we moved the
# check for 0 to the codgen.
proc nimModInt(a, b: int; res: ptr int): bool {.nimbaseH.}

proc nimModInt64(a, b: int64; res: ptr int64): bool {.nimbaseH.}

# Platform independent versions.

template addImplFallback(name, T, U) {.dirty.} =
  when not declared(name):
    proc name(a, b: T; res: ptr T): bool {.compilerproc, inline.} =
      let r = cast[T](cast[U](a) + cast[U](b))
      if (r xor a) >= T(0) or (r xor b) >= T(0):
        res[] = r
      else:
        result = true

addImplFallback(nimAddInt, int, uint)
addImplFallback(nimAddInt64, int64, uint64)

template subImplFallback(name, T, U) {.dirty.} =
  when not declared(name):
    proc name(a, b: T; res: ptr T): bool {.compilerproc, inline.} =
      let r = cast[T](cast[U](a) - cast[U](b))
      if (r xor a) >= 0 or (r xor not b) >= 0:
        res[] = r
      else:
        result = true

subImplFallback(nimSubInt, int, uint)
subImplFallback(nimSubInt64, int64, uint64)

template mulImplFallback(name, T, U, conv) {.dirty.} =
  #
  # This code has been inspired by Python's source code.
  # The native int product x*y is either exactly right or *way* off, being
  # just the last n bits of the true product, where n is the number of bits
  # in an int (the delivered product is the true product plus i*2**n for
  # some integer i).
  #
  # The native float64 product x*y is subject to three
  # rounding errors: on a sizeof(int)==8 box, each cast to double can lose
  # info, and even on a sizeof(int)==4 box, the multiplication can lose info.
  # But, unlike the native int product, it's not in *range* trouble:  even
  # if sizeof(int)==32 (256-bit ints), the product easily fits in the
  # dynamic range of a float64. So the leading 50 (or so) bits of the float64
  # product are correct.
  #
  # We check these two ways against each other, and declare victory if
  # they're approximately the same. Else, because the native int product is
  # the only one that can lose catastrophic amounts of information, it's the
  # native int product that must have overflowed.
  #
  when not declared(name):
    proc name(a, b: T; res: ptr T): bool {.compilerproc, inline.} =
      let r = cast[T](cast[U](a) * cast[U](b))
      let floatProd = conv(a) * conv(b)
      let resAsFloat = conv(r)
      # Fast path for normal case: small multiplicands, and no info
      # is lost in either method.
      if resAsFloat == floatProd:
        res[] = r
      else:
        # Somebody somewhere lost info. Close enough, or way off? Note
        # that a != 0 and b != 0 (else resAsFloat == floatProd == 0).
        # The difference either is or isn't significant compared to the
        # true value (of which floatProd is a good approximation).

        # abs(diff)/abs(prod) <= 1/32 iff
        #   32 * abs(diff) <= abs(prod) -- 5 good bits is "close enough"
        if 32.0 * abs(resAsFloat - floatProd) <= abs(floatProd):
          res[] = r
        else:
          result = true

mulImplFallback(nimMulInt, int, uint, toFloat)
mulImplFallback(nimMulInt64, int64, uint64, toBiggestFloat)


template divImplFallback(name, T) {.dirty.} =
  proc name(a, b: T; res: ptr T): bool {.compilerproc, inline.} =
    # we moved the b == 0 case out into the codegen.
    if a == low(T) and b == T(-1):
      result = true
    else:
      res[] = a div b

divImplFallback(nimDivInt, int)
divImplFallback(nimDivInt64, int64)

proc raiseFloatInvalidOp {.compilerproc, noinline.} =
  sysFatal(FloatInvalidOpDefect, "FPU operation caused a NaN result")

proc raiseFloatOverflow(x: float64) {.compilerproc, noinline.} =
  if x > 0.0:
    sysFatal(FloatOverflowDefect, "FPU operation caused an overflow")
  else:
    sysFatal(FloatUnderflowDefect, "FPU operations caused an underflow")