Esempio n. 1
0
 def f(i, j):
     for param, _ in unroll_parameters:
         defl = PARAMETERS[param]
         set_param(jitdriver, param, defl)
     set_param(jitdriver, "threshold", 3)
     set_param(jitdriver, "trace_eagerness", 2)
     total = 0
     frame = Frame(i)
     j = float(j)
     while frame.i > 3:
         jitdriver.can_enter_jit(frame=frame, total=total, j=j)
         jitdriver.jit_merge_point(frame=frame, total=total, j=j)
         total += frame.i
         if frame.i >= 20:
             frame.i -= 2
         frame.i -= 1
         j *= -0.712
         if j + (-j):    raise ValueError
         k = myabs1(myabs2(j))
         if k - abs(j):  raise ValueError
         if k - abs(-j): raise ValueError
         if t.get().nine != 9: raise ValueError
         rposix.set_errno(total)
         if rposix.get_errno() != total: raise ValueError
     return chr(total % 253)
Esempio n. 2
0
def PyOS_string_to_double(space, s, endptr, w_overflow_exception):
    """Convert a string s to a double, raising a Python
    exception on failure.  The set of accepted strings corresponds to
    the set of strings accepted by Python's float() constructor,
    except that s must not have leading or trailing whitespace.
    The conversion is independent of the current locale.

    If endptr is NULL, convert the whole string.  Raise
    ValueError and return -1.0 if the string is not a valid
    representation of a floating-point number.

    If endptr is not NULL, convert as much of the string as
    possible and set *endptr to point to the first unconverted
    character.  If no initial segment of the string is the valid
    representation of a floating-point number, set *endptr to point
    to the beginning of the string, raise ValueError, and return
    -1.0.

    If s represents a value that is too large to store in a float
    (for example, "1e500" is such a string on many platforms) then
    if overflow_exception is NULL return Py_HUGE_VAL (with
    an appropriate sign) and don't set any exception.  Otherwise,
    overflow_exception must point to a Python exception object;
    raise that exception and return -1.0.  In both cases, set
    *endptr to point to the first character after the converted value.

    If any other error occurs during the conversion (for example an
    out-of-memory error), set the appropriate Python exception and
    return -1.0.
    """
    user_endptr = True
    try:
        if not endptr:
            endptr = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
            user_endptr = False
        result = rdtoa.dg_strtod(s, endptr)
        endpos = (rffi.cast(rffi.LONG, endptr[0]) -
                  rffi.cast(rffi.LONG, s))
        if endpos == 0 or (not user_endptr and not endptr[0][0] == '\0'):
            raise OperationError(
                space.w_ValueError,
                space.wrap('invalid input at position %s' % endpos))
        if rposix.get_errno() == errno.ERANGE:
            rposix.set_errno(0)
            if w_overflow_exception is None:
                if result > 0:
                    return rfloat.INFINITY
                else:
                    return -rfloat.INFINITY
            else:
                raise OperationError(w_overflow_exception,
                                     space.wrap('value too large'))
        return result
    finally:
        if not user_endptr:
            lltype.free(endptr, flavor='raw')
Esempio n. 3
0
 def readdir(dirp):
     rposix.set_errno(0)
     direntp = os_readdir(dirp)
     if not direntp:
         if rposix.get_errno() == 0:
             return None
         else:
             raise OSError(rposix.get_errno(), "error in readdir")
     namep = rffi.cast(rffi.CCHARP, direntp.c_d_name)
     return rffi.charp2str(namep)
Esempio n. 4
0
 def readdir(dirp):
     rposix.set_errno(0)
     direntp = os_readdir(dirp)
     if not direntp:
         if rposix.get_errno() == 0:
             return None
         else:
             raise OSError(rposix.get_errno(), "error in readdir")
     namep = rffi.cast(rffi.CCHARP, direntp.c_d_name)
     return rffi.charp2str(namep)
Esempio n. 5
0
    def _sem_timedwait_save(sem, deadline):
        delay = 0
        void = lltype.nullptr(rffi.VOIDP.TO)
        with lltype.scoped_alloc(TIMEVALP.TO, 1) as tvdeadline:
            while True:
                # poll
                if _sem_trywait(sem) == 0:
                    return 0
                elif rposix.get_errno() != errno.EAGAIN:
                    return -1

                now = gettimeofday()
                c_tv_sec = rffi.getintfield(deadline[0], 'c_tv_sec')
                c_tv_nsec = rffi.getintfield(deadline[0], 'c_tv_nsec')
                if (c_tv_sec < now[0] or
                    (c_tv_sec == now[0] and c_tv_nsec <= now[1])):
                    rposix.set_errno(errno.ETIMEDOUT)
                    return -1


                # calculate how much time is left
                difference = ((c_tv_sec - now[0]) * 1000000 +
                                    (c_tv_nsec - now[1]))

                # check delay not too long -- maximum is 20 msecs
                if delay > 20000:
                    delay = 20000
                if delay > difference:
                    delay = difference
                delay += 1000

                # sleep
                rffi.setintfield(tvdeadline[0], 'c_tv_sec', delay / 1000000)
                rffi.setintfield(tvdeadline[0], 'c_tv_usec', delay % 1000000)
                if _select(0, void, void, void, tvdeadline) < 0:
                    return -1
Esempio n. 6
0
 def f():
     set_errno(12)
     return get_errno()
Esempio n. 7
0
File: gil.py Progetto: charred/pypy
def after_external_call():
    e = get_errno()
    rthread.gil_acquire()
    rthread.gc_thread_run()
    after_thread_switch()
    set_errno(e)
Esempio n. 8
0
File: gil.py Progetto: charred/pypy
def before_external_call():
    # this function must not raise, in such a way that the exception
    # transformer knows that it cannot raise!
    e = get_errno()
    rthread.gil_release()
    set_errno(e)
Esempio n. 9
0
def set_errno(space, w_errno):
    rposix.set_errno(space.int_w(w_errno))
Esempio n. 10
0
def _error_reset():
    rposix.set_errno(0)
Esempio n. 11
0
def after_external_call():
    e = get_errno()
    rgil.gil_acquire()
    rthread.gc_thread_run()
    after_thread_switch()
    set_errno(e)