Exposing guc_malloc/strdup/realloc for plugins?

Started by Michael Paquierover 7 years ago2 messages
#1Michael Paquier
michael@paquier.xyz
1 attachment(s)

Hi all,

While hacking on an extension, I have finished by doing things similar
to guc_malloc & friends for the allocation of a GUC parameter for malloc
portability. While that's not really a big deal to copy/paste this
code, I am wondering if it would make sense to expose them for extension
developers. Please see the attached for the simple idea.

Thanks,
--
Michael

Attachments:

guc-alloc-extern.patchtext/x-diff; charset=us-asciiDownload
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index f496ad6281..e548473fb3 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -4203,9 +4203,10 @@ static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **
 
 
 /*
- * Some infrastructure for checking malloc/strdup/realloc calls
+ * Some infrastructure for checking malloc/strdup/realloc calls with
+ * GUC parameters.
  */
-static void *
+void *
 guc_malloc(int elevel, size_t size)
 {
 	void	   *data;
@@ -4221,7 +4222,7 @@ guc_malloc(int elevel, size_t size)
 	return data;
 }
 
-static void *
+void *
 guc_realloc(int elevel, void *old, size_t size)
 {
 	void	   *data;
@@ -4237,7 +4238,7 @@ guc_realloc(int elevel, void *old, size_t size)
 	return data;
 }
 
-static char *
+char *
 guc_strdup(int elevel, const char *src)
 {
 	char	   *data;
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 3d13a33b94..280249a257 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -415,6 +415,10 @@ extern void GUC_check_errcode(int sqlerrcode);
 	pre_format_elog_string(errno, TEXTDOMAIN), \
 	GUC_check_errhint_string = format_elog_string
 
+/* Support for GUC allocation */
+extern void *guc_malloc(int elevel, size_t size);
+extern void *guc_realloc(int elevel, void *old, size_t size);
+extern char *guc_strdup(int elevel, const char *src);
 
 /*
  * The following functions are not in guc.c, but are declared here to avoid
#2Euler Taveira
euler@timbira.com.br
In reply to: Michael Paquier (#1)
Re: Exposing guc_malloc/strdup/realloc for plugins?

2018-05-08 3:46 GMT-03:00 Michael Paquier <michael@paquier.xyz>:

While hacking on an extension, I have finished by doing things similar
to guc_malloc & friends for the allocation of a GUC parameter for malloc
portability. While that's not really a big deal to copy/paste this
code, I am wondering if it would make sense to expose them for extension
developers. Please see the attached for the simple idea.

Although I didn't need similar code on some extensions, code reuse is
always a good goal.

--
Euler Taveira Timbira -
http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento