From patchwork Tue Dec 13 22:45:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 32964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp402950wrn; Tue, 13 Dec 2022 14:46:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf6YlWU0CJ2hczILaS33sMN0KRHE6S8tpNQ8AQkn3jRrDyegB3ymxPNJr2cIxphkbQJnc81F X-Received: by 2002:a17:906:8257:b0:7c1:5098:907f with SMTP id f23-20020a170906825700b007c15098907fmr12234245ejx.61.1670971615527; Tue, 13 Dec 2022 14:46:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670971615; cv=none; d=google.com; s=arc-20160816; b=nTLwNQrk/53BvE8AhxdLJIvP54D8QI1NvOjlLdTkiEkkRv7g1/dpxH1fRNAcztI64D FSalwTMXXjFiV7fFv0gNg44scdAPGdElf3kLCwX+zvwVR/RUbnbIGUgXrooJ1rI6MPR1 U05z44J8UzDMVucth6bJZv7wZ0eckh0EOdDJTilrBojx83yEFC3yk2pTuC+/sJG3m8Dj Ei1Eh95xjEUYafg8LeM5PnIdXswGvcWpBJXSMXmS3kkOWbLlwZ/x7xbu8oF6qZTYnfXE rA8VgK+5SYO41dX1P/r8dxZTfnyAguoOljGxeVpAs0hbtDCVIeA6YvR6XHkTIzEzRP8w S3RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iqQHeIflk+LSY5Djd2QgIuJzjP7G5VCgY26Oq09VkqY=; b=eHQCrXNLwr6G6cZMLk+T6W6qQ0/EIJIEHA1B9+hf8KyDRoPHAPfv0ftkm+ohs5W4zh HwMa7oEQ1gttzK7jQ7eMxd3+piLtERxARH294Pp/Le3kbIpQrfpLLUuz2kQtMBagnnCy iKWERuOepaVCRQSuxfJ3MX/65Tlxc4nlo7eMFdL87R2DbivDLRe5quRzXpkaRQMT5wUu 91AqzY5AYp5FuGHgLoJBF6c8JmV4gtYjBAfQG/gBBpW+gvyUJytJB6FReC+DjiKkpgiR sFNEQCYQvLmylIp93c2AbhH+EZZ4VZh2L68Z5m4FWjr5OlI2VrKIQo6JgLRsY6HTfqR0 SBOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hsh9tKsl; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id rq5-20020a17090788c500b007807e1f3d9dsi8375107ejc.842.2022.12.13.14.46.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 14:46:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hsh9tKsl; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53933384EF5D for ; Tue, 13 Dec 2022 22:46:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53933384EF5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670971614; bh=iqQHeIflk+LSY5Djd2QgIuJzjP7G5VCgY26Oq09VkqY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Hsh9tKslqn46UwYRoNarZ3jVZe4GLU5m/J3oRKkkFxcsM0EE5eZ7A111jGgcCgbu5 0dbM9cydQCKq/O94Du1Si6HBMuwJYEq9fd6xe+iIykpGFNdnnI0wDlgsFqSciw6UHV /mLPmBWunVRkVz1c7wte8PYyuZdjef48TY+nf+Vg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id 1A169384F717 for ; Tue, 13 Dec 2022 22:46:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1A169384F717 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4NWtrR2BFXz9sRw; Tue, 13 Dec 2022 23:45:59 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [GCC-12][committed] libphobos: Backport library and bindings fixes from mainline Date: Tue, 13 Dec 2022 23:45:48 +0100 Message-Id: <20221213224548.853922-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4NWtrR2BFXz9sRw X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752140732698324292?= X-GMAIL-MSGID: =?utf-8?q?1752140732698324292?= Hi, This patch backports some fixes for the libphobos library from mainline that fix build and testsuite failures. Regression tested on x86_64-linux-gnu/-m32/-mx32, committed to releases/gcc-12 branch. D Runtime changes: - Fix MIPS64 bindings for CRuntime_UClibc. Phobos changes: - Fix std.path.expandTilde erroneously raising onOutOfMemory after failed call to getpwnam_r(). - Fix std.random unittest failures on ILP32 targets. - Use GENERIC_IO on CRuntime_UClibc port of std.stdio. libphobos/ChangeLog: * libdruntime/core/stdc/fenv.d: Compile in MIPS uClibc bindings on MIPS_Any targets. * libdruntime/core/stdc/math.d: Likewise. * libdruntime/core/sys/posix/dlfcn.d: Likewise. * libdruntime/core/sys/posix/setjmp.d: Add MIPS64 definitions for CRuntime_UClibc. * libdruntime/core/sys/posix/sys/types.d: Likewise. * src/std/path.d (expandTilde): Handle more errno codes that could be left set by getpwnam_r. * src/std/random.d: Use D_LP64 in unittests. * src/std/stdio.d: Set CRuntime_UClibc as GENERIC_IO target. --- libphobos/libdruntime/core/stdc/fenv.d | 2 +- libphobos/libdruntime/core/stdc/math.d | 2 +- libphobos/libdruntime/core/sys/posix/dlfcn.d | 2 +- libphobos/libdruntime/core/sys/posix/setjmp.d | 16 +++++++++++++ .../libdruntime/core/sys/posix/sys/types.d | 12 ++++++++++ libphobos/src/std/path.d | 23 +++++++++++++++---- libphobos/src/std/random.d | 14 +++++------ libphobos/src/std/stdio.d | 3 +-- 8 files changed, 57 insertions(+), 17 deletions(-) diff --git a/libphobos/libdruntime/core/stdc/fenv.d b/libphobos/libdruntime/core/stdc/fenv.d index 88123fb16a6..5242ba9d4e2 100644 --- a/libphobos/libdruntime/core/stdc/fenv.d +++ b/libphobos/libdruntime/core/stdc/fenv.d @@ -483,7 +483,7 @@ else version (CRuntime_UClibc) alias fexcept_t = ushort; } - else version (MIPS32) + else version (MIPS_Any) { struct fenv_t { diff --git a/libphobos/libdruntime/core/stdc/math.d b/libphobos/libdruntime/core/stdc/math.d index 0393ea52c07..51fd68f9fc3 100644 --- a/libphobos/libdruntime/core/stdc/math.d +++ b/libphobos/libdruntime/core/stdc/math.d @@ -120,7 +120,7 @@ else version (CRuntime_UClibc) /// enum int FP_ILOGBNAN = int.min; } - else version (MIPS32) + else version (MIPS_Any) { /// enum int FP_ILOGB0 = -int.max; diff --git a/libphobos/libdruntime/core/sys/posix/dlfcn.d b/libphobos/libdruntime/core/sys/posix/dlfcn.d index a9519ca234a..24fa3787ec4 100644 --- a/libphobos/libdruntime/core/sys/posix/dlfcn.d +++ b/libphobos/libdruntime/core/sys/posix/dlfcn.d @@ -387,7 +387,7 @@ else version (CRuntime_UClibc) enum RTLD_LOCAL = 0; enum RTLD_NODELETE = 0x01000; } - else version (MIPS32) + else version (MIPS_Any) { enum RTLD_LAZY = 0x0001; enum RTLD_NOW = 0x0002; diff --git a/libphobos/libdruntime/core/sys/posix/setjmp.d b/libphobos/libdruntime/core/sys/posix/setjmp.d index 91e3a19d081..5a15d82d2ee 100644 --- a/libphobos/libdruntime/core/sys/posix/setjmp.d +++ b/libphobos/libdruntime/core/sys/posix/setjmp.d @@ -370,6 +370,22 @@ else version (CRuntime_UClibc) double[6] __fpregs; } } + else version (MIPS64) + { + struct __jmp_buf + { + long __pc; + long __sp; + long[8] __regs; + long __fp; + long __gp; + int __fpc_csr; + version (MIPS_N64) + double[8] __fpregs; + else + double[6] __fpregs; + } + } else static assert(0, "unimplemented"); diff --git a/libphobos/libdruntime/core/sys/posix/sys/types.d b/libphobos/libdruntime/core/sys/posix/sys/types.d index ec229dd3b2b..3e515c4c68e 100644 --- a/libphobos/libdruntime/core/sys/posix/sys/types.d +++ b/libphobos/libdruntime/core/sys/posix/sys/types.d @@ -1140,6 +1140,18 @@ else version (CRuntime_UClibc) enum __SIZEOF_PTHREAD_BARRIER_T = 20; enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; } + else version (MIPS64) + { + enum __SIZEOF_PTHREAD_ATTR_T = 56; + enum __SIZEOF_PTHREAD_MUTEX_T = 40; + enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; + enum __SIZEOF_PTHREAD_COND_T = 48; + enum __SIZEOF_PTHREAD_CONDATTR_T = 4; + enum __SIZEOF_PTHREAD_RWLOCK_T = 56; + enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; + enum __SIZEOF_PTHREAD_BARRIER_T = 32; + enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; + } else version (ARM) { enum __SIZEOF_PTHREAD_ATTR_T = 36; diff --git a/libphobos/src/std/path.d b/libphobos/src/std/path.d index de180fcc548..777d8b924dd 100644 --- a/libphobos/src/std/path.d +++ b/libphobos/src/std/path.d @@ -3959,7 +3959,7 @@ string expandTilde(string inputPath) @safe nothrow version (Posix) { import core.exception : onOutOfMemoryError; - import core.stdc.errno : errno, ERANGE; + import core.stdc.errno : errno, EBADF, ENOENT, EPERM, ERANGE, ESRCH; import core.stdc.stdlib : malloc, free, realloc; /* Joins a path from a C string to the remainder of path. @@ -4065,7 +4065,7 @@ string expandTilde(string inputPath) @safe nothrow char[] extra_memory; passwd result; - while (1) + loop: while (1) { extra_memory.length += extra_memory_size; @@ -4088,10 +4088,23 @@ string expandTilde(string inputPath) @safe nothrow break; } - if (errno != ERANGE && + switch (errno) + { + case ERANGE: // On BSD and OSX, errno can be left at 0 instead of set to ERANGE - errno != 0) - onOutOfMemoryError(); + case 0: + break; + + case ENOENT: + case ESRCH: + case EBADF: + case EPERM: + // The given name or uid was not found. + break loop; + + default: + onOutOfMemoryError(); + } // extra_memory isn't large enough import core.checkedint : mulu; diff --git a/libphobos/src/std/random.d b/libphobos/src/std/random.d index 106e51ceedb..c23eac9843e 100644 --- a/libphobos/src/std/random.d +++ b/libphobos/src/std/random.d @@ -2516,7 +2516,7 @@ if (!is(T == enum) && (isIntegral!T || isSomeChar!T)) assert(rnd.uniform!ulong == 4838462006927449017); enum Fruit { apple, mango, pear } - version (X86_64) // https://issues.dlang.org/show_bug.cgi?id=15147 + version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147 assert(rnd.uniform!Fruit == Fruit.mango); } @@ -2783,7 +2783,7 @@ auto ref choice(Range)(auto ref Range range) auto rnd = MinstdRand0(42); auto elem = [1, 2, 3, 4, 5].choice(rnd); - version (X86_64) // https://issues.dlang.org/show_bug.cgi?id=15147 + version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147 assert(elem == 3); } @@ -2865,7 +2865,7 @@ if (isRandomAccessRange!Range) auto rnd = MinstdRand0(42); auto arr = [1, 2, 3, 4, 5].randomShuffle(rnd); - version (X86_64) // https://issues.dlang.org/show_bug.cgi?id=15147 + version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147 assert(arr == [3, 5, 2, 4, 1]); } @@ -2955,15 +2955,15 @@ if (isRandomAccessRange!Range) auto arr = [1, 2, 3, 4, 5, 6]; arr = arr.dup.partialShuffle(1, rnd); - version (X86_64) // https://issues.dlang.org/show_bug.cgi?id=15147 + version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147 assert(arr == [2, 1, 3, 4, 5, 6]); // 1<->2 arr = arr.dup.partialShuffle(2, rnd); - version (X86_64) // https://issues.dlang.org/show_bug.cgi?id=15147 + version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147 assert(arr == [1, 4, 3, 2, 5, 6]); // 1<->2, 2<->4 arr = arr.dup.partialShuffle(3, rnd); - version (X86_64) // https://issues.dlang.org/show_bug.cgi?id=15147 + version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147 assert(arr == [5, 4, 6, 2, 1, 3]); // 1<->5, 2<->4, 3<->6 } @@ -3369,7 +3369,7 @@ if (isRandomAccessRange!Range) import std.range : iota; auto rnd = MinstdRand0(42); - version (X86_64) // https://issues.dlang.org/show_bug.cgi?id=15147 + version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147 assert(10.iota.randomCover(rnd).equal([7, 4, 2, 0, 1, 6, 8, 3, 9, 5])); } diff --git a/libphobos/src/std/stdio.d b/libphobos/src/std/stdio.d index 1bde73d628d..ca6f48c7c13 100644 --- a/libphobos/src/std/stdio.d +++ b/libphobos/src/std/stdio.d @@ -85,8 +85,7 @@ else version (CRuntime_Musl) } else version (CRuntime_UClibc) { - // uClibc supports GCC IO - version = GCC_IO; + version = GENERIC_IO; } else version (OSX) {