Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHUJQ-0008Gl-I8 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jul 2023 19:06:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHUJP-00044R-CB for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jul 2023 19:06:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHUJO-00044B-VV for pgsql-hackers@lists.postgresql.org; Thu, 06 Jul 2023 19:06:43 +0000 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qHUJL-002auj-HO for pgsql-hackers@postgresql.org; Thu, 06 Jul 2023 19:06:42 +0000 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7836164a08aso40497039f.1 for ; Thu, 06 Jul 2023 12:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=singh-im.20221208.gappssmtp.com; s=20221208; t=1688670397; x=1691262397; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pFy2J2hVvA+lK+hy3T/O24J2UTf99KMStnv1nKiEF+o=; b=zTzIbPtGrpF4yvaNYLr7Kp0TQOErHvk2zZ3oZ5klLO2tcZkpDQ7l1QJdcYjIbc1LpJ 8D8stotOFkJssLJA1XrOQFsSO+TTTEqSfPKhDXHGJrzTI0EBplUumyPWfe/4LyiJZNEX 2DBl+MrBdTIFwWo4kHoXqsSlv462L16hF0Vthy1PtKojqThV9ocZjncHiX6KJm96QAC7 3X2ycoxwxVSkcA4jPcs623Pmhjg7eGc48ToGiqYiwxR+V+1lKKFhSaUMKbP5A4TLPr0c SkZLHUodo0p+sAyjemzPIPtBDekeBgVWabUYs/nWicYsuWan2bBUwXqUcQIhzg8bYmR5 3EfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688670397; x=1691262397; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pFy2J2hVvA+lK+hy3T/O24J2UTf99KMStnv1nKiEF+o=; b=Jwwk4Abgu94vS61nCSpbWqIBturm0AmLok9gk45bRK/vWDqp2W0ksSOzhtee0a8kFs iDAfFyjEoT1DEXO3zWso8zdPVUX/dT7zjLKeLRW6euYHlCxSOFod/eRW5x4WKHLrfgnu IuRM2qWut8463Vm9LkM6nsxb1Flg92WyveJ5dHdCOIZ1+9jQqhA+fH6QauNnfmQ5JSKj 5Yl6+/RPE/JFL7o0g1PhOrHeyYljoQ+VOA+DgaswdoFkISUMtUeP16Gkc0RsAK8WwgFx 1HTP3RN7ypW0VNmWA4wr/7uFevEA7gq49MmLdGXmUBKUCF+9gJSxh3M9FqqI7+ol94pL pXQA== X-Gm-Message-State: ABy/qLZywPV45ckduRAU2C1ja+Ae0PpaCRYVQXuGGM462gRfTV5L6ivR wqxDqhoR0npLoFbjdzh61ndezKoi9pOrRvbIPxM= X-Google-Smtp-Source: APBJJlFCL/ag9I/WLg2rUdD26u9bS5PxEs88GobtPH2V26672UpdYpgNs5CNwLG8RPp8NR+q98mNUsXqCpY/vgFP6og= X-Received: by 2002:a5d:9f48:0:b0:776:fd07:3c96 with SMTP id u8-20020a5d9f48000000b00776fd073c96mr3781723iot.7.1688670397391; Thu, 06 Jul 2023 12:06:37 -0700 (PDT) MIME-Version: 1.0 References: <20230613.163921.1246444645573084901.horikyota.ntt@gmail.com> In-Reply-To: From: Gurjeet Singh Date: Thu, 6 Jul 2023 12:06:20 -0700 Message-ID: Subject: Re: Avoid unncessary always true test (src/backend/storage/buffer/bufmgr.c) To: Karina Litskevich Cc: Ranier Vilela , Richard Guo , Kyotaro Horiguchi , michael@paquier.xyz, pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 6, 2023 at 8:01=E2=80=AFAM Karina Litskevich wrote: > > >> EB_SMGR and EB_REL are macros for making new structs. >> IMO these are buggy, once make new structs without initializing all fiel= ds. >> Attached a patch to fix this and make more clear when rel or smgr is NUL= L. > > > As long as a structure is initialized, its fields that are not present in > initialization are initialized to zeros and NULLs depending on their type= s. > See C99 Standard 6.7.8.21 and 6.7.8.10. This behaviour is quite well know= n, > so I don't think this place is buggy. Anyway, if someone else says the co= de > is more readable with these fields initialized explicitly, then go on. Even though I am not a fan of the Designated Initializers feature, I agree with Karina. Per the standard, the unmentioned fields get initialized to zeroes/NULLs, so the explicit initialization to zero/null that this additional patch does is unnecessary. Moreover, I feel that it makes the code less pleasant to read. C99, 6.7.8.21: > If there are fewer initializers in a brace-enclosed list than there are > elements or members of an aggregate, or fewer characters in a string lite= ral > used to initialize an array of known size than there are elements in the = array, > the remainder of the aggregate shall be initialized implicitly the same a= s > objects that have static storage duration. C99, 6.7.8.10: > If an object that has automatic storage duration is not initialized expli= citly, > its value is indeterminate. If an object that has static storage duration= is > not initialized explicitly, then: > - if it has pointer type, it is initialized to a null pointer; > - if it has arithmetic type, it is initialized to (positive or unsigned) = zero; > - if it is an aggregate, every member is initialized (recursively) accord= ing to these rules; > - if it is a union, the first named member is initialized (recursively) a= ccording to these rules. Best regards, Gurjeet http://Gurje.et