Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65195 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26420 invoked from network); 25 Jan 2013 22:08:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2013 22:08:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.220.177 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.220.177 mail-vc0-f177.google.com Received: from [209.85.220.177] ([209.85.220.177:60745] helo=mail-vc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/B0-17242-87203015 for ; Fri, 25 Jan 2013 17:08:57 -0500 Received: by mail-vc0-f177.google.com with SMTP id m18so660344vcm.36 for ; Fri, 25 Jan 2013 14:08:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=mbIgXVEctoR2vOJ4paX2tkvjTJ4gQuOF7d6Uky3kwx4=; b=gZdHR2iVCjrXs3jIpAzW+NbrvIBhuKV7MncTnh01/Xzg64d4uUmqdVnGKJxfdfYdC2 rmdE0lDF4MiNRiy0dy0OR8Ler6Z1HZvJr/w0+EgJhlSTPclk9JzC7ZBSf294LvgaXRku Rr0kqjuFe4Cv9Ubs/G35YlEXmUzLITHYUY97NU2rdMacpuTRwpXuMNsT3F/pRWB+nnDy q6shDoCf03HLlGK9a66hUOlpDYzxGWirCebvDaDCna/bcqpLyZ7toEC61+Fd+aukAw3X GhddtsjR29J5eE7gVGy5cC9H3A1lo+Gf4Ga8LpCTkPkQKazeBEK5ZImTP9dBJvDBp06z 0z+g== X-Received: by 10.52.74.38 with SMTP id q6mr6999173vdv.17.1359151733453; Fri, 25 Jan 2013 14:08:53 -0800 (PST) Received: from [192.168.200.148] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPS id z10sm1246120vds.17.2013.01.25.14.08.52 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Jan 2013 14:08:52 -0800 (PST) Message-ID: <51030272.5040804@lerdorf.com> Date: Fri, 25 Jan 2013 14:08:50 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: Marco Schuster CC: internals References: In-Reply-To: X-Enigmail-Version: 1.4.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQkx25Dj5ULunte77gEakL+5cWu45fmOWUVbB7K2cIuT3KSSh8Kzw+IeCAzsE2SNPiHfBu8D Subject: Re: [PHP-DEV] New uint native data type? From: rasmus@lerdorf.com (Rasmus Lerdorf) On 01/25/2013 01:39 PM, Marco Schuster wrote: > Hi all, > > I'm currently writing a php-program to process certain special binary > files, which include 32-bit offsets which I need to read and > manipulate. The problem is that PHPs int type is only 31-bit because > they have sign information. Sure, I could use the GMP/bcmath stuff, > but that isn't really an option because of performance and the fact > that I'd have to use bc* functions everywhere, and the code is already > complex enough. Because I need to do maths and, later on, file > accesses at positions > 2GB, with them and not just print, > sprintf("%u",$val) is not sufficient, too. > > Switching to 64-bit doesn't help in my case, as the program interfaces > with external windows-only dependencies and the PHP x64 build doesn't > do 64-bit ints at the moment. > > Would it be possible to extend the PHP engine and add a "uint" native > type which allows handling of full 32-bit values and if yes, is there > any documentation about the parts of the engine I need to modify? The > PHP internals manual doesn't have much content and the Zend / main > directories in the source code lack useful information, too. No, this isn't something a quick patch will solve for you. It would require changes throughout all of PHP and all the extensions. For display purposes you can easily print these unsigned using s/printf('%u',$val) and manipulation is possible too depending on what sort of things you are trying to do to them. If that isn't enough, writing a little custom extension to handle your special case for these offsets is way way easier than modifying PHP to add a new type. -Rasmus