stdcxx-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <j...@apache.org>
Subject [jira] Commented: (STDCXX-901) 26.class.gslice test fails
Date Tue, 03 Jun 2008 01:22:45 GMT

    [ https://issues.apache.org/jira/browse/STDCXX-901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12601804#action_12601804
] 

Martin Sebor commented on STDCXX-901:
-------------------------------------

This is from the binary incompatible rewrite of {{valarray}} that I've been mentioning for
eons (I should finally commit it on trunk). If it fixes this bug it might spark an idea for
a compatible fix...

{noformat}
// 26.3.6 - generalized slice of a valarray
class _RWSTD_EXPORT gslice
{
public:

    // 26.3.6.1
    gslice (): _C_imp (0) { /* no-op */ }

    gslice (_RWSTD_SIZE_T,
            const valarray<_RWSTD_SIZE_T>&,
            const valarray<_RWSTD_SIZE_T>&);

    gslice (const gslice&);

    ~gslice ();

    gslice& operator= (const gslice&);

    // 26.3.6.2
    _RWSTD_SIZE_T start () const {
        return _C_imp ? _C_imp->_C_start : 0;
    }

    valarray<_RWSTD_SIZE_T> size () const {
        return _C_imp ? _C_imp->_C_length : valarray<_RWSTD_SIZE_T>();
    }

    valarray<_RWSTD_SIZE_T> stride () const {
        return _C_imp ? _C_imp->_C_stride : valarray<_RWSTD_SIZE_T>();
    }

    const _RWSTD_SIZE_T _C_size () const {
        return _C_imp ? _C_imp->_C_inxs.size () : 0;
    }

    const valarray<_RWSTD_SIZE_T>& _C_indices () const {
        _RWSTD_ASSERT (0 != _C_imp);
        return _C_imp->_C_inxs;
    }

private:

    // referenced counted gslice implementation for efficiency
    struct _Imp {
        _Imp (_RWSTD_SIZE_T,
              const valarray<_RWSTD_SIZE_T>&,
              const valarray<_RWSTD_SIZE_T>&);

        valarray<_RWSTD_SIZE_T> _C_length;   // set of lengths (sizes equal)
        valarray<_RWSTD_SIZE_T> _C_stride;   // set of strides (sizes equal)
        valarray<_RWSTD_SIZE_T> _C_inxs;     // cached array of indices
        _RWSTD_SIZE_T           _C_start;    // starting offset
        _RWSTD_SIZE_T           _C_refs;     // reference count

    private:
        _Imp (const _Imp&);            // not copyable
        void operator=(const _Imp&);   // not assignable
    };

    _Imp *_C_imp;   // reference-counted implementation or 0
};


gslice::_Imp::
_Imp (size_t                  beg,
      const valarray<size_t>& len,
      const valarray<size_t>& str)
    : _C_length (len),
    _C_stride (str),
    _C_inxs (/* initialized below */),
    _C_start (beg),
    _C_refs (0)
{
    _RWSTD_ASSERT (_C_length.size () == _C_stride.size ());

    // compute the number of indices represented by this slice
    // and store it for later so that the expensive computation
    // need only be done at most once
    const size_t length = _C_length.size ();

    if (0 == length)
        return;

    size_t nelems = 1;

    for (size_t i = 0; i != length; ++i) {
        nelems *= _C_length [i];
    }

    _C_inxs.resize (nelems);

    size_t small_cache [256];
    const size_t cache_size = sizeof small_cache / sizeof *small_cache;

    size_t* const cache =
        length < cache_size ? small_cache : new size_t [length];

    memset (cache, 0, length * sizeof *cache);

    _C_inxs [0] = _C_start;

    for (size_t i = 1; i < nelems; ++i) {

        size_t inx = length;

        while (inx && cache [inx - 1] == _C_length [inx - 1] - 1)
            --inx;

        _RWSTD_ASSERT (0 != inx);

        ++cache [inx - 1];
        if (inx < length)
            memset (cache + inx, 0, (length - inx) * sizeof *cache);

        _C_inxs [i] = _C_start;

        for (size_t j = 0; j != inx; ++j)
            _C_inxs [i] += cache [j] * _C_stride [j];
    }

    if (cache != small_cache)
        delete[] cache;
}


gslice::
gslice (size_t                  beg,
        const valarray<size_t>& len,
        const valarray<size_t>& str)
    : _C_imp (new _Imp (beg, len, str))
{
    // no-op
}


gslice::
gslice (const gslice &rhs)
    : _C_imp (rhs._C_imp)
{
    if (_C_imp)
        _RWSTD_ATOMIC_PREINCREMENT (_C_imp->_C_refs, false);
}


gslice::
~gslice ()
{
    if (_C_imp && 0 == _RWSTD_ATOMIC_PREDECREMENT (_C_imp->_C_refs, false))
        delete _C_imp;
}


gslice& gslice::
operator= (const gslice &rhs)
{
    if (_C_imp && 0 == _RWSTD_ATOMIC_PREDECREMENT (_C_imp->_C_refs, false))
        delete _C_imp;

    if (rhs._C_imp)
        _RWSTD_ATOMIC_PREINCREMENT (_C_imp->_C_refs, false);

    return *this;
}
{noformat}

> 26.class.gslice test fails
> --------------------------
>
>                 Key: STDCXX-901
>                 URL: https://issues.apache.org/jira/browse/STDCXX-901
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: Tests
>    Affects Versions: 4.2.0, 4.2.1
>         Environment: MSVC
>            Reporter: Farid Zaripov
>            Assignee: Travis Vitek
>            Priority: Minor
>             Fix For: 4.2.2
>
>          Time Spent: 6h
>  Remaining Estimate: 0h
>
> The 26.class.gslice test fails with the 162 similar assertions:
> {noformat}
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 1: expected 1, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 1: expected 1, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 1: expected 1, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 2: expected 2, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 2: expected 2, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 2: expected 2, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 3: expected 3, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 3: expected 3, got 0
> # ASSERTION (S7) (5 lines):
> # TEXT: mismatch at 0, index 3: expected 3, got 0
> ...
> {noformat}
>   I'm not found the opened issue for gslice, so maybe this is another bug in gslice class
or maybe the test itself is incorrect.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message