Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVTW4-008m9s-Km for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jan 2025 10:42:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tVTW3-00GkGx-V3 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jan 2025 10:42:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVTW3-00GkGM-De for pgsql-hackers@lists.postgresql.org; Wed, 08 Jan 2025 10:42:23 +0000 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tVTW0-000V4S-1Z for pgsql-hackers@postgresql.org; Wed, 08 Jan 2025 10:42:22 +0000 Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6d92cd1e811so5873146d6.1 for ; Wed, 08 Jan 2025 02:42:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1736332939; x=1736937739; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=v6gjg4qZH9WIDznQddJROnNEus6dU86VdJ+mJMI5Z5w=; b=LIlGjFjROw8Ym3G/GfUc9UGEEJ+1W7tx3HdsTjbM4snO+W3DDzr5SY+MvqBF/d6TCi j3ea3aflYqNGb+ba0mljINAE/lEgpAG+S+2oO1djSBvCcd5H6BhjNU6+r1uPJseZTJ6C rvprIZPJL6ZGryQSmKAkc5HWp7k4jRlxolfRbaOvNyw7cRsPrwcZ+RKVcsA118yadRK/ BYnLGNENdKT9k7a7kJ6lP6IX6lkNUdyXWCdS7BS4W0s2ya6wRf39Xz3Jo/E/k8Vtl4tp fJRWepaxfbc56x5lojNH+zEeRhTNq/GZOB4LvrNQU1D93gBwJgZ5x8Dpqw/XdJf7Hsgu 8QqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736332939; x=1736937739; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=v6gjg4qZH9WIDznQddJROnNEus6dU86VdJ+mJMI5Z5w=; b=A2rjkGNMacXGWI599+HMT4a8x0jjg3pVoVhuhge+Nqata1lHA8wUcK6i8boCOqGVEh 7ShG35lnbYFC1SmOAMoSsRfdTtDN0ZKcjFNagD2gGuVkhbsZljeth2lCGJLfyOlagd1i Uh9Fdo2+HJmnYcVdIYPW+FAWx4wWbUiOXtnWDAP0d/aBHjERAD41qlNlH/buEu0sika/ PEsPfWecvxX0ymMxW9rsTW+Y08Es6yfTVjBBQtK4EZiYhf8RB+7b5RencIK5rechJ3nd daWsTePtcZYq/t+RRnJLsFg5+3dNED52kI3aNyFgbvVuhtkse5qo9d9ZxBVGqKH6OpfX Al1A== X-Forwarded-Encrypted: i=1; AJvYcCXsFBzbYGRheslsImKvpfg8AZdvyYGZyjHGjZhYtkU3Xl3gfM3GtC3Hp+5WIreGWudxKoQcdX4zCcUUOPj8@postgresql.org X-Gm-Message-State: AOJu0YwsAMeazNPi8IrJyNNzUNSCVYL7ujryLnsmMQ8IeuwPkqZb694z Hmus55gAPpIo9CuTdPTtYb8KGnK/sX6EuuV2pONg9/80wRmszOBUwTmRtaZvE2s= X-Gm-Gg: ASbGncu2lM44aSO6ijwwPBS5y/stMj1om6amI277Xwm1ADiMK9T22fn2fuUE/gzEzQC z0rbd35Z+F4pXeItzLwkh84ag4GJF+49C7bafa13RQpZFan7gFYBT6CJUk88uq9lpaUeVNrnhLt iaDn/sSjj3ooHFpRoTee3iTE2l/fv/d3TQclghWV7/hKsT/tEzITvpgrmJoX6uACcCcDJgpVcOZ CJNtPsW6G2KUxRrEdRQW/zhd4aGXZKz1eRVGEv6yhnqHr/YGCM8UG6e/mOXIDVyIaw= X-Google-Smtp-Source: AGHT+IG9lHzLj1eDL91aMapjAwbT0c1uQIbSb3cQgYqDYqPdEaDEfUd3cEkvz8yw7gVYveGBcQOTeg== X-Received: by 2002:ad4:5ba6:0:b0:6d8:ab3c:5d7 with SMTP id 6a1803df08f44-6df9ae6a5ebmr37425746d6.24.1736332939400; Wed, 08 Jan 2025 02:42:19 -0800 (PST) Received: from ?IPV6:2605:a601:a681:6b00::1cc? ([2605:a601:a681:6b00::1cc]) by smtp.googlemail.com with ESMTPSA id 6a1803df08f44-6dd180ea955sm190135716d6.21.2025.01.08.02.42.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jan 2025 02:42:18 -0800 (PST) Message-ID: <27a573c0-70f0-4d5c-b9ca-d8c4e2b999f6@dunslane.net> Date: Wed, 8 Jan 2025 05:42:09 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Coccinelle for PostgreSQL development [1/N]: coccicheck.py To: Mats Kindahl , PostgreSQL Development References: From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0D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Wfw7gQUCZFlx 5wUJGVGAjgAKCRCZ+n/LWfw7gf+iB/4g8CPY5jihf5r/8EsoIGe2H+dpVmpPF8YGBzTIvCz/ fQoOq8AX/pE76QEuFnFZWfjw+wgBXgCVmkox2Eflkk6z4ND3pcwGZ6CfCxTQCDk/dij+2DQ4 6bmDCy/sBgcbz9mTpoLC11HLoPae6YN9nBNQRZDcEFEu54OaVOqlIdbA6m+POIBCXZdHOFc0 WoDTgxHRzC1jgQNidyd6tKqcsVJs0dzF0oKTmFFmUAqTdJO12LBuNA1rlqrR3EtpYk8B/wtS 5dIMD7Q8hwQpL+4C6GNpb6ZKnPkLi47pDOLhz2qBrqN+rqUEsT3YnExYpzj5yOBi+FlmV1Hw 49QYe1sn2ZPs In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-01-07 Tu 2:44 PM, Mats Kindahl wrote: > I got some time over during the holidays, so I spent some of it > doing something I've been thinking about for a while. > > For those of you that are not aware of it: Coccinelle is a tool for > pattern matching and text transformation for C code and can be used > for detection of problematic programming patterns and to make complex, > tree-wide patches easy. It is aware of the structure of C code and is > better suited to make complicated changes than what is possible using > normal text substitution tools like Sed and Perl. > > Coccinelle have been successfully been used in the Linux project since > 2008 and is now an established tool for Linux development and a large > number of semantic patches have been added to the source tree to > capture everything from generic issues (like eliminating the redundant > A in expressions like "!A || (A && B)") to more Linux-specific > problems like adding a missing call to kfree(). > > Although PostgreSQL is nowhere the size of the Linux kernel, it is > nevertheless of a significant size and would benefit from > incorporating Coccinelle into the development. I noticed it's been > used in a few cases way back (like 10 years back) to fix issues in the > PostgreSQL code, but I thought it might be useful to make it part of > normal development practice to, among other things: > > - Identify and correct bugs in the source code both during development > and review. > - Make large-scale changes to the source tree to improve the code > based on new insights. > - Encode and enforce APIs by ensuring that function calls are used > correctly. > - Use improved coding patterns for more efficient code. > - Allow extensions to automatically update code for later PostgreSQL > versions. > > To that end, I created a series of patches to show how it could be > used in the PostgreSQL tree. It is a lot easier to discuss concrete > code and I split it up into separate messages since that makes it > easier to discuss each individual patch. The series contains code to > make it easy to work with Coccinelle during development and reviews, > as well as examples of semantic patches that capture problems, > demonstrate how to make large-scale changes, how to enforce APIs, and > also improve some coding patterns. > > This first patch contains the coccicheck.py script, which is a > re-implementation of the coccicheck script that the Linux kernel uses. > We cannot immediately use the coccicheck script since it is quite > closely tied to the Linux source code tree and we need to have > something that both supports autoconf and Meson. Since Python seems to > be used more and more in the tree, it seems to be the most natural > choice. (I have no strong opinion on what language to use, but think > it would be good to have something that is as platform-independent as > possible.) > > The intention is that we should be able to use the Linux semantic > patches directly, so it supports the "Requires" and "Options" > keywords, which can be used to require a specific version of spatch(1) > and add options to the execution of that semantic patch, respectively. > Please don't start multiple threads like this. If you want to submit a set of patches for a single feature, send them all as attachments in a single email. Otherwise this just makes life hard for threading email readers. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com