From patchwork Sat Nov 18 19:55:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 839261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-467305-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IfkZwRAG"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yfQhm6Psgz9ryv for ; Sun, 19 Nov 2017 06:56:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=IwA/qmVYGNPO g9MzaZL1MGX74OIP9rsY+CNlrfI1OU1ep0ahW41QeZgOQhDaJkocrax7Zs6sfnlQ 3ZdL7UADkfKC6xY22P2dna+xp6c/lAWbAs/HI3BttEwyQJg036ZZs3XH1656bZO3 aZU4Jhtg03czYzXGoAiulRkAWQlEYzc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=e3KFVUOCedxCvyjaWm zl0X60Rg8=; b=IfkZwRAGhLcY+pJfFyomXFKjF85vRtJGjqgZ+a2DZrmRi4xeKO pvwXH5pYEY8fo/Sr96kykPZl6+YJci5tYf6NCTRMTKWWk6Bn68XOSpnVmJXSS4A+ 3KMp/6xUF60q2WFvPvUBbhehFqn9GQ+lh17/BYyjN0NP6ORPpa7ACVhYI= Received: (qmail 82937 invoked by alias); 18 Nov 2017 19:55:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 82915 invoked by uid 89); 18 Nov 2017 19:55:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-lf0-f41.google.com Received: from mail-lf0-f41.google.com (HELO mail-lf0-f41.google.com) (209.85.215.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 18 Nov 2017 19:55:52 +0000 Received: by mail-lf0-f41.google.com with SMTP id w23so6073084lfd.11; Sat, 18 Nov 2017 11:55:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bA71yRaDQ+yVg12tpZGsJMPUYlLrnSbf8mVagNv38g4=; b=Cn4bMGzTw1WNxf6jrH+tRyDbmVDpTD1/ZxkSFJ4we2OlE7lKwoVfVGkbxhfhNtYv/F 2RddRhYo5yTFY6lZaxgnjzcv8ScnGKi0SqPBzWIbXK0dlhVvhreiELZ5NSzRhIETLK+X 9OPgy70v5wZurGimkWmTqY5zvS5AFiTz9V2EY6Tw+Q2TmbCWrTH7vmNHnIuMiaDjcByN jO0CEZiiZJnwtodC0+qF1KS+qA7OYLIe+/nBs1hM8HVgG/+9R47+Ka3xD5RC/SxNF0tn u7nx+mcm6VKVr6l8VtsAKgb1bMIlgS63l+2QQeBveDD+vKq6eYIhMn28JGBbfNCaoxRr RhXw== X-Gm-Message-State: AJaThX5JJpYHeooQQjeWVYqCm6bb3yxaVn/uf59H5HGwJJmcwy9ma8Kp KIlhYicyyXROgiE6fYsj/JemLg== X-Google-Smtp-Source: AGs4zMYtfVZOPLg0LvsJmJz+RNc2alCKqgISeZ7XAb+iDQx1PQWpt6U9bbim4VIDRJgguU2glaiSpg== X-Received: by 10.46.43.86 with SMTP id q83mr2246016lje.104.1511034949658; Sat, 18 Nov 2017 11:55:49 -0800 (PST) Received: from dt.lan (a88-114-247-254.elisa-laajakaista.fi. [88.114.247.254]) by smtp.gmail.com with ESMTPSA id v10sm303910lfi.11.2017.11.18.11.55.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Nov 2017 11:55:49 -0800 (PST) From: Janne Blomqvist To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Janne Blomqvist Subject: [PATCH] PR 44292 Handle large record lengths Date: Sat, 18 Nov 2017 21:55:41 +0200 Message-Id: <1511034941-15326-1-git-send-email-blomqvist.janne@gmail.com> Now that the ABI supports large record lengths, there's a few places in libgfortran where we need to use larger types. For internal units which by definition are in-memory, it's enought to use ptrdiff_t, for external units gfc_offset. Regtested on x86_64-pc-linux-gnu, Ok for trunk? libgfortran/ChangeLog: 2017-11-18 Janne Blomqvist * io/transfer.c (skip_record): Use gfc_offset to handle large records. (next_record_r): Likewise. (sset): Likewise. (next_record_w): Use gfc_offset/ptrdiff_t appropriately. --- libgfortran/io/transfer.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 5296370..c173447 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -3290,7 +3290,7 @@ next_array_record (st_parameter_dt *dtp, array_loop_spec *ls, int *finished) position. */ static void -skip_record (st_parameter_dt *dtp, ssize_t bytes) +skip_record (st_parameter_dt *dtp, gfc_offset bytes) { ssize_t rlength, readb; #define MAX_READ 4096 @@ -3367,7 +3367,6 @@ static void next_record_r (st_parameter_dt *dtp, int done) { gfc_offset record; - int bytes_left; char p; int cc; @@ -3419,7 +3418,7 @@ next_record_r (st_parameter_dt *dtp, int done) } else { - bytes_left = (int) dtp->u.p.current_unit->bytes_left; + gfc_offset bytes_left = dtp->u.p.current_unit->bytes_left; bytes_left = min_off (bytes_left, ssize (dtp->u.p.current_unit->s) - stell (dtp->u.p.current_unit->s)); @@ -3590,12 +3589,13 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord) /* Utility function like memset() but operating on streams. Return value is same as for POSIX write(). */ -static ssize_t -sset (stream *s, int c, ssize_t nbyte) +static gfc_offset +sset (stream *s, int c, gfc_offset nbyte) { #define WRITE_CHUNK 256 char p[WRITE_CHUNK]; - ssize_t bytes_left, trans; + gfc_offset bytes_left; + ssize_t trans; if (nbyte < WRITE_CHUNK) memset (p, c, nbyte); @@ -3645,11 +3645,10 @@ next_record_cc (st_parameter_dt *dtp) static void next_record_w (st_parameter_dt *dtp, int done) { - gfc_offset m, record, max_pos; - int length; + gfc_offset max_pos_off; /* Zero counters for X- and T-editing. */ - max_pos = dtp->u.p.max_pos; + max_pos_off = dtp->u.p.max_pos; dtp->u.p.max_pos = dtp->u.p.skips = dtp->u.p.pending_spaces = 0; switch (current_mode (dtp)) @@ -3674,7 +3673,7 @@ next_record_w (st_parameter_dt *dtp, int done) case UNFORMATTED_DIRECT: if (dtp->u.p.current_unit->bytes_left > 0) { - length = (int) dtp->u.p.current_unit->bytes_left; + gfc_offset length = dtp->u.p.current_unit->bytes_left; if (sset (dtp->u.p.current_unit->s, 0, length) != length) goto io_error; } @@ -3691,11 +3690,14 @@ next_record_w (st_parameter_dt *dtp, int done) if (is_internal_unit (dtp)) { char *p; + /* Internal unit, so must fit in memory. */ + ptrdiff_t length, m, record; + ptrdiff_t max_pos = max_pos_off; if (is_array_io (dtp)) { int finished; - length = (int) dtp->u.p.current_unit->bytes_left; + length = dtp->u.p.current_unit->bytes_left; /* If the farthest position reached is greater than current position, adjust the position and set length to pad out @@ -3705,14 +3707,14 @@ next_record_w (st_parameter_dt *dtp, int done) - dtp->u.p.current_unit->bytes_left; if (max_pos > m) { - length = (int) (max_pos - m); + length = (max_pos - m); if (sseek (dtp->u.p.current_unit->s, length, SEEK_CUR) < 0) { generate_error (&dtp->common, LIBERROR_INTERNAL_UNIT, NULL); return; } - length = (int) (dtp->u.p.current_unit->recl - max_pos); + length = ((ptrdiff_t) dtp->u.p.current_unit->recl - max_pos); } p = write_block (dtp, length); @@ -3735,7 +3737,7 @@ next_record_w (st_parameter_dt *dtp, int done) dtp->u.p.current_unit->endfile = AT_ENDFILE; /* Now seek to this record */ - record = record * dtp->u.p.current_unit->recl; + record = record * ((ptrdiff_t) dtp->u.p.current_unit->recl); if (sseek (dtp->u.p.current_unit->s, record, SEEK_SET) < 0) { @@ -3758,17 +3760,18 @@ next_record_w (st_parameter_dt *dtp, int done) - dtp->u.p.current_unit->bytes_left; if (max_pos > m) { - length = (int) (max_pos - m); + length = max_pos - m; if (sseek (dtp->u.p.current_unit->s, length, SEEK_CUR) < 0) { generate_error (&dtp->common, LIBERROR_INTERNAL_UNIT, NULL); return; } - length = (int) (dtp->u.p.current_unit->recl - max_pos); + length = (ptrdiff_t) dtp->u.p.current_unit->recl + - max_pos; } else - length = (int) dtp->u.p.current_unit->bytes_left; + length = dtp->u.p.current_unit->bytes_left; } if (length > 0) {