Welcome to MacForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

comp.sys.mac.programmer.codewarrior

 
   Macintosh computer (Home) -> Programmer Code RSS
Next:  Cocoa NSTableView windows in PowerPlant applicati..  
Author Message
Peter Paulus

External


Since: Feb 17, 2004
Posts: 31



(Msg. 1) Posted: Tue Feb 17, 2004 12:11 pm
Post subject: comp.sys.mac.programmer.codewarrior
Archived from groups: comp>sys>mac>programmer>codewarrior (more info?)

Hello all,

I used to have a CodeWarrior 8.3 MacOS 9.2 Shared Library project where I redirected std::cout, and std::err to a custom class, by replacing it's streambuf with rdbuf(). The custom class inherits from std::streambuf and overrides the sync() and overflow() methods. Thus everything that got inserted into std::cout was redirected to my class that displayed it appropriately.

Recently I changed over to a bundle package, MacOS X and CodeWarrior 9.1. Now, whenever I insert something in the outputstream std::cout, I get a read access failure in if (os_.good()) with the follwoing callstack:

QuarkXPress 0x00003800 (PPC) QuarkXPress 0x00003980 (PPC) QuarkXPress 0x00482604 (PPC) QuarkXPress 0x000164B0 (PPC) QuarkXPress 0x003BB738 (PPC) QuarkXPress 0x00530FD0 (PPC) QuarkXPress 0x00530A3C (PPC) QuarkXPress 0x0052FF08 (PPC) QuarkXPress 0x0052F69C (PPC) QuarkXPress 0x0052BBFC (PPC) QuarkXPress 0x0052DB24 (PPC) QuarkXPress 0x00526C30 (PPC) QuarkXPress 0x00526E44 (PPC) Cougar::setup_callback(xtsetuprec*) xpress::xtensions::cougar::ConsoleWAP::ConsoleWAP(long, long) std& std::operator<<<std, char_traits<char> >(basic_ostream<char, std>, basic_ostream, const char*) std::ostream::sentry::sentry(std::ostream&) std::ostream::flush() std::ostream::sentry::sentry(std::ostream&)

I suspect it has something to do with the std::cout not being initialized properly. As far as I know __initialize() took care of that on the MacOS 9 Shared Library. In bundle1.o I cannot find a corresponding call.

All I can find is a source iostream.cpp that contains the definition of std::cout and it's companions.

Can somebody point me in the right direction to solve this issue?

With kind regards,
Peter Paulus

 >> Stay informed about: comp.sys.mac.programmer.codewarrior 
Back to top
Login to vote
MW Ron

External


Since: Aug 04, 2003
Posts: 1662



(Msg. 2) Posted: Tue Feb 17, 2004 2:11 pm
Post subject: Re: comp.sys.mac.programmer.codewarrior [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <4031dab8$0$267$4d4ebb8e@news.nl.uu.net>,
Peter Paulus <peter.paulus RemoveThis @nerocmediaware.nl> wrote:

 >Hello all,
 >
 >I used to have a CodeWarrior 8.3 MacOS 9.2 Shared Library project where I
 >redirected std::cout, and std::err to a custom class, by replacing it's
 >streambuf with rdbuf(). The custom class inherits from std::streambuf and
 >overrides the sync() and overflow() methods. Thus everything that got inserted
 >into std::cout was redirected to my class that displayed it appropriately.
 >
 >Recently I changed over to a bundle package, MacOS X and CodeWarrior 9.1. Now,
 >whenever I insert something in the outputstream std::cout, I get a read access
 >failure in if (os_.good()) with the follwoing callstack:
 >
 >QuarkXPress 0x00003800 (PPC)
 >QuarkXPress 0x00003980 (PPC)
 >QuarkXPress 0x00482604 (PPC)
 >QuarkXPress 0x000164B0 (PPC)
 >QuarkXPress 0x003BB738 (PPC)
 >QuarkXPress 0x00530FD0 (PPC)
 >QuarkXPress 0x00530A3C (PPC)
 >QuarkXPress 0x0052FF08 (PPC)
 >QuarkXPress 0x0052F69C (PPC)
 >QuarkXPress 0x0052BBFC (PPC)
 >QuarkXPress 0x0052DB24 (PPC)
 >QuarkXPress 0x00526C30 (PPC)
 >QuarkXPress 0x00526E44 (PPC)
 >Cougar::setup_callback(xtsetuprec*)
 >xpress::xtensions::cougar::ConsoleWAP::ConsoleWAP(long, long)
 >std& std::operator<<<std, char_traits<char> >(basic_ostream<char, std>,
 >basic_ostream, const char*)
 >std::ostream::sentry::sentry(std::ostream&)
 >std::ostream::flush()
 >std::ostream::sentry::sentry(std::ostream&)
 >
 >
 >I suspect it has something to do with the std::cout not being initialized
 >properly. As far as I know __initialize() took care of that on the MacOS 9
 >Shared Library. In bundle1.o I cannot find a corresponding call.
 >
 >All I can find is a source iostream.cpp that contains the definition of
 >std::cout and it's companions.
 >
 >Can somebody point me in the right direction to solve this issue?

Yeah for bundles you need to set the initialization your self, in the
linker settings be sure to add the init entry point the main entry
point is just a suggestion but the init entry point will be enforced.

See if that doesn't work. If not let us know.

Ron

--

Metrowerks, maker of CodeWarrior - "Software Starts Here"
Ron Liechty - MWRon RemoveThis @metrowerks.com - <http://www.metrowerks.com><!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: comp.sys.mac.programmer.codewarrior 
Back to top
Login to vote
Peter Paulus1

External


Since: Feb 19, 2004
Posts: 6



(Msg. 3) Posted: Thu Feb 19, 2004 8:18 pm
Post subject: Re: comp.sys.mac.programmer.codewarrior [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hello Ron,

Thank you for answering my question twice. I posted the message to soon
and then tried to correct the subject-field. Sorry about that.

I've been trying to find the correct static initialization function for
C++ objects in a MacOS X Bundle Package, but have been unable to find one.

Disassembling /usr/lib/crt1.o I came up with _call_mod_init_funcs. This
object-file is used for applications.

Disassembling /usr/lib/dylib1.o I came up with __initialize_Cplusplus.
This object-file is used for shared libraries.

Disassembling /usr/lib/bundle1.o seems to have no initialization
function. This object-file is used for Bundle Packages. It is the one I
use in this project.

I link against 'MSL_All_Mach-O_D.lib' and 'MSL_Runtime_Mach-O_D.lib'.
The frameworks 'System' and 'Carbon' are included in the project.

Next I've seen functions like
__sinit_/ConsoleWAP.cpp
__register_global_object
__mod_init_func
__ZSt20__msl_ios_base_ninit
__ZSt20__msl_ios_base_winit

when disassembling my ConsoleWAP.cpp.

But whatever I specify at the Init Entry Point in the linker panel, I
get a warning:

Only dynamic libraries and frameworks support initialization (init
routine '_initialize_Cplusplus' ignored.)

And a link-error:
undefined _initialize_Cplusplus

I've tried inserting something into std::cout before it is redirected to
my custom class. This gives the same result.

I've read (parts of) the MachORuntime.pdf from Apple. On page 16 they
mention the static initializers for C++ objects in /usr/lib/crt1.o.

On page 111 /usr/lib/bundle1.o is mentioned. But nothing is said about
the static C++ initializers.

Would you be so kind as to tell me what initialization function can be
used to initialize std::cout (and others) correctly.

With kind regards,
Peter Paulus


MW Ron wrote:

 > In article <4031dab8$0$267$4d4ebb8e@news.nl.uu.net>,
 > Peter Paulus <peter.paulus.TakeThisOut@nerocmediaware.nl> wrote:
 >
 >
  >>Hello all,
  >>
  >>I used to have a CodeWarrior 8.3 MacOS 9.2 Shared Library project where I
  >>redirected std::cout, and std::err to a custom class, by replacing it's
  >>streambuf with rdbuf(). The custom class inherits from std::streambuf and
  >>overrides the sync() and overflow() methods. Thus everything that got inserted
  >>into std::cout was redirected to my class that displayed it appropriately.
  >>
  >>Recently I changed over to a bundle package, MacOS X and CodeWarrior 9.1. Now,
  >>whenever I insert something in the outputstream std::cout, I get a read access
  >>failure in if (os_.good()) with the follwoing callstack:
  >>
  >>QuarkXPress 0x00003800 (PPC)
  >>QuarkXPress 0x00003980 (PPC)
  >>QuarkXPress 0x00482604 (PPC)
  >>QuarkXPress 0x000164B0 (PPC)
  >>QuarkXPress 0x003BB738 (PPC)
  >>QuarkXPress 0x00530FD0 (PPC)
  >>QuarkXPress 0x00530A3C (PPC)
  >>QuarkXPress 0x0052FF08 (PPC)
  >>QuarkXPress 0x0052F69C (PPC)
  >>QuarkXPress 0x0052BBFC (PPC)
  >>QuarkXPress 0x0052DB24 (PPC)
  >>QuarkXPress 0x00526C30 (PPC)
  >>QuarkXPress 0x00526E44 (PPC)
  >>Cougar::setup_callback(xtsetuprec*)
  >>xpress::xtensions::cougar::ConsoleWAP::ConsoleWAP(long, long)
  >>std& std::operator<<<std, char_traits<char> >(basic_ostream<char, std>,
  >>basic_ostream, const char*)
  >>std::ostream::sentry::sentry(std::ostream&)
  >>std::ostream::flush()
  >>std::ostream::sentry::sentry(std::ostream&)
  >>
  >>
  >>I suspect it has something to do with the std::cout not being initialized
  >>properly. As far as I know __initialize() took care of that on the MacOS 9
  >>Shared Library. In bundle1.o I cannot find a corresponding call.
  >>
  >>All I can find is a source iostream.cpp that contains the definition of
  >>std::cout and it's companions.
  >>
  >>Can somebody point me in the right direction to solve this issue?
 >
 >
 > Yeah for bundles you need to set the initialization your self, in the
 > linker settings be sure to add the init entry point the main entry
 > point is just a suggestion but the init entry point will be enforced.
 >
 > See if that doesn't work. If not let us know.
 >
 > Ron
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: comp.sys.mac.programmer.codewarrior 
Back to top
Login to vote
Howard Hinnant

External


Since: Oct 07, 2003
Posts: 123



(Msg. 4) Posted: Thu Feb 19, 2004 11:28 pm
Post subject: Re: comp.sys.mac.programmer.codewarrior [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <4034E1D8.9000508.TakeThisOut@neroc.nl>, Peter Paulus <peter.TakeThisOut@neroc.nl>
wrote:

 > Would you be so kind as to tell me what initialization function can be
 > used to initialize std::cout (and others) correctly.

Try constructing an object of type: std::ios_base::Init

#include <ios>

int main()
{
std::ios_base::Init construct_streams;
}

-Howard<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: comp.sys.mac.programmer.codewarrior 
Back to top
Login to vote
Peter Paulus1

External


Since: Feb 19, 2004
Posts: 6



(Msg. 5) Posted: Fri Feb 20, 2004 2:51 pm
Post subject: Re: comp.sys.mac.programmer.codewarrior [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hello Howard,

Thank you for your suggestion. I've changed my code accordingly. Tracing
into std::ios_base::Init::Init() and then __nInit::__nInit(), I see the
following.

__nInit::ninit_cnt_s equals 13 the first time I reach that codepoint.
Next the block guarded by

if (ninit_cnt_s == 0)
{
new (&cin)istream(&fin);
new (&cout)ostream(&fout);
new (&cerr)ostream(&ferr);
new (&clog)ostream(&ferr);
cin.tie(&cout);
cerr.setf(ios_base::unitbuf);

fin.pubsetbuf(0, 0);
fout.pubsetbuf(0, 0);
ferr.pubsetbuf(0, 0);
}

is skipped. This eventually leads up to the problem I described earlier.

Even when I break at the entry point of the Bundle Package, the Global
Variables dialog tell me that both std::__nInit::ninit_cnt_s and
std::__wInit::winit_cnt_s equal 13.

Looking at lines 54, 55 of MSL/MSL_C++/MSL_Common/Src/iostream.cpp I see
the following:

int __nInit::ninit_cnt_s;
int __wInit::winit_cnt_s;

I would have expected:

int __nInit::ninit_cnt_s = 0;
int __wInit::winit_cnt_s = 0;

So I changed this code to the above. Rebuild the MSL_C++_Mach-O library.
Included MSL_C++_Mach-O.lib, MSL_C_Mach-O.lib and MSL_Runtime_Mach-O.lib

instead of MSL_All_Mach-O.lib.

Now the debugger came up with only assembly, but I think I've located
the 'if (ninit_cnt_s == 0)': (Please bear with me, the last time I did
some serious assembly was in way back in 1985 on a Rockwell 6502)

....
lwz RTOC, 12932(r3)
addi r0, RTOC, 1
cmpwi RTOC, 0x0000
stw r0, 12932(r3)
bne std::__nInit::__nInit()+0x5A800
....

In the Register Window, General Registers, register R0 contains 0x0D.

Note that, after I changed the libraries, in the Gloabel Variables
window, I could not find std::__nInit::ninit_cnt_s and
std::__wInit::winit_cnt_s any more.

Is this where Ron's remarks about the linker initialization point come
into play?

Have you got any more suggestions?

With kind regards,
Peter Paulus

Howard Hinnant wrote:
 > In article <4034E1D8.9000508 RemoveThis @neroc.nl>, Peter Paulus <peter RemoveThis @neroc.nl>
 > wrote:
 >
 >
  >>Would you be so kind as to tell me what initialization function can be
  >>used to initialize std::cout (and others) correctly.
 >
 >
 > Try constructing an object of type: std::ios_base::Init
 >
 > #include <ios>
 >
 > int main()
 > {
 > std::ios_base::Init construct_streams;
 > }
 >
 > -Howard<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: comp.sys.mac.programmer.codewarrior 
Back to top
Login to vote
Howard Hinnant

External


Since: Oct 07, 2003
Posts: 123



(Msg. 6) Posted: Fri Feb 20, 2004 11:32 pm
Post subject: Re: comp.sys.mac.programmer.codewarrior [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <4035e687$0$273$4d4ebb8e@news.nl.uu.net>,
Peter Paulus <peter.DeleteThis@neroc.nl> wrote:

 > So I changed this code to the above. Rebuild the MSL_C++_Mach-O library.
 > Included MSL_C++_Mach-O.lib, MSL_C_Mach-O.lib and MSL_Runtime_Mach-O.lib

Try linking to the debug versions of these (have _D in the name). That
should get you back to source debugging.

 > instead of MSL_All_Mach-O.lib.
 >
 > Now the debugger came up with only assembly, but I think I've located
 > the 'if (ninit_cnt_s == 0)': (Please bear with me, the last time I did
 > some serious assembly was in way back in 1985 on a Rockwell 6502)
 >
 > ...
 > lwz RTOC, 12932(r3)
 > addi r0, RTOC, 1
 > cmpwi RTOC, 0x0000
 > stw r0, 12932(r3)
 > bne std::__nInit::__nInit()+0x5A800
 > ...
 >
 > In the Register Window, General Registers, register R0 contains 0x0D.

It sounds like (in both of your tests) that the stream initialization
code has already been run (13 times in your example). The actual
initialization is done during the first run, and the later ones do
nothing but increment the count.

 > Have you got any more suggestions?

After switching to the debug version of the libraries, set a break point
in the initialization functions, and rerun to convince yourself that the
streams are indeed getting initialized, and walk up the stack to see
who's responsible.

-Howard<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: comp.sys.mac.programmer.codewarrior 
Back to top
Login to vote
Peter Paulus1

External


Since: Feb 19, 2004
Posts: 6



(Msg. 7) Posted: Tue Mar 09, 2004 2:28 pm
Post subject: Re: comp.sys.mac.programmer.codewarrior [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Peter Paulus wrote:
 > Hello all,
 >
 > I used to have a CodeWarrior 8.3 MacOS 9.2 Shared Library project where I redirected std::cout, and std::err to a custom class, by replacing it's streambuf with rdbuf(). The custom class inherits from std::streambuf and overrides the sync() and overflow() methods. Thus everything that got inserted into std::cout was redirected to my class that displayed it appropriately.
 >
 > Recently I changed over to a bundle package, MacOS X and CodeWarrior 9.1. Now, whenever I insert something in the outputstream std::cout, I get a read access failure in if (os_.good()) with the follwoing callstack:
 >
 > QuarkXPress 0x00003800 (PPC)
 > QuarkXPress 0x00003980 (PPC)
 > QuarkXPress 0x00482604 (PPC)
 > QuarkXPress 0x000164B0 (PPC)
 > QuarkXPress 0x003BB738 (PPC)
 > QuarkXPress 0x00530FD0 (PPC)
 > QuarkXPress 0x00530A3C (PPC)
 > QuarkXPress 0x0052FF08 (PPC)
 > QuarkXPress 0x0052F69C (PPC)
 > QuarkXPress 0x0052BBFC (PPC)
 > QuarkXPress 0x0052DB24 (PPC)
 > QuarkXPress 0x00526C30 (PPC)
 > QuarkXPress 0x00526E44 (PPC)
 > Cougar::setup_callback(xtsetuprec*)
 > xpress::xtensions::cougar::ConsoleWAP::ConsoleWAP(long, long)
 > std& std::operator<<<std, char_traits<char> >(basic_ostream<char, std>, basic_ostream, const char*)
 > std::ostream::sentry::sentry(std::ostream&)
 > std::ostream::flush()
 > std::ostream::sentry::sentry(std::ostream&)
 >
 > I suspect it has something to do with the std::cout not being initialized properly. As far as I know __initialize() took care of that on the MacOS 9 Shared Library. In bundle1.o I cannot find a corresponding call.
 >
 > All I can find is a source iostream.cpp that contains the definition of std::cout and it's companions.
 >
 > Can somebody point me in the right direction to solve this issue?
 >
 > With kind regards,
 > Peter Paulus
 >
 >



To eliminate binary compatibility issues, I've recreated my project in
CodeWarrior 8.3 on MacOS 10.2.8. I've now got a single project instead
of a main project with subprojects.

The error still occurs. Not only in std::cout but also in a new
std::ofstream that is dynamically created.

Here is the call-stack during initialization:
QuarkXPress 0x00003800 (PPC)
QuarkXPress 0x00003980 (PPC)
QuarkXPress 0x00482604 (PPC)
QuarkXPress 0x000164B0 (PPC)
QuarkXPress 0x003BB738 (PPC)
QuarkXPress 0x00530F14 (PPC)
QuarkXPress 0x0052FD20 (PPC)
QuarkXPress 0x0052E924 (PPC)
QuarkXPress 0x0052BA1C (PPC)
QuarkXPress 0x0052CF5C (PPC)
CoreFoundation 0x9015CBF4 (PPC)
CoreFoundation 0x9015CFE4 (PPC)
libSystem.B.dylib 0x900169C8 (PPC)
dyld 0x8FE121A4 (PPC)
dyld 0x8FE106F0 (PPC)
dyld 0x8FE160A0 (PPC)
dyld 0x8FE16594 (PPC)
___sinit_:Cougar_cpp
__ZNSt7__nInitC1Ev
__ZNSt13basic_filebufIcNSt11char_traitsIcEEE7seekoffElNSt8ios_base7seekdirENS3_8openmodeE


Using std:cout from a Sample XTension in QuarkXPress did work. But the
sample XTension are all plain C. So I've put extern "C" around all code
and I set 'force compile c++' on.

Has anybody got a clue as to what goes wrong here?

With kind regards,
Peter Paulus<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: comp.sys.mac.programmer.codewarrior 
Back to top
Login to vote
Display posts from previous:   
   Macintosh computer (Home) -> Programmer Code All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]