bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

syntax coloring tight-loop bug


From: Tim Love
Subject: syntax coloring tight-loop bug
Date: Fri, 14 Apr 2006 10:52:53 +0100 (BST)

This bug report will be sent to the Free Software Foundation,
not to your local site managers!
Please write in English, because the Emacs maintainers do not have
translators to read other languages for them.

Your bug report will be posted to the address@hidden mailing list,
and to the gnu.emacs.bug news group.

In GNU Emacs 21.3.1 (hppa2.0w-hp-hpux11.11, Motif Version 2.1.0)
 of 2003-07-15 on last
configured using `configure  --with-gcc=no --prefix=/opt/emacs-21.3 
--with-x-toolkit=motif --x-includes=/usr/include/Motif2.1 
--x-libraries=/usr/lib/Motif2.1'
Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: C
  locale-coding-system: nil
  default-enable-multibyte-characters: t

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:


With certain C++ files, users can input characters that cause the emacs
window to freeze while emacs uses all available CPU. It's repeatable on 
HP-UX (details above) and on SuSE 10.0 with Gnu Emacs 21.3.1.

Here's a repeat-by
* Load the text below into buffer (apologies for the length)
* append  " (" to the "if (volume ==0)" line
* wait a second or 2 for the file to be recolorized

--- snip here ---
// OurTradingFunctions2.cc
// File containing function definitions written for part 2

// Standard library header files
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vogle.h>
#include <vogleextras.h>
#include <trading.h>

// User-defined constants, data structures and function prototypes
#include "OurTradingHeader.h"


using namespace std;
// Function to initialise trading account and connect to exchange
void InitialiseAccount(int dataSet, int labGroup, TradingAccount &account)
{
   int ec, day= 0;

   // Set data members of TradingAccount structure for day = 0
   account.today = day;
   account.price[day] = 20.0;
   account.transaction[day] = TT_PASS;
   account.volume[day] = 0;
   account.stock[day] = 0;
   account.balance[day] = 20000.0;

   // Call trading library function and handle exit (return) code
   ec = TE_InitialiseTrading(dataSet, labGroup);
   HandleExitCode(ec);



}

// Function definition to display error messages from trading exchange
// The program is terminated with exit(-1) if there is an error
void HandleExitCode(int errorCode)
{
   switch(errorCode)
   {
      case TE_OKAY:
         break;

      case TE_FAIL:
         cout << "Trading error: bad parameter." << endl;
         exit(-1);

      case TE_ALREADY_CONNECTED:
         cout << "Trading error: already connected to server." << endl;
         exit(-1);

      case TE_NOT_CONNECTED:
         cout << "Trading error: not connected to server." << endl;
         exit(-1);

      case TE_AUTH_FAILED:
         cout << "Trading error: authorisation failed." << endl;
         exit(-1);

      case TE_TOO_EARLY:
         cout << "Trading error: must agree price every day." << endl;
         exit(-1);

      case TE_TOO_LATE:
         cout << "Trading error: transaction already made for today." << endl;
         exit(-1);

      case TE_NO_FUNDS:
         cout << "Trading error: insufficient funds for purchase." << endl;
         exit(-1);

      case TE_NO_STOCK:
         cout << "Trading error: insufficient stock for sale." << endl;
         exit(-1);

      default:
         cout << "Trading error: trading system failure." << endl;
         exit(-1);
  }
}
//Gets todays price and calls the decision making function

void MyTrader(TradingAccount &account ModelData data)


{

  int ec, i, volume;


for (int i=1; i<51; i++)
{

     ec =  TE_GetPrice(i, account.price[i]);
    //loops through 50 days

     HandleExitCode(ec);
     //checks for a valid return code
     account.today = i;

     MakeDecision1(account,volume);

     ec =  TE_Trade(account.transaction[account.today], volume);

     HandleExitCode(ec);

     UpdateAccount(account,volume);
 }


}

int MakeDecision2(TradingAccount &account, int &volume, ModelData data)
{

  float PricePred, PriceAct, Square, M;

  PricePred = data.a + (data.b*(account.today+100));
  //predicted price from bet fit line for this day
  PriceAct = account.price[i];
  //actual price
  Square = (PricePred - PriceAct)*(PricePred - PriceAct);
  //difference sqaured to compare to variance
  M = 20/(data.variance)
    //gradient of model line for volume to buy or sell
  volume = M*Square
    //model line





    //dec buy sell pass
    if (volume == 0)

{

 account.transaction[account.today]=0

}

    else  if ((PricePred - PriceAct) > 0)
{
account.transaction[account.today] = 1
}

    else ((PricePred - PriceAct) < 0)
      {

account.transaction[account.today] = -1
      }


}



int MakeDecision1(TradingAccount &account, int &volume)

{

  if(account.today == 50)
    {
    account.transaction[account.today] = 1;
    volume = 1000;
    }
  else
    {
      account.transaction[account.today] = 0;
      volume = 0;
    }


  return volume;

}


void UpdateAccount(TradingAccount &account, int volume)

{
  account.volume[account.today] = volume;

  account.stock[account.today] = account.stock[(account.today) - 1]
+(volume*(account.transaction[account.today]));

  account.balance[account.today] = account.balance[(account.today) - 1] -(
(account.price[account.today]) * volume * account.transaction[account.today]);

}



void CloseAccount(TradingAccount &account)

{

  int ec, finalstock;
  float finalbalance;

  ec = TE_CloseTrading(finalbalance, finalstock);

  HandleExitCode(ec);

  cout << "Our final Balance is" << account.balance[50] << endl;

  cout << "Our Final Stock is" << account.stock[50] << endl;

  cout << finalbalance << endl;
  cout << finalstock << endl;

}


void writeresults(TradingAccount account)

{

  ofstream fout;

  fout.open("output.dat");
  if (fout.good())
    {

      fout << "Price  Transaction  Volume  Stock  Balance" << endl;

for (int i=1; i<51; i++)
  {
      fout << account.price[i] << "    ";
      fout << account.transaction[i]<<"          ";
      fout << account.volume[i]<<"    ";
      fout << account.stock[i]<<"      ";
      fout << account.balance[i]<<"       "<<endl;
  }
    } // brace for if
  else
    {

      cout << "Cannot open file";
    }

}


--- snip here ---





reply via email to

[Prev in Thread] Current Thread [Next in Thread]