diff options
| author | Bruce Momjian | 1997-11-05 21:38:25 +0000 |
|---|---|---|
| committer | Bruce Momjian | 1997-11-05 21:38:25 +0000 |
| commit | 951986c550dccfdafffcf2eda30980c7310b41b4 (patch) | |
| tree | 9bd4eb75a2c8cdc96e72cd5675c0a398d9c3659c /contrib/miscutil | |
| parent | 5aaf00f3f39848eb8fef768e3ec8c0e816a87172 (diff) | |
Update of contrib stuff from massimo.
Diffstat (limited to 'contrib/miscutil')
| -rw-r--r-- | contrib/miscutil/Makefile | 62 | ||||
| -rw-r--r-- | contrib/miscutil/assert_test.c | 43 | ||||
| -rw-r--r-- | contrib/miscutil/assert_test.h | 7 | ||||
| -rw-r--r-- | contrib/miscutil/misc_utils.c | 50 | ||||
| -rw-r--r-- | contrib/miscutil/misc_utils.h | 10 | ||||
| -rw-r--r-- | contrib/miscutil/misc_utils.sql.in | 40 |
6 files changed, 212 insertions, 0 deletions
diff --git a/contrib/miscutil/Makefile b/contrib/miscutil/Makefile new file mode 100644 index 00000000000..982515ab296 --- /dev/null +++ b/contrib/miscutil/Makefile @@ -0,0 +1,62 @@ +#------------------------------------------------------------------------- +# +# Makefile-- +# Makefile for array iterator functions. +# +#------------------------------------------------------------------------- + +PGDIR = ../.. +SRCDIR = $(PGDIR)/src + +include $(SRCDIR)/Makefile.global + +INCLUDE_OPT = -I ./ \ + -I $(SRCDIR)/ \ + -I $(SRCDIR)/include \ + -I $(SRCDIR)/port/$(PORTNAME) + +CFLAGS += $(INCLUDE_OPT) + +ifeq ($(PORTNAME), linux) + ifdef LINUX_ELF + ifeq ($(CC), gcc) + CFLAGS += -fPIC + endif + endif +endif + +ifeq ($(PORTNAME), i386_solaris) + CFLAGS+= -fPIC +endif + +MODNAME = misc_utils + +MODULE = $(MODNAME)$(DLSUFFIX) + +all: module sql + +module: $(MODULE) + +sql: $(MODNAME).sql + +install: $(MODULE) + cp -p $(MODULE) $(LIBDIR) + cd $(LIBDIR); strip $(MODULE) + +%.sql: %.sql.in + sed "s|MODULE_PATHNAME|$(LIBDIR)/$(MODULE)|" < $< > $@ + +.SUFFIXES: $(DLSUFFIX) + +%$(DLSUFFIX): %.c + cc $(CFLAGS) -shared -o $@ $< + +depend dep: + $(CC) -MM $(INCLUDE_OPT) *.c >depend + +clean: + rm -f $(MODULE) $(MODNAME).sql assert_test.so + +ifeq (depend,$(wildcard depend)) +include depend +endif diff --git a/contrib/miscutil/assert_test.c b/contrib/miscutil/assert_test.c new file mode 100644 index 00000000000..fa2ec1fcaad --- /dev/null +++ b/contrib/miscutil/assert_test.c @@ -0,0 +1,43 @@ +/* + * assert_test.c -- + * + * This file tests Postgres assert checking. + * + * Copyright (c) 1996, Massimo Dal Zotto <dz@cs.unitn.it> + */ + +#include "postgres.h" +#include "assert_test.h" + +extern int assertTest(int val); +extern int assertEnable(int val); + +int +assert_enable(int val) +{ + return assertEnable(val); +} + +int +assert_test(int val) +{ + return assertTest(val); +} + +/* + +-- Enable/disable Postgres assert checking. +-- +create function assert_enable(int4) returns int4 + as '/usr/local/pgsql/lib/assert_test.so' + language 'C'; + +-- Test Postgres assert checking. +-- +create function assert_test(int4) returns int4 + as '/usr/local/pgsql/lib/assert_test.so' + language 'C'; + +*/ + +/* end of file */ diff --git a/contrib/miscutil/assert_test.h b/contrib/miscutil/assert_test.h new file mode 100644 index 00000000000..2af288729aa --- /dev/null +++ b/contrib/miscutil/assert_test.h @@ -0,0 +1,7 @@ +#ifndef ASSERT_TEST_H +#define ASSERT_TEST_H + +int assert_enable(int val); +int assert_test(int val); + +#endif diff --git a/contrib/miscutil/misc_utils.c b/contrib/miscutil/misc_utils.c new file mode 100644 index 00000000000..3b8f379d21f --- /dev/null +++ b/contrib/miscutil/misc_utils.c @@ -0,0 +1,50 @@ +/* + * utils.c -- + * + * This file defines various Postgres utility functions. + * + * Copyright (c) 1996, Massimo Dal Zotto <dz@cs.unitn.it> + */ + +#include <unistd.h> + +#include "postgres.h" +#include "utils/palloc.h" + +#include "misc_utils.h" + +extern int ExecutorLimit(int limit); +extern void Async_Unlisten(char *relname, int pid); + +int +query_limit(int limit) +{ + return ExecutorLimit(limit); +} + +int +backend_pid() +{ + return getpid(); +} + +int +unlisten(char *relname) +{ + Async_Unlisten(relname, getpid()); + return 0; +} + +int +max(int x, int y) +{ + return ((x > y) ? x : y); +} + +int +min(int x, int y) +{ + return ((x < y) ? x : y); +} + +/* end of file */ diff --git a/contrib/miscutil/misc_utils.h b/contrib/miscutil/misc_utils.h new file mode 100644 index 00000000000..7dd583c2646 --- /dev/null +++ b/contrib/miscutil/misc_utils.h @@ -0,0 +1,10 @@ +#ifndef MISC_UTILS_H +#define MISC_UTILS_H + +int query_limit(int limit); +int backend_pid(void); +int unlisten(char *relname); +int max(int x, int y); +int min(int x, int y); + +#endif diff --git a/contrib/miscutil/misc_utils.sql.in b/contrib/miscutil/misc_utils.sql.in new file mode 100644 index 00000000000..0c90ba52eb9 --- /dev/null +++ b/contrib/miscutil/misc_utils.sql.in @@ -0,0 +1,40 @@ +-- SQL code to define the new array iterator functions and operators + +-- min(x,y) +-- +create function min(int4,int4) returns int4 + as 'MODULE_PATHNAME' + language 'C'; + +-- max(x,y) +-- +create function max(int4,int4) returns int4 + as 'MODULE_PATHNAME' + language 'C'; + +-- Set the maximum number of tuples returned by a single query +-- +create function query_limit(int4) returns int4 + as 'MODULE_PATHNAME' + language 'C'; + +-- Return the pid of the backend +-- +create function backend_pid() returns int4 + as 'MODULE_PATHNAME' + language 'C'; + +-- Unlisten from a relation +-- +create function unlisten(name) returns int4 + as 'MODULE_PATHNAME' + language 'C'; + +-- Unlisten from all relations for this backend +-- +create function unlisten() returns int4 + as 'delete from pg_listener where listenerpid = backend_pid(); + select 0' + language 'sql'; + +-- end of file |
