Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55663 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75461 invoked from network); 29 Sep 2011 15:07:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Sep 2011 15:07:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=keisial@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=keisial@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.170 as permitted sender) X-PHP-List-Original-Sender: keisial@gmail.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:42590] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/00-09488-4C9848E4 for ; Thu, 29 Sep 2011 11:07:49 -0400 Received: by eyh6 with SMTP id 6so495876eyh.29 for ; Thu, 29 Sep 2011 08:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=tTtwU/s2lbmDJ+OZOIiy7wXZ/poS/8ySnM51IXwx0X8=; b=ipGRyUy6qgt9Vl0hpw/NAOITfTx0QxFcfWoqQMxoEzGXVQtQG68Zn1VF8W67u6BeCY IwkduvO7kxmJLP1sk0ANVPddXfd6qUU4rIl4zRDUo8odU8zmZ/IDdS18H4WlHunsS1Xk nMDnne53JNEw9HvjYL5cdOgAyS91Kw5aa1LhQ= Received: by 10.216.88.70 with SMTP id z48mr1280226wee.46.1317308865185; Thu, 29 Sep 2011 08:07:45 -0700 (PDT) Received: from [192.168.1.26] (217.Red-88-13-201.dynamicIP.rima-tde.net. [88.13.201.217]) by mx.google.com with ESMTPS id u16sm2891815wbm.5.2011.09.29.08.07.43 (version=SSLv3 cipher=OTHER); Thu, 29 Sep 2011 08:07:44 -0700 (PDT) Message-ID: <4E848B31.2030501@gmail.com> Date: Thu, 29 Sep 2011 17:13:53 +0200 User-Agent: Thunderbird MIME-Version: 1.0 To: Olivier Favre CC: internals@lists.php.net References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------030403040409080109060700" Subject: Re: [PHP-DEV] Cast trap with INI entries compiling C++ extension From: keisial@gmail.com ("=?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?=") --------------030403040409080109060700 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 29/09/11 14:14, Olivier Favre wrote: > Hi everyone, > > I've been developing a PHP extension for internal needs. > We're using C++, by using PHP_REQUIRE_CXX() in config.m4. > I'm using debian sid 64bits, with the package php5-dev-5.3.8-2 > (against which the patch below has been created). (...) > My point is that there is a problem if it is that easy to trigger a > bug with some "natural reflex" to get rid of a warning. > I suggest some fixes: > * Use strlen() instead of sizeof(). > * Use in-macro cast to char[]. > * Use const when the string value won't be modified (I'm not talking > about the pointer, but its content). > In fact, I propose the following changes so that no user (extension > writer) code has to change: (...) > > We use const char* fields not to trigger the C++ deprecation warning, > and we use strlen() to get the size of the string (which is the only > normal way anyway), but test for a non NULL value (useless for "name" > I guess). By the way, I still return sizeof(NULL) for compatibility, > but 0 should probably be a better value. > > I only tested that change with building my C++ PHP extension, whole > PHP recompilation. > > Best, Using strlen() there forces a runtime call to figure out the string length*, the sizeof is preferable there. I find the change from char* to const char* acceptable, though. Or at least |char const*, I'm not sure if those values are changed at runtime. I have found in the past some places where a const keyword would be preferable, but was't used. I don't know if there's a rationale for that or is it just "old code". There are functions using the const keyword, so it is not a case of compatibility... * GCC may actually be smart enough to resolve it at compilation time, since it implements strlen() as a builtin. But you obviously can't count on that. I'm not even sure if that's legal C (or from which version). g++ doesn't complain, but with your patch of adding strlen(), I think gcc gives (on C files) the following warning: > warning: initializer element is not a constant expression | --------------030403040409080109060700--