Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55671 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69962 invoked from network); 30 Sep 2011 09:17:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Sep 2011 09:17:18 -0000 Authentication-Results: pb1.pair.com header.from=olivier@yakaz.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=olivier@yakaz.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain yakaz.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: olivier@yakaz.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:36365] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/40-01351-D19858E4 for ; Fri, 30 Sep 2011 05:17:18 -0400 Received: by qyl16 with SMTP id 16so192235qyl.8 for ; Fri, 30 Sep 2011 02:17:15 -0700 (PDT) Received: by 10.229.1.145 with SMTP id 17mr7252260qcf.34.1317374235166; Fri, 30 Sep 2011 02:17:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.190.199 with HTTP; Fri, 30 Sep 2011 02:16:55 -0700 (PDT) In-Reply-To: <4E84D3DE.8010805@gmail.com> References: <4E848B31.2030501@gmail.com> <4E84A73E.8030601@gmail.com> <4E84B4DE.3070904@hristov.com> <4E84D3DE.8010805@gmail.com> Date: Fri, 30 Sep 2011 11:16:55 +0200 Message-ID: To: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= Cc: Andrey Hristov , Gustavo Lopes , internals@lists.php.net Content-Type: multipart/mixed; boundary=0016364ec95452c7d504ae251750 Subject: Re: [PHP-DEV] Cast trap with INI entries compiling C++ extension From: olivier@yakaz.com (Olivier Favre) --0016364ec95452c7d504ae251750 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I keep on having the following error: ERROR: =E2=8B=85 Incorrect Captcha while trying to file a bug on the following page: https://bugs.php.net/report.php (Debian sid, Google Chrome 14.0.835.186) I tried flushing my cookies. There are two opened bug reports about that: - https://bugs.php.net/bug.php?id=3D54380 - https://bugs.php.net/bug.php?id=3D53255 And I would have liked to file another... if only I could! Anyway, if someone else is luckier, here what I'd have liked to file: PHP version: 5.3.8 Package affected: Compile issues/Compilation warning Bug type: Feature/Change request OS: All (seen under Linux) Summary: char* field should be const char* to avoid C++ warning Description: http://news.php.net/php.internals/55662 I'm writing a C++ extension to PHP. When declaring a INI entry I get the following warning, multiple times: warning: deprecated conversion from string constant to 'char*' [-Wwrite-str= ings] This only arises when compiling with a C++ compiler. The right and easy fix seems to set some fields to const char *. Some may even be set to const char * const (but this alternative seems to be used nowhere). The proposed patch is against the php5-dev-5.3.8-2 package of debian sid: PHP 5.3.8-2 with Suhosin-Patch (cli) (built: Sep 12 2011 07:28:26) - - - Test script: Write a C++ extension: config.m4 should contain PHP_REQUIRE_CXX(). Declare your module: zend_module_entry quezako_module_entry =3D { STANDARD_MODULE_HEADER, "YourExtensionName", // (1 warning here) [...], "0.42", // (1 warning here) [...], STANDARD_MODULE_PROPERTIES_EX }; Declare an INI entry: PHP_INI_BEGIN() STD_PHP_INI_ENTRY( "extensionName.variable", // (1 warning here) "default value", // (1 warning here) [...] ) PHP_INI_END() - - - Patch name: field_constness_cpp_compilation_warning_fix.patch Patch file: (see attached file) Expected result: No compilation warning. - - - Actual result: Multiple of the following warning: warning: deprecated conversion from string constant to 'char*' [-Wwrite-str= ings] Using the very common fix of prepending (char*) to the string constant is especially harmful here, because of ZEND_INI_ENTRY3_EX using sizeof() on in= : it returns 4/8 (32/64bits platform). Using a cast to char[] solves the problem, but the above fix is a very very common mistake. If the target fields were const char*, no compilation warning would be rose= . - - - Solve the problem 17 + 23 =3D ?: 40 (I even checked the answer using a calculator!!!!) Submit: Send bug report (I'm going mad, really...) -- Olivier Favre Software engineer Yakaz www.yakaz.com --0016364ec95452c7d504ae251750 Content-Type: text/x-patch; charset=US-ASCII; name="field_constness_cpp_compilation_warning_fix.patch" Content-Disposition: attachment; filename="field_constness_cpp_compilation_warning_fix.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gt6yemk21 LS0tIHplbmRfaW5pLmgJMjAxMS0wOS0zMCAxMDoxODo1OS42MzA5NTIwMzQgKzAyMDAKKysrIC91 c3IvaW5jbHVkZS9waHA1L1plbmQvemVuZF9pbmkuaAkyMDExLTA5LTI5IDEyOjI0OjM5LjAxMjg4 MjUyNyArMDIwMApAQCAtNjUsMTQgKzY1LDE0IEBACiBzdHJ1Y3QgX3plbmRfaW5pX2VudHJ5IHsK IAlpbnQgbW9kdWxlX251bWJlcjsKIAlpbnQgbW9kaWZpYWJsZTsKLQljb25zdCBjaGFyICpuYW1l OworCWNoYXIgKm5hbWU7CiAJdWludCBuYW1lX2xlbmd0aDsKIAlaRU5EX0lOSV9NSCgoKm9uX21v ZGlmeSkpOwogCXZvaWQgKm1oX2FyZzE7CiAJdm9pZCAqbWhfYXJnMjsKIAl2b2lkICptaF9hcmcz OwogCi0JY29uc3QgY2hhciAqdmFsdWU7CisJY2hhciAqdmFsdWU7CiAJdWludCB2YWx1ZV9sZW5n dGg7CiAKIAljaGFyICpvcmlnX3ZhbHVlOwotLS0gemVuZF9tb2R1bGVzLmgJMjAxMS0wOS0zMCAx MDoxOTo1NC4yMzQ5NDk2NzQgKzAyMDAKKysrIC91c3IvaW5jbHVkZS9waHA1L1plbmQvemVuZF9t b2R1bGVzLmgJMjAxMS0wOS0xMiAwOTo0NDowMS4wMDAwMDAwMDAgKzAyMDAKQEAgLTk4LDcgKzk4 LDcgQEAKIAl1bnNpZ25lZCBjaGFyIHR5cGU7CiAJdm9pZCAqaGFuZGxlOwogCWludCBtb2R1bGVf bnVtYmVyOwotCWNvbnN0IGNoYXIgKmJ1aWxkX2lkOworCWNoYXIgKmJ1aWxkX2lkOwogfTsKIAog I2RlZmluZSBNT0RVTEVfREVQX1JFUVVJUkVECQkxCg== --0016364ec95452c7d504ae251750--