Peter O'Gorman wrote:

I'd guess that there is a static constructor somewhere in one of the other objects which gets called before main() and does something odd

You had the right idea: As it turns out, the crash does not happen in the main program at all, as I thought before, but inside a static constructor long before main() is run. The precise line in the scribus code is


scribus/scfonts_encoding.cpp:23: if (tf.open(IO_ReadOnly))

It seems that Qt's QFile::open method works differently whether it is run in main() or from a static constructor. Why this would be so, and who is to blame, Qt or Darwin, is way beyond my non-existing C++ knowledge.

As it seems, it is not a bug in Scribus, unless they are doing something illegal that I don't see.

I have reduced the relevant scribus code to the 2 attached small files that show the same behavior: If LANG is set to something non null, the program crashes in the tf.open command and produces the same crash log as scribus does, and if LANG is unset or set to the empty string, it doesn't crash. If instead of LANG, one plays with LC_CTYPE or LC_ALL, one is allowed to set them to "C", but not to anything else non empty.

Also, if the file reading code is taken out of the Foo:foo method and put into main(), the problem disappears. No more bus error, whether LANG is set or not.

Any advice is appreciated.

--
Martin





/***** file qfiletest.h ****/ 

#include <qstring.h>

class Foo
{
 public:
        Foo(){};
        Foo(QString name);
        int foo(QString name);
};

class Bar
{
 public:
        Bar(){};
        static Foo ReadTheFile;
};

/***** file qfiletest.cc
   compile with
   c++ -o qfiletest qfiletest.cc -I/sw/include -I/sw/include/qt -L/sw/lib -lqt-mt
*****/

#include <qfile.h>
#include <qtextstream.h>

#include "qfiletest.h"

#include <iostream>

int Foo::foo(QString name)
{
  QString line;
  QFile tf(name);
  std::cout << "\nBefore open: Filename: " << name << "\n";
  if (tf.open(IO_ReadOnly))
    {
      std::cout << "\nAfter open: 1 line: \n";
      QTextStream t(&tf);
      line=t.readLine();
      tf.close();
      std::cout << line;
      return 0;
    }
  else
    return 1;
}

Foo::Foo(QString name)
{
  foo(name);
}

Foo Bar::ReadTheFile("/sw/include/qt/qmodules.h");

int main()
{
  std::cout << "\n\n Here is main \n";
  return 0;
}

Reply via email to