]> granicus.if.org Git - postgresql/blobdiff - src/test/regress/regress.c
Update copyright for the year 2010.
[postgresql] / src / test / regress / regress.c
index db887c304d5b769d5dacd84e8ce7c69492ec291c..ffbe4e37b8338e5f4f11eaf108e79fc0ddd3e21a 100644 (file)
@@ -1,22 +1,28 @@
 /*
- * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.54 2002/11/13 00:39:48 momjian Exp $
+ * $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.72 2009/01/07 13:44:37 tgl Exp $
  */
 
 #include "postgres.h"
 
-#include <float.h>                             /* faked on sunos */
+#include <float.h>
+#include <math.h>
+
+#include "access/transam.h"
+#include "access/xact.h"
+#include "catalog/pg_type.h"
+#include "commands/sequence.h"
+#include "commands/trigger.h"
+#include "executor/executor.h"
+#include "executor/spi.h"
+#include "utils/builtins.h"
+#include "utils/geo_decls.h"
 
-#include "utils/geo_decls.h"   /* includes <math.h> */
-#include "executor/executor.h" /* For GetAttributeByName */
-#include "commands/sequence.h" /* for nextval() */
 
 #define P_MAXDIG 12
 #define LDELIM                 '('
 #define RDELIM                 ')'
 #define DELIM                  ','
 
-typedef TupleTableSlot *TUPLE;
-
 extern Datum regress_dist_ptpath(PG_FUNCTION_ARGS);
 extern Datum regress_path_dist(PG_FUNCTION_ARGS);
 extern PATH *poly2path(POLYGON *poly);
@@ -29,9 +35,14 @@ extern int   oldstyle_length(int n, text *t);
 extern Datum int44in(PG_FUNCTION_ARGS);
 extern Datum int44out(PG_FUNCTION_ARGS);
 
+#ifdef PG_MODULE_MAGIC
+PG_MODULE_MAGIC;
+#endif
+
+
 /*
-** Distance from a point to a path
-*/
+ * Distance from a point to a path
+ */
 PG_FUNCTION_INFO_V1(regress_dist_ptpath);
 
 Datum
@@ -54,16 +65,16 @@ regress_dist_ptpath(PG_FUNCTION_ARGS)
                default:
 
                        /*
-                        * the distance from a point to a path is the smallest
-                        * distance from the point to any of its constituent segments.
+                        * the distance from a point to a path is the smallest distance
+                        * from the point to any of its constituent segments.
                         */
                        Assert(path->npts > 1);
                        for (i = 0; i < path->npts - 1; ++i)
                        {
                                regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]);
                                tmp = DatumGetFloat8(DirectFunctionCall2(dist_ps,
-                                                                                                         PointPGetDatum(pt),
-                                                                                                 LsegPGetDatum(&lseg)));
+                                                                                                                PointPGetDatum(pt),
+                                                                                                         LsegPGetDatum(&lseg)));
                                if (i == 0 || tmp < result)
                                        result = tmp;
                        }
@@ -72,8 +83,10 @@ regress_dist_ptpath(PG_FUNCTION_ARGS)
        PG_RETURN_FLOAT8(result);
 }
 
-/* this essentially does a cartesian product of the lsegs in the
-   two paths, and finds the min distance between any two lsegs */
+/*
+ * this essentially does a cartesian product of the lsegs in the
+ * two paths, and finds the min distance between any two lsegs
+ */
 PG_FUNCTION_INFO_V1(regress_path_dist);
 
 Datum
@@ -98,7 +111,7 @@ regress_path_dist(PG_FUNCTION_ARGS)
 
                        tmp = DatumGetFloat8(DirectFunctionCall2(lseg_distance,
                                                                                                         LsegPGetDatum(&seg1),
-                                                                                                 LsegPGetDatum(&seg2)));
+                                                                                                        LsegPGetDatum(&seg2)));
                        if (!have_min || tmp < min)
                        {
                                min = tmp;
@@ -114,8 +127,7 @@ regress_path_dist(PG_FUNCTION_ARGS)
 }
 
 PATH *
-poly2path(poly)
-POLYGON    *poly;
+poly2path(POLYGON *poly)
 {
        int                     i;
        char       *output = (char *) palloc(2 * (P_MAXDIG + 1) * poly->npts + 64);
@@ -125,11 +137,12 @@ POLYGON    *poly;
 
        for (i = 0; i < poly->npts; i++)
        {
-               sprintf(buf, ",%*g,%*g", P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
+               snprintf(buf, sizeof(buf), ",%*g,%*g",
+                                P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
                strcat(output, buf);
        }
 
-       sprintf(buf, "%c", RDELIM);
+       snprintf(buf, sizeof(buf), "%c", RDELIM);
        strcat(output, buf);
        return DatumGetPathP(DirectFunctionCall1(path_in,
                                                                                         CStringGetDatum(output)));
@@ -180,10 +193,7 @@ interpt_pp(PG_FUNCTION_ARGS)
 
 /* like lseg_construct, but assume space already allocated */
 void
-regress_lseg_construct(lseg, pt1, pt2)
-LSEG      *lseg;
-Point     *pt1;
-Point     *pt2;
+regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
 {
        lseg->p[0].x = pt1->x;
        lseg->p[0].y = pt1->y;
@@ -197,7 +207,7 @@ PG_FUNCTION_INFO_V1(overpaid);
 Datum
 overpaid(PG_FUNCTION_ARGS)
 {
-       TUPLE           tuple = (TUPLE) PG_GETARG_POINTER(0);
+       HeapTupleHeader tuple = PG_GETARG_HEAPTUPLEHEADER(0);
        bool            isnull;
        int32           salary;
 
@@ -225,8 +235,7 @@ extern Datum pt_in_widget(PG_FUNCTION_ARGS);
 #define NARGS  3
 
 WIDGET *
-widget_in(str)
-char      *str;
+widget_in(char *str)
 {
        char       *p,
                           *coord[NARGS],
@@ -246,14 +255,13 @@ char         *str;
        result->center.y = atof(coord[1]);
        result->radius = atof(coord[2]);
 
-       sprintf(buf2, "widget_in: read (%f, %f, %f)\n", result->center.x,
-                       result->center.y, result->radius);
+       snprintf(buf2, sizeof(buf2), "widget_in: read (%f, %f, %f)\n",
+                        result->center.x, result->center.y, result->radius);
        return result;
 }
 
 char *
-widget_out(widget)
-WIDGET    *widget;
+widget_out(WIDGET * widget)
 {
        char       *result;
 
@@ -277,8 +285,6 @@ pt_in_widget(PG_FUNCTION_ARGS)
        PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius);
 }
 
-#define ABS(X) ((X) >= 0 ? (X) : -(X))
-
 PG_FUNCTION_INFO_V1(boxarea);
 
 Datum
@@ -288,8 +294,8 @@ boxarea(PG_FUNCTION_ARGS)
        double          width,
                                height;
 
-       width = ABS(box->high.x - box->low.x);
-       height = ABS(box->high.y - box->low.y);
+       width = Abs(box->high.x - box->low.x);
+       height = Abs(box->high.y - box->low.y);
        PG_RETURN_FLOAT8(width * height);
 }
 
@@ -300,11 +306,7 @@ reverse_name(char *string)
        int                     len;
        char       *new_string;
 
-       if (!(new_string = palloc0(NAMEDATALEN)))
-       {
-               fprintf(stderr, "reverse_name: palloc failed\n");
-               return NULL;
-       }
+       new_string = palloc0(NAMEDATALEN);
        for (i = 0; i < NAMEDATALEN && string[i]; ++i)
                ;
        if (i == NAMEDATALEN || !string[i])
@@ -315,7 +317,8 @@ reverse_name(char *string)
        return new_string;
 }
 
-/* This rather silly function is just to test that oldstyle functions
+/*
+ * This rather silly function is just to test that oldstyle functions
  * work correctly on toast-able inputs.
  */
 int
@@ -329,8 +332,6 @@ oldstyle_length(int n, text *t)
        return n + len;
 }
 
-#include "executor/spi.h"              /* this is what you need to work with SPI */
-#include "commands/trigger.h"  /* -"- and triggers */
 
 static TransactionId fd17b_xid = InvalidTransactionId;
 static TransactionId fd17a_xid = InvalidTransactionId;
@@ -430,14 +431,14 @@ funny_dup17(PG_FUNCTION_ARGS)
        if (SPI_processed > 0)
        {
                selected = DatumGetInt32(DirectFunctionCall1(int4in,
-                                                                                       CStringGetDatum(SPI_getvalue(
-                                                                                                  SPI_tuptable->vals[0],
-                                                                                                  SPI_tuptable->tupdesc,
-                                                                                                                                                1
-                                                                                                                                       ))));
+                                                                                               CStringGetDatum(SPI_getvalue(
+                                                                                                          SPI_tuptable->vals[0],
+                                                                                                          SPI_tuptable->tupdesc,
+                                                                                                                                                        1
+                                                                                                                                               ))));
        }
 
-       elog(DEBUG3, "funny_dup17 (fired %s) on level %3d: %d/%d tuples inserted/selected",
+       elog(DEBUG4, "funny_dup17 (fired %s) on level %3d: %d/%d tuples inserted/selected",
                 when, *level, inserted, selected);
 
        SPI_finish();
@@ -455,7 +456,7 @@ extern Datum set_ttdummy(PG_FUNCTION_ARGS);
 
 #define TTDUMMY_INFINITY       999999
 
-static void *splan = NULL;
+static SPIPlanPtr splan = NULL;
 static bool ttoff = false;
 
 PG_FUNCTION_INFO_V1(ttdummy);
@@ -487,11 +488,11 @@ ttdummy(PG_FUNCTION_ARGS)
        if (!CALLED_AS_TRIGGER(fcinfo))
                elog(ERROR, "ttdummy: not fired by trigger manager");
        if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
-               elog(ERROR, "ttdummy: can't process STATEMENT events");
+               elog(ERROR, "ttdummy: cannot process STATEMENT events");
        if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
                elog(ERROR, "ttdummy: must be fired before event");
        if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
-               elog(ERROR, "ttdummy: can't process INSERT event");
+               elog(ERROR, "ttdummy: cannot process INSERT event");
        if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
                newtuple = trigdata->tg_newtuple;
 
@@ -545,7 +546,7 @@ ttdummy(PG_FUNCTION_ARGS)
                        elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
 
                if (oldon != newon || oldoff != newoff)
-                       elog(ERROR, "ttdummy (%s): you can't change %s and/or %s columns (use set_ttdummy)",
+                       elog(ERROR, "ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
                                 relname, args[0], args[1]);
 
                if (newoff != TTDUMMY_INFINITY)
@@ -560,16 +561,9 @@ ttdummy(PG_FUNCTION_ARGS)
                return PointerGetDatum(NULL);
        }
 
-       {
-               text       *seqname = DatumGetTextP(DirectFunctionCall1(textin,
-                                                                               CStringGetDatum("ttdummy_seq")));
-
-               newoff = DirectFunctionCall1(nextval,
-                                                                        PointerGetDatum(seqname));
-               /* nextval now returns int64; coerce down to int32 */
-               newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
-               pfree(seqname);
-       }
+       newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
+       /* nextval now returns int64; coerce down to int32 */
+       newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
 
        /* Connect to SPI manager */
        if ((ret = SPI_connect()) < 0)
@@ -594,7 +588,7 @@ ttdummy(PG_FUNCTION_ARGS)
                cnulls[attnum[1] - 1] = ' ';
        }
        else
-/* DELETE */
+               /* DELETE */
        {
                cvals[attnum[1] - 1] = newoff;  /* stop_date eq current date */
                cnulls[attnum[1] - 1] = ' ';
@@ -603,7 +597,7 @@ ttdummy(PG_FUNCTION_ARGS)
        /* if there is no plan ... */
        if (splan == NULL)
        {
-               void       *pplan;
+               SPIPlanPtr      pplan;
                Oid                *ctypes;
                char       *query;
 
@@ -649,7 +643,7 @@ ttdummy(PG_FUNCTION_ARGS)
                SPI_freetuple(tmptuple);
        }
        else
-/* DELETE */
+               /* DELETE */
                rettuple = trigtuple;
 
        SPI_finish();                           /* don't forget say Bye to SPI mgr */