From owner-freebsd-current@FreeBSD.ORG Wed Jul 11 02:22:19 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DA5E716A474 for ; Wed, 11 Jul 2007 02:22:19 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (c220-239-20-82.belrs4.nsw.optusnet.com.au [220.239.20.82]) by mx1.freebsd.org (Postfix) with ESMTP id 4376C13C45A for ; Wed, 11 Jul 2007 02:22:18 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by turion.vk2pj.dyndns.org (8.14.1/8.14.1) with ESMTP id l6B2MHHc020141; Wed, 11 Jul 2007 12:22:17 +1000 (EST) (envelope-from peter@turion.vk2pj.dyndns.org) Received: (from peter@localhost) by turion.vk2pj.dyndns.org (8.14.1/8.14.1/Submit) id l6B2MHAe020140; Wed, 11 Jul 2007 12:22:17 +1000 (EST) (envelope-from peter) Date: Wed, 11 Jul 2007 12:22:17 +1000 From: Peter Jeremy To: Andrey Chernov , freebsd-current@freebsd.org Message-ID: <20070711022217.GA19840@turion.vk2pj.dyndns.org> References: <20070703182400.Q1449@baba.farley.org> <20070709145418.T52164@thor.farley.org> <20070710154148.GA22873@nagual.pp.ru> <20070710213602.GX3434@turion.vk2pj.dyndns.org> <20070710224619.GA31654@nagual.pp.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jRHKVT23PllUwdXP" Content-Disposition: inline In-Reply-To: <20070710224619.GA31654@nagual.pp.ru> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.16 (2007-06-09) Cc: Subject: Re: HEADS UP: getenv() and family API change X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jul 2007 02:22:19 -0000 --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2007-Jul-11 02:46:19 +0400, Andrey Chernov wrote: >On Wed, Jul 11, 2007 at 07:36:02AM +1000, Peter Jeremy wrote: >> On 2007-Jul-10 19:41:48 +0400, Andrey Chernov wrote: >> >To say strictly, copying somewhere is not neccessary since this way wor= ks=20 >> >too: >> > >> >static char *s =3D "PATH=3D/bin"; >> > >> >putenv(s); >>=20 >> I thought the C compiler was still free to place the string into RO >> memory and/or coalesce it with other strings in that case. >>=20 >> Wouldn't the following be clearer (s is forced to be writable): >>=20 >> static char s[] =3D "PATH=3D/bin"; >>=20 >> putenv(s); > >This two are the same, since there is no "const", so compiler can't put=20 >static char *s >into RO memory. Maybe that's the theory but neither gcc 4.2.0 (as in -current) or gcc 3.4.6 (as in 6-stable) work that way. The following program shows that both 's' and 't' are initialised to point to the same read-only string. ----8<------ #include int main () { static char *s =3D "PATH=3D/bin"; static char *t =3D "PATH=3D/bin"; static char u[] =3D "PATH=3D/bin"; if (s =3D=3D t) printf("s & t are common\n"); s =3D "PATH=3D/sbin"; printf("%s\n", s); u[4] =3D ':'; printf("u=3D\"%s\"\n", u); t[4] =3D ':'; printf("t=3D\"%s\"\n", t); s[4] =3D ':'; printf("s=3D\"%s\"\n", s); return 0; } ----8<------ gives the following results (-current shown, 6-stable is the same): cc -O2 -fno-strict-aliasing -pipe -march=3Dathlon-xp x.c -o x server% ./x s & t are common PATH=3D/sbin u=3D"PATH:/bin" zsh: segmentation fault (core dumped) ./x server% gcc -v Using built-in specs. Target: i386-undermydesk-freebsd Configured with: FreeBSD/i386 system compiler Thread model: posix gcc version 4.2.0 20070514 [FreeBSD] server%=20 --=20 Peter Jeremy --jRHKVT23PllUwdXP Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGlD7Z/opHv/APuIcRAoo/AJ93bYmcX1mkNEkrRnwiRWydKzSnRQCcDT5A tXQa5LhMIo/kKrjAGsDD5Rg= =4D42 -----END PGP SIGNATURE----- --jRHKVT23PllUwdXP--