Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85687 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77968 invoked from network); 2 Apr 2015 16:01:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Apr 2015 16:01:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=keyurgovande@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=keyurgovande@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.172 as permitted sender) X-PHP-List-Original-Sender: keyurgovande@gmail.com X-Host-Fingerprint: 209.85.214.172 mail-ob0-f172.google.com Received: from [209.85.214.172] ([209.85.214.172:34043] helo=mail-ob0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 37/52-56257-5C76D155 for ; Thu, 02 Apr 2015 11:01:10 -0500 Received: by obbgh1 with SMTP id gh1so128637694obb.1 for ; Thu, 02 Apr 2015 09:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Fr8M6cN55avJ2Zx1v0+AI4WFnt42+xz0yIpzvYRTQLU=; b=y0Z9vT7ASAUQmmYzvakOWcbtdt/aNg9TdCjB0wEJ5tmcftS5XKEZERoIQ/m2s3tA9t Zof587br34SrnEOPhVlfI+tfJeoehaVsaz+wiNLvUCZXYCqBJ9TdkaWbATwHviuyRA7i X6poasg0n5rAino//chV81JftnXADyDPXT28aXWJMsA5JsUM90iY9TqiJI4WQ14TCIme hTgdqfAyrTw7I9WbjGrv9yAo6jcSLpEx5v4rxDqNKyt9uZirJUeMSInOJSTokwpt0plR 3r0uDujy74rZTr56mtVKXMm2gUK4UjuUfczCJR2SF3DcE3/QTD7Aja6v36fLvzGA+0JG PZmQ== MIME-Version: 1.0 X-Received: by 10.182.80.103 with SMTP id q7mr48038418obx.18.1427990462924; Thu, 02 Apr 2015 09:01:02 -0700 (PDT) Received: by 10.182.22.51 with HTTP; Thu, 2 Apr 2015 09:01:02 -0700 (PDT) In-Reply-To: <551CEDF6.7090408@lerdorf.com> References: <551CEDF6.7090408@lerdorf.com> Date: Thu, 2 Apr 2015 12:01:02 -0400 Message-ID: To: Rasmus Lerdorf Cc: Dan Ackroyd , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b2e44b0490fc00512bff04f Subject: Re: [PHP-DEV] Deprecate setlocale? From: keyurgovande@gmail.com (Keyur Govande) --047d7b2e44b0490fc00512bff04f Content-Type: text/plain; charset=UTF-8 On Thu, Apr 2, 2015 at 3:21 AM, Rasmus Lerdorf wrote: > On 04/01/2015 09:15 AM, Dan Ackroyd wrote: > > Hi, > > > > I'd like to get people's feedback for the idea of making setlocale be > > either deprecated and to be removed eventually or just increasing the > > warning level against people using it. > > > > The short version of why we should do this is that setlocale breaks > > things. It is a process wide operation, that is not thread safe on > > most platforms. Although people use it to alter the way strings are > > output, it also breaks libraries that are assuming that they are > > running in a "C" locale. > > The PHP setlocale() wrapper can be made threadsafe in a portable manner > via newlocale()/uselocale(), so that part isn't an issue. Someone just > needs to write the code for the threaded SAPIs. It hasn't been a high > priority due to how few people use non-Windows ZTS mode so far. > > Obviously within the same process there may be issues with changing a > locale to something unexpected by subsequent code, but that is really a > bug in that code then. If some library function expects and only works > in the "C" locale, it should make sure it is in that locale before doing > anything and then restoring the locale back appropriately. And with a > bit of symbol trickery libraries that do actually call setlocale to > change it and restore it can be made to use our newlocale/uselocale > thread-local locale mechanism. > > setlocale() is used quite a bit and for non-threaded, which is the bulk > of php usage, it tends to work quite well. It is annoying that it is > process-wide and as you noted that can cause issues, sure, and that the > current implementation isn't threadsafe, but it isn't something that is > technically unsolvable. Rather than throwing our hands in the air and > just pulling the rug out from under people using it, we should take a > look at fixing the problems associated with it instead. > > -Rasmus > > To Rasmus's point, here's a PR for HHVM to provide a thread-safe setlocale implementation: https://github.com/facebook/hhvm/pull/4736/files It should be fairly easy to refactor the thread-safe-setlocale.(h/cpp) files for Zend. --047d7b2e44b0490fc00512bff04f--