delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-apps/2001/05/17/13:43:49

Mailing-List: contact cygwin-apps-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-apps-owner AT sourceware DOT cygnus DOT com
List-Subscribe: <mailto:cygwin-apps-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-apps/>
List-Post: <mailto:cygwin-apps AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-apps-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/lists.html#faqs>
Delivered-To: mailing list cygwin-apps AT sources DOT redhat DOT com
Date: Thu, 17 May 2001 13:41:52 -0400
From: Christopher Faylor <cgf AT redhat DOT com>
To: cygwin-apps <cygwin-apps AT cygwin DOT com>
Subject: Re: [PATCH] Don't use context to mark initialised variables as dllimport
Message-ID: <20010517134152.G1496@redhat.com>
Reply-To: cygwin-apps AT cygwin DOT com
Mail-Followup-To: cygwin-apps <cygwin-apps AT cygwin DOT com>
References: <20010517100006 DOT 21057 DOT qmail AT web6405 DOT mail DOT yahoo DOT com>
Mime-Version: 1.0
User-Agent: Mutt/1.3.11i
In-Reply-To: <20010517100006.21057.qmail@web6405.mail.yahoo.com>; from danny_r_smith_2001@yahoo.co.nz on Thu, May 17, 2001 at 08:00:06PM +1000

I already have this applied to my sources from the last time you
submitted it.

cgf

On Thu, May 17, 2001 at 08:00:06PM +1000, Danny Smith wrote:
>This is a  patch to gcc-2.95.3-4 (cygwin special).
> 
>Static constant initialisation of data in C++ classes works when
>linking
>statically, but not with dllimported classes. 
>
>The following code is used to build dll:
>
>dllclass.h
>======================================
>#if BUILDING_DLL
># define DLLIMPORT __declspec (dllexport)
>#else /* Not BUILDING_DLL */
># define DLLIMPORT __declspec (dllimport)
>#endif /* Not BUILDING_DLL */
>
>class DLLIMPORT 
>DllClass {
>public:
>  DllClass(); 
>  unsigned int a_method () const;
>  static int non_const_int;	/* initialised in dllclass.cc */
>  static const unsigned int const_int=256;
>  char buffer[const_int];  
>};
>==========================================
>
>dllclass.cc
>===========================================
>#include "dllclass.h"
>#include <string.h>
>DllClass::DllClass(){
>  memset(buffer,0,const_int); 
>}
>
>unsigned int 
>DllClass::a_method () const { 
>  return const_int;
>}
>int
>DllClass::non_const_int;
>
>============================================
>
>Dll build correctly.
>non_const_int is exported as DATA.
>const_int is not exported. That's fine.
>
>This is client code:
>usedll.cc
>=========================================
>#include <stdio.h>
>#include "dllclass.h"
>
>int main () {
>  DllClass A;
>  printf("a_method = %d\n", A.a_method());
>}
>==========================================
>
>This fails to compile with error:
>dllclass.h:13: initialized variable `const int DllClass::const_int' is
>marked dllimport.
>
>This error is emitted by i386_pe_mark_dllimport(), not long after
>i386_pe_dllimport_p() automatically puts the dllimport there in the
>first place.
>
>
>In this case, (integral const), one workaround is the enum hack.
>-  static const unsigned int const_int=256;
>+  enum {const_int=256};
>
>
>The problem occurs because class members get the dllimport status
>of their class, without first checking if they are initialised inline
>(eg as for  static consts).
>
>The following  patch to gcc/config/i386/winnt.c fixes the problem.
>I have tested with STLport, which uses static const initialisation of
>fmtflags (in ios_base) and locale categories and elsewhere.
>
>
>ChangeLog
>
>2001-05-17  Danny Smith  <danny_r_smith_2001 AT yahoo DOT com DOT nz
>
>	* gcc/config/i386/winnt.c (i386_pe_dllimport_p): Don't use 
>	context to mark initialised variables as dllimport.
>
>
>--- gcc/config/i386/winnt.c.orig	Wed Jan 19 19:30:10 2000
>+++ gcc/config/i386/winnt.c	Tue Mar 27 22:03:47 2001
>@@ -250,6 +250,11 @@ i386_pe_dllimport_p (decl)
>   context = associated_type (decl);
>   if (context)
>     {
>+    /* Don't use context to mark initialised variables as dllimport */
>+      if (TREE_CODE (decl) == VAR_DECL
>+        && (DECL_INITIAL (decl)
>+          && ! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))  
>+        return 0;
>       imp = lookup_attribute ("dllimport",
> 			      TYPE_ATTRIBUTES (context));
>       if (imp)
>
>Danny
>
>
>
>_____________________________________________________________________________
>http://messenger.yahoo.com.au - Yahoo! Messenger
>- Voice chat, mail alerts, stock quotes and favourite news and lots more!

-- 
cgf AT cygnus DOT com                        Red Hat, Inc.
http://sources.redhat.com/            http://www.redhat.com/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019