From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1230 invoked by alias); 23 May 2012 16:41:40 -0000 Received: (qmail 1210 invoked by uid 22791); 23 May 2012 16:41:38 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-qa0-f73.google.com (HELO mail-qa0-f73.google.com) (209.85.216.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 23 May 2012 16:41:24 +0000 Received: by qafk22 with SMTP id k22so540264qaf.0 for ; Wed, 23 May 2012 09:41:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=to:cc:subject:message-id:date:from:x-gm-message-state; bh=VImYZjMh11BhXjT096qBfSF8SlRVSB7JKkKh8wFpG6E=; b=gxzUNLZyD/B9XoFw3TL8O6IdPC2czj1c3EJMCoIuAvAy2PhmO9uavjOeXkDbGu3pG+ HJTY64JEDENE9GaFqpUmPxP+olnRaZT0T79hUaJhi3FefYA5Lo3bl7B9kfA7B3SiNtmU SzlRVYe9XClS2JIku2jmGDXY7DBGiUWa3HzWTDg1ZaoyUMO4jVFafPl5CNmSecTZ8UPR GYFN9wKh7AABP2T8xsENd6nBLl5vHbCP3H1ACvVsREcHMyDICSQtsBVAWqUwIPOX/8nt gdNGV4dQeoB3Uqk5vkgeEJu5+H0Ke/IFf+O1U4ytor6AKZmfl6bmDvPtmijJfqeda4UL VrXA== Received: by 10.236.73.131 with SMTP id v3mr46253205yhd.6.1337791283822; Wed, 23 May 2012 09:41:23 -0700 (PDT) Received: by 10.236.73.131 with SMTP id v3mr46253199yhd.6.1337791283778; Wed, 23 May 2012 09:41:23 -0700 (PDT) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id b8si20982387yhn.6.2012.05.23.09.41.23 (version=TLSv1/SSLv3 cipher=AES128-SHA); Wed, 23 May 2012 09:41:23 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.18.110.50]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id 86D6310004D; Wed, 23 May 2012 09:41:23 -0700 (PDT) Received: by ruffy.mtv.corp.google.com (Postfix, from userid 67641) id 099BD2461B1; Wed, 23 May 2012 09:41:22 -0700 (PDT) To: iant@google.com cc: gcc-patches@sourcware.org, binutils@sourceware.org, gdb-patches@sourceware.org Subject: [RFA] leb128.h: Umm, how about int64_t? Message-Id: <20120523164123.099BD2461B1@ruffy.mtv.corp.google.com> Date: Wed, 23 May 2012 16:41:00 -0000 From: dje@google.com (Doug Evans) X-Gm-Message-State: ALoCoQk+79dO4OdB6QQSMH/tsOz+fkeACbOwqnNtwPM9EuK/SPGlWG1CshI0bnlUq0VGem1OwgmeoQQGzb4nJTD8nvrHrtUBE0g0IYvUiaRwwnwsHDP74p6q02vilCnfa5CKxMLQ4/7YoNzPibMHwRhNH+Mk2ekDYw== X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-05/txt/msg00903.txt.bz2 It turns out gdb can't use long long but it can use {,u}int64_t. [Insert lament that we're debating whether to switch to C++ and yet we can't even use C99. :-(] I opted for renaming the functions instead of adding new ones since there'd be no current users. I left adding the long long versions back for when there's an actual need for them. Ok to check in? 2012-05-23 Doug Evans * leb128.h: #include stdint.h, inttypes.h. (read_uleb128_to_uint64): Renamed from read_uleb128_to_ull. Change to take a uint64_t * argument instead of unsigned long long. (read_sleb128_to_uint64): Renamed from read_sleb128_to_ll. Change to take an int64_t * argument instead of long long. Index: leb128.h =================================================================== RCS file: /cvs/src/src/include/leb128.h,v retrieving revision 1.1 diff -u -p -r1.1 leb128.h --- leb128.h 22 May 2012 18:05:30 -0000 1.1 +++ leb128.h 23 May 2012 16:27:53 -0000 @@ -19,7 +19,12 @@ Boston, MA 02110-1301, USA. */ /* The functions defined here can be speed critical. Since they are all pretty small we keep things simple and just define - them all as "static inline". */ + them all as "static inline". + + WARNING: This file is used by GDB which is stuck at C90. :-( + Though it can use stdint.h, inttypes.h. + Therefore if you want to add support for "long long" you need + to wrap it in #ifdef CC_HAS_LONG_LONG. */ #ifndef LEB128_H #define LEB128_H @@ -30,6 +35,13 @@ Boston, MA 02110-1301, USA. */ /* Get a definition for NULL, size_t. */ #include +#ifdef HAVE_STDINT_H +#include +#endif +#ifdef HAVE_INTTYPES_H +#include +#endif + /* Decode the unsigned LEB128 constant at BUF into the variable pointed to by R, and return the number of bytes read. If we read off the end of the buffer, zero is returned, @@ -39,12 +51,12 @@ Boston, MA 02110-1301, USA. */ read to avoid const-vs-non-const problems. */ static inline size_t -read_uleb128_to_ull (const unsigned char *buf, const unsigned char *buf_end, - unsigned long long *r) +read_uleb128_to_uint64 (const unsigned char *buf, const unsigned char *buf_end, + uint64_t *r) { const unsigned char *p = buf; unsigned int shift = 0; - unsigned long long result = 0; + uint64_t result = 0; unsigned char byte; while (1) @@ -53,7 +65,7 @@ read_uleb128_to_ull (const unsigned char return 0; byte = *p++; - result |= ((unsigned long long) (byte & 0x7f)) << shift; + result |= ((uint64_t) (byte & 0x7f)) << shift; if ((byte & 0x80) == 0) break; shift += 7; @@ -72,12 +84,12 @@ read_uleb128_to_ull (const unsigned char read to avoid const-vs-non-const problems. */ static inline size_t -read_sleb128_to_ll (const unsigned char *buf, const unsigned char *buf_end, - long long *r) +read_sleb128_to_int64 (const unsigned char *buf, const unsigned char *buf_end, + int64_t *r) { const unsigned char *p = buf; unsigned int shift = 0; - long long result = 0; + int64_t result = 0; unsigned char byte; while (1) @@ -86,13 +98,13 @@ read_sleb128_to_ll (const unsigned char return 0; byte = *p++; - result |= ((unsigned long long) (byte & 0x7f)) << shift; + result |= ((uint64_t) (byte & 0x7f)) << shift; shift += 7; if ((byte & 0x80) == 0) break; } if (shift < (sizeof (*r) * 8) && (byte & 0x40) != 0) - result |= -(((unsigned long long) 1) << shift); + result |= -(((uint64_t) 1) << shift); *r = result; return p - buf;