v1-0017-bootstrap-Use-palloc-instead-of-malloc-for-flex.patch

text/plain

Filename: v1-0017-bootstrap-Use-palloc-instead-of-malloc-for-flex.patch
Type: text/plain
Part: 16
Message: Re: pure parsers and reentrant scanners

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0017
Subject: bootstrap: Use palloc() instead of malloc() for flex
File+
src/backend/bootstrap/bootscanner.l 30 0
From dfb1624981c5c5b517e5049b5274fc5d45eac177 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 3 Dec 2024 15:28:16 +0100
Subject: [PATCH v1 17/19] bootstrap: Use palloc() instead of malloc() for flex

---
 src/backend/bootstrap/bootscanner.l | 30 +++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index c4e7139fa41..ad33b4e3fd8 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -49,6 +49,9 @@ fprintf_to_ereport(const char *fmt, const char *msg)
 %option noinput
 %option nounput
 %option noyywrap
+%option noyyalloc
+%option noyyrealloc
+%option noyyfree
 %option warn
 %option prefix="boot_yy"
 
@@ -132,3 +135,30 @@ boot_yyerror(yyscan_t yyscanner, const char *message)
 
 	elog(ERROR, "%s at line %d", message, yylineno);
 }
+
+/*
+ * Interface functions to make flex use palloc() instead of malloc().
+ * It'd be better to make these static, but flex insists otherwise.
+ */
+
+void *
+yyalloc(yy_size_t size, yyscan_t yyscanner)
+{
+	return palloc(size);
+}
+
+void *
+yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
+{
+	if (ptr)
+		return repalloc(ptr, size);
+	else
+		return palloc(size);
+}
+
+void
+yyfree(void *ptr, yyscan_t yyscanner)
+{
+   if (ptr)
+	   pfree(ptr);
+}
-- 
2.47.1