0001-Use-foreach_ptr.patch.nocfbot

text/plain

Filename: 0001-Use-foreach_ptr.patch.nocfbot
Type: text/plain
Part: 0
Message: Re: RFC: Additional Directory for Extensions
From 35c2106558095e74359cec58b9631fa19ed937b3 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 6 Mar 2025 14:28:08 +0100
Subject: [PATCH] Use foreach_ptr

---
 src/backend/commands/extension.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index 7e8a28e4064..4bdb20aaf54 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -51,10 +51,10 @@
 #include "commands/defrem.h"
 #include "commands/extension.h"
 #include "commands/schemacmds.h"
-#include "nodes/pg_list.h"
 #include "funcapi.h"
 #include "mb/pg_wchar.h"
 #include "miscadmin.h"
+#include "nodes/pg_list.h"
 #include "nodes/queryjumble.h"
 #include "storage/fd.h"
 #include "tcop/utility.h"
@@ -2183,20 +2183,17 @@ Datum
 pg_available_extensions(PG_FUNCTION_ARGS)
 {
 	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
+	List	   *locations;
 	DIR		   *dir;
 	struct dirent *de;
-	List	   *locations;
-	ListCell   *cell;
 
 	/* Build tuplestore to hold the result rows */
 	InitMaterializedSRF(fcinfo, 0);
 
 	locations = get_extension_control_directories();
 
-	foreach(cell, locations)
+	foreach_ptr(char, location, locations)
 	{
-		char	   *location = (char *) lfirst(cell);
-
 		dir = AllocateDir(location);
 
 		/*
@@ -2271,7 +2268,6 @@ pg_available_extension_versions(PG_FUNCTION_ARGS)
 {
 	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
 	List	   *locations;
-	ListCell   *cell;
 	DIR		   *dir;
 	struct dirent *de;
 
@@ -2279,10 +2275,9 @@ pg_available_extension_versions(PG_FUNCTION_ARGS)
 	InitMaterializedSRF(fcinfo, 0);
 
 	locations = get_extension_control_directories();
-	foreach(cell, locations)
-	{
-		char	   *location = (char *) lfirst(cell);
 
+	foreach_ptr(char, location, locations)
+	{
 		dir = AllocateDir(location);
 
 		/*
@@ -2449,16 +2444,13 @@ extension_file_exists(const char *extensionName)
 {
 	bool		result = false;
 	List	   *locations;
-	ListCell   *cell;
 	DIR		   *dir;
 	struct dirent *de;
 
 	locations = get_extension_control_directories();
 
-	foreach(cell, locations)
+	foreach_ptr(char, location, locations)
 	{
-		char	   *location = (char *) lfirst(cell);
-
 		dir = AllocateDir(location);
 
 		/*
-- 
2.48.1