[comp.lang.c++] multiple instances of NIL object using NIHCL

kgorlen@alw.nih.gov (Keith Gorlen) (12/07/90)

In article <1335@fang.dsto.oz>, dch@aeg.dsto.oz.au (Dave Hanslip) writes:
|> 
|> We are running SunOs 4.1 on Sparcstation 1's and 1+'s and using Sun's C++
|> compiler version 2.0.
|> 
|> When we initially compiled the NIH class libraries we found that we could not
|> get them to work unless we removed the _main.o from libnihcl.a and used as the first line of our main
|> 
|> NIHCL::Initialize()
|> 
|> This seemed to work fine, but we are now running into troubles with what we believe to be multiple instances of the NIL object.

By this do you mean that Object::Nil changes at some point while your program is running?  If so, this is a known NIHCL R3.0 bug, see attachment for the patch.

|> When _main is left in libnihcl.a it seems that it never gets activated.
|> 
|> We cannot find any meaningful or useful references to _main.C in the Sun
|> manuals.
|> 
|> Has anybody had any experience with using a custom version of _main?
|> 
|> Has anybody else followed the same path as us and can advise?
|> 
|> Should we be looking somewhere else for the problem?
|> 
|> Any help would be appreciated.
|> 
|> David C. Hanslip                              E-mail: dch@aeg.dsto.oz.au
|> Aeronautical Research Laboratory              Phone: +61 8 259 5792
|> DSTO Salisbury, South Australia               Fax: +61 8 259 5507

Sorry, I can't help with the _main problem--it works with Sun R2.0 under SunOS 4.0.3, and we're not running 4.1 here yet.

-- 
	Keith Gorlen			phone: (301) 496-1111
	Building 12A, Room 2033		uucp: uunet!kgorlen%alw.nih.gov
	National Institutes of Health	Internet: kgorlen@alw.nih.gov
	Bethesda, MD 20892

*** /tmp/,RCSt1a07168	Fri Nov  2 16:46:26 1990
--- Object.h	Fri Nov  2 13:58:23 1990
***************
*** 108,116 ****
  inline unsigned int	MIN(unsigned int a, unsigned int b)	{ return a <= b ? a : b; }
  inline unsigned long	MIN(unsigned long a, unsigned long b)	{ return a <= b ? a : b; }
  
! static class NIHCL {
  private:			// static member variables
- 	static int initCount;		// see NIHCL::NIHCL() and NIHCL::~NIHCL()
  	static bool init;		// YES if NIHCL initialization complete
  	static unsigned char	char_bit_mask[sizeof(char)*8];
  	static unsigned short	short_bit_mask[sizeof(short)*8];
--- 108,117 ----
  inline unsigned int	MIN(unsigned int a, unsigned int b)	{ return a <= b ? a : b; }
  inline unsigned long	MIN(unsigned long a, unsigned long b)	{ return a <= b ? a : b; }
  
! class NIHCLInitialize;
! 
! class NIHCL {
  private:			// static member variables
  	static bool init;		// YES if NIHCL initialization complete
  	static unsigned char	char_bit_mask[sizeof(char)*8];
  	static unsigned short	short_bit_mask[sizeof(short)*8];
***************
*** 119,127 ****
  	static unsigned char	bit_reverse[256];
  private:			// static member functions
  	static void initTables();	// initialize tables
  public:				// static member functions
- 	NIHCL();
- 	~NIHCL();
  	static unsigned	char charBitMask(int i)		{ return char_bit_mask[i]; }
  	static unsigned	short shortBitMask(int i)	{ return short_bit_mask[i]; }
  	static unsigned	int intBitMask(int i)		{ return int_bit_mask[i]; }
--- 120,127 ----
  	static unsigned char	bit_reverse[256];
  private:			// static member functions
  	static void initTables();	// initialize tables
+ 	friend NIHCLInitialize;
  public:				// static member functions
  	static unsigned	char charBitMask(int i)		{ return char_bit_mask[i]; }
  	static unsigned	short shortBitMask(int i)	{ return short_bit_mask[i]; }
  	static unsigned	int intBitMask(int i)		{ return int_bit_mask[i]; }
***************
*** 130,135 ****
--- 130,141 ----
  	static void initialize();	// library initialization
  	static bool initialized()	{ return init; }
  	static void setError(int error, int sev ...);	// set an NIHCL error condition
+ };
+ 
+ static class NIHCLInitialize : public NIHCL {
+ 	static int initCount;
+ public:
+ 	NIHCLInitialize();
  } NIHCL_init;
  
  class ClassList : public NIHCL {
*** /tmp/,RCSt1a07174	Fri Nov  2 16:49:12 1990
--- Nil.c	Tue Oct 30 11:51:06 1990
***************
*** 38,44 ****
  	Nil() {}
  	virtual int compare(const Object&) const; // compare objects 
  	virtual Object* copy() const;		// copy returns nil 
- 	virtual Object* deepCopy();		// copy returns nil 
  	virtual void dumpOn(ostream& strm =cerr) const;
  	virtual unsigned hash() const;		// calculate object hash 
  	virtual bool isEqual(const Object&) const;	// equality test 
--- 38,43 ----
***************
*** 51,57 ****
  
  extern const int NIHCL_RDUNKCLASS;
  
! Object*	const Object::nil = 0;	    // initialized by NIHCL::NIHCL()
  
  #define	THIS	Nil
  #define	BASE	Object
--- 50,56 ----
  
  extern const int NIHCL_RDUNKCLASS;
  
! Object*	const Object::nil = 0;	    // initialized by NIHCLInitialize::NIHCLInitialize()
  
  #define	THIS	Nil
  #define	BASE	Object
***************
*** 78,85 ****
  
  Object* Nil::copy() const { return nil; }
  
- Object* Nil::deepCopy() { return nil; }
- 
  void Nil::dumpOn(ostream& strm) const { strm << "NIL"; }
  
  void Nil::printOn(ostream& strm) const { strm << "NIL"; }
--- 77,82 ----
***************
*** 110,116 ****
  
  #include <errlib.h>
  
! int NIHCL::initCount = 0;
  bool NIHCL::init = NO;
  unsigned char NIHCL::char_bit_mask[sizeof(char)*8];
  unsigned short NIHCL::short_bit_mask[sizeof(short)*8];
--- 107,113 ----
  
  #include <errlib.h>
  
! int NIHCLInitialize::initCount = 0;
  bool NIHCL::init = NO;
  unsigned char NIHCL::char_bit_mask[sizeof(char)*8];
  unsigned short NIHCL::short_bit_mask[sizeof(short)*8];
***************
*** 150,156 ****
  
  extern void NIHCL__errinit();	// error facility initializer for NIHCL
  
! NIHCL::NIHCL()
  // Called once for every module that includes Object.h
  {
  	if (initCount++) return;
--- 147,153 ----
  
  extern void NIHCL__errinit();	// error facility initializer for NIHCL
  
! NIHCLInitialize::NIHCLInitialize()
  // Called once for every module that includes Object.h
  {
  	if (initCount++) return;
***************
*** 159,170 ****
  	initTables();				// initialize NIHCL tables
  	Object** nilp = (Object**)&Object::nil;	// create the nil object and
  	*nilp = new Nil;			// initialize the pointer to it	
- }
- 
- NIHCL::~NIHCL()
- // Called once for every module that includes Object.h
- {
- 	if (--initCount) return;
  }
  
  void NIHCL::initialize()	// NIHCL initialization, called once from _main 
--- 156,161 ----

dch@aeg.dsto.oz.au (Dave Hanslip) (12/07/90)

We are running SunOs 4.1 on Sparcstation 1's and 1+'s and using Sun's C++
compiler version 2.0.

When we initially compiled the NIH class libraries we found that we could not
get them to work unless we removed the _main.o from libnihcl.a and used as the first line of our main

NIHCL::Initialize()

This seemed to work fine, but we are now running into troubles with what we believe to be multiple instances of the NIL object.

When _main is left in libnihcl.a it seems that it never gets activated.

We cannot find any meaningful or useful references to _main.C in the Sun
manuals.

Has anybody had any experience with using a custom version of _main?

Has anybody else followed the same path as us and can advise?

Should we be looking somewhere else for the problem?

Any help would be appreciated.

David C. Hanslip                              E-mail: dch@aeg.dsto.oz.au
Aeronautical Research Laboratory              Phone: +61 8 259 5792
DSTO Salisbury, South Australia               Fax: +61 8 259 5507