Quantcast

Infinite loop on x86_64 platform with 64bit target

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Infinite loop on x86_64 platform with 64bit target

Harro Verkouter

Hi all,

I am using Spirit (jeez you'd propably never guessed that ..) however my
g++ is ending up in an infinite loop when I try to compile for a 64bit
target. If a compile the same file for a 32bit target on the same
machine, all's well.

It may be because of the construct I have used. I've added some stuff to
enable parsing a comma separated list of numbers and/or ranges, where a
'range' is <number>-<number> (to emphasize that 'range' in this context
is not range as in the predefined 'range_p' parser).

I'm compiling with g++-3.3.2 on an Opteron running a 64bit Linux 2.4.25
kernel. More detail info is in the attached 'infinite-loop.txt' file
(output of uname en g++ -v amongst others).

Anyone else having seen this before? Googling turned up nothing, nor did
searching the mail-archive - unless I haven't searched carefully enough.

Maybe I should use a different approach? I havent' come up with an
alternative yet. I'm open to suggestions!

Any help would be greatly appreciated - I prefer not to run 32bit code
on my 64bit machine - no use in not using half the CPU :/ ;)


I include the source of the file I'm trying to compile below.

Thanks for your attention so far,

Harro Verkouter


infinite-loop.cc :

// c++ crud
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>

// spirit stuff
#include <boost/spirit/core.hpp>
#include <boost/spirit/utility.hpp>
#include <boost/spirit/symbols.hpp>


using namespace std;
using namespace boost::spirit;

//
// The grammar for a list
// of ints and ranges of ints
//
struct ilist_grammar:
        public grammar<ilist_grammar>
{
        template <typename ScannerT>
        struct definition
        {
                rule<ScannerT>    line, range, entry;
               
                definition( ilist_grammar const& self )
                {
                        // if a 'range' is parsed,
                        // it sets the range start, range end
                        // and finally insert [start,end) into
                        // the list
                        range       = (int_p[assign(self.r_start)] >> '-'
                                                        >> int_p[assign(self.r_end)])[self.ranger];
                        // if the int_p is parsed, the integer
                        // is automagically appended to the list
                        entry       = range|int_p[append(self.iList)];
                        line        = entry >> *(',' >> entry);
                }

                rule<ScannerT> const& start( void ) const
                {
                        return line;
                }
        };


        struct ranger_t
        {
                // we don't actually use the iterators (in this case)
                // this is supposed to be triggered when a range is
                // parsed and this will append the range to the
                // result and clear the range for the next range
                template <typename IteratorT>
                void operator()( IteratorT , IteratorT ) const
                {
                        if( parent )
                        {
                                while( parent->r_start<=parent->r_end )
                                {
                                        parent->iList.push_back(parent->r_start);
                                        ++parent->r_start;
                                }
                                // reset
                                parent->r_start = 0;
                                parent->r_end   = 0;
                        }
                        return;
                }

                ranger_t() :
                        parent( 0 )
                {
                }

                ranger_t( ilist_grammar* p ) :
                        parent( p )
                {
                }

                ilist_grammar*   parent;
        };

        mutable int         r_start, r_end;
        // this functor is used to be able to process a parsed range
        // the void operator()( iterator start, iterator end ) const
        // is called - this method will process the range
        mutable ranger_t    ranger;
        mutable vector<int> iList;

        ilist_grammar() :
                ranger( this )
        {
        }
};

//
// this parses a list of integers and ranges of integers
// into a vector.
// The vector is uniquefied and sorted
// before it's given back to the user
//
bool parse_list( const char* s, vector<int>& v )
{
        bool           rv;
        ilist_grammar  lg;
               
        if( (rv=parse(s, lg, space_p).full)==true )
        {
                vector<int>::iterator  uniqptr;

                v = lg.iList;

                // sort + make unique?
                sort( v.begin(), v.end() );

                uniqptr = unique( v.begin(), v.end() );

                v.erase( uniqptr, v.end() );
        }
        return rv;
}

int main( int , char** )
{
        string      s;
        vector<int> vi;

        cout << "Enter a list of numbers/ranges: ";
        cin >> s;

        if( !parse_list(s.c_str(), vi) )
        {
                cout << "Syntax error." << endl;
                return -1;
        }
        cout << "You entered:\n";
        copy(vi.begin(), vi.end(), ostream_iterator<int>(cout, ","));

        return 0;
}







-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Loading...