PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
regress.c File Reference
#include "postgres.h"
#include <float.h>
#include <math.h>
#include <signal.h>
#include "access/htup_details.h"
#include "access/transam.h"
#include "access/tuptoaster.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 "miscadmin.h"
#include "port/atomics.h"
#include "utils/builtins.h"
#include "utils/geo_decls.h"
#include "utils/rel.h"
#include "utils/typcache.h"
#include "utils/memutils.h"
Include dependency graph for regress.c:

Go to the source code of this file.

Data Structures

struct  WIDGET
 

Macros

#define P_MAXDIG   12
 
#define LDELIM   '('
 
#define RDELIM   ')'
 
#define DELIM   ','
 
#define NARGS   3
 
#define TTDUMMY_INFINITY   999999
 

Functions

PATHpoly2path (POLYGON *poly)
 
void regress_lseg_construct (LSEG *lseg, Point *pt1, Point *pt2)
 
char * reverse_name (char *string)
 
int oldstyle_length (int n, text *t)
 
 PG_FUNCTION_INFO_V1 (regress_dist_ptpath)
 
Datum regress_dist_ptpath (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (regress_path_dist)
 
Datum regress_path_dist (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (interpt_pp)
 
Datum interpt_pp (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (overpaid)
 
Datum overpaid (PG_FUNCTION_ARGS)
 
WIDGETwidget_in (char *str)
 
char * widget_out (WIDGET *widget)
 
 PG_FUNCTION_INFO_V1 (pt_in_widget)
 
Datum pt_in_widget (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (boxarea)
 
Datum boxarea (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (funny_dup17)
 
Datum funny_dup17 (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (ttdummy)
 
Datum ttdummy (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (set_ttdummy)
 
Datum set_ttdummy (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (int44in)
 
Datum int44in (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (int44out)
 
Datum int44out (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (make_tuple_indirect)
 
Datum make_tuple_indirect (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (regress_putenv)
 
Datum regress_putenv (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (wait_pid)
 
Datum wait_pid (PG_FUNCTION_ARGS)
 
static void test_atomic_uint32 (void)
 
 PG_FUNCTION_INFO_V1 (test_atomic_ops)
 
Datum test_atomic_ops (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static TransactionId fd17b_xid = InvalidTransactionId
 
static TransactionId fd17a_xid = InvalidTransactionId
 
static int fd17b_level = 0
 
static int fd17a_level = 0
 
static bool fd17b_recursion = true
 
static bool fd17a_recursion = true
 
static SPIPlanPtr splan = NULL
 
static bool ttoff = false
 

Macro Definition Documentation

#define DELIM   ','

Definition at line 44 of file regress.c.

Referenced by widget_in().

#define LDELIM   '('

Definition at line 42 of file regress.c.

Referenced by widget_in().

#define NARGS   3

Definition at line 246 of file regress.c.

Referenced by widget_in().

#define P_MAXDIG   12

Definition at line 41 of file regress.c.

Referenced by poly2path().

#define RDELIM   ')'

Definition at line 43 of file regress.c.

Referenced by poly2path(), and widget_in().

#define TTDUMMY_INFINITY   999999

Definition at line 459 of file regress.c.

Referenced by ttdummy().

Function Documentation

Datum boxarea ( PG_FUNCTION_ARGS  )

Definition at line 297 of file regress.c.

References Abs, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_FLOAT8, Point::x, and Point::y.

298 {
299  BOX *box = PG_GETARG_BOX_P(0);
300  double width,
301  height;
302 
303  width = Abs(box->high.x - box->low.x);
304  height = Abs(box->high.y - box->low.y);
305  PG_RETURN_FLOAT8(width * height);
306 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double y
Definition: geo_decls.h:60
#define Abs(x)
Definition: c.h:812
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104
Datum funny_dup17 ( PG_FUNCTION_ARGS  )

Definition at line 352 of file regress.c.

References CALLED_AS_TRIGGER, CStringGetDatum, DatumGetInt32, DEBUG4, DirectFunctionCall1, elog, ERROR, fd17a_level, fd17a_recursion, fd17a_xid, fd17b_level, fd17b_recursion, fd17b_xid, GetCurrentTransactionId(), int4in(), InvalidTransactionId, NAMEDATALEN, palloc(), PointerGetDatum, RelationData::rd_att, SPI_connect(), SPI_exec(), SPI_finish(), SPI_fname(), SPI_getrelname(), SPI_gettype(), SPI_getvalue(), SPI_processed, SPI_tuptable, TriggerData::tg_event, TriggerData::tg_relation, TriggerData::tg_trigtuple, TransactionIdIsCurrentTransactionId(), TRIGGER_FIRED_BEFORE, SPITupleTable::tupdesc, UINT64_FORMAT, and SPITupleTable::vals.

353 {
354  TriggerData *trigdata = (TriggerData *) fcinfo->context;
355  TransactionId *xid;
356  int *level;
357  bool *recursion;
358  Relation rel;
359  TupleDesc tupdesc;
360  HeapTuple tuple;
361  char *query,
362  *fieldval,
363  *fieldtype;
364  char *when;
365  uint64 inserted;
366  int selected = 0;
367  int ret;
368 
369  if (!CALLED_AS_TRIGGER(fcinfo))
370  elog(ERROR, "funny_dup17: not fired by trigger manager");
371 
372  tuple = trigdata->tg_trigtuple;
373  rel = trigdata->tg_relation;
374  tupdesc = rel->rd_att;
375  if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
376  {
377  xid = &fd17b_xid;
378  level = &fd17b_level;
379  recursion = &fd17b_recursion;
380  when = "BEFORE";
381  }
382  else
383  {
384  xid = &fd17a_xid;
385  level = &fd17a_level;
386  recursion = &fd17a_recursion;
387  when = "AFTER ";
388  }
389 
391  {
392  *xid = GetCurrentTransactionId();
393  *level = 0;
394  *recursion = true;
395  }
396 
397  if (*level == 17)
398  {
399  *recursion = false;
400  return PointerGetDatum(tuple);
401  }
402 
403  if (!(*recursion))
404  return PointerGetDatum(tuple);
405 
406  (*level)++;
407 
408  SPI_connect();
409 
410  fieldval = SPI_getvalue(tuple, tupdesc, 1);
411  fieldtype = SPI_gettype(tupdesc, 1);
412 
413  query = (char *) palloc(100 + NAMEDATALEN * 3 +
414  strlen(fieldval) + strlen(fieldtype));
415 
416  sprintf(query, "insert into %s select * from %s where %s = '%s'::%s",
417  SPI_getrelname(rel), SPI_getrelname(rel),
418  SPI_fname(tupdesc, 1),
419  fieldval, fieldtype);
420 
421  if ((ret = SPI_exec(query, 0)) < 0)
422  elog(ERROR, "funny_dup17 (fired %s) on level %3d: SPI_exec (insert ...) returned %d",
423  when, *level, ret);
424 
425  inserted = SPI_processed;
426 
427  sprintf(query, "select count (*) from %s where %s = '%s'::%s",
428  SPI_getrelname(rel),
429  SPI_fname(tupdesc, 1),
430  fieldval, fieldtype);
431 
432  if ((ret = SPI_exec(query, 0)) < 0)
433  elog(ERROR, "funny_dup17 (fired %s) on level %3d: SPI_exec (select ...) returned %d",
434  when, *level, ret);
435 
436  if (SPI_processed > 0)
437  {
440  SPI_tuptable->vals[0],
442  1
443  ))));
444  }
445 
446  elog(DEBUG4, "funny_dup17 (fired %s) on level %3d: " UINT64_FORMAT "/%d tuples inserted/selected",
447  when, *level, inserted, selected);
448 
449  SPI_finish();
450 
451  (*level)--;
452 
453  if (*level == 0)
454  *xid = InvalidTransactionId;
455 
456  return PointerGetDatum(tuple);
457 }
static TransactionId fd17a_xid
Definition: regress.c:343
uint32 TransactionId
Definition: c.h:397
#define DatumGetInt32(X)
Definition: postgres.h:478
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
Definition: xact.c:773
int SPI_connect(void)
Definition: spi.c:84
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:266
int SPI_finish(void)
Definition: spi.c:147
SPITupleTable * SPI_tuptable
Definition: spi.c:41
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
HeapTuple * vals
Definition: spi.h:27
#define DEBUG4
Definition: elog.h:22
uint64 SPI_processed
Definition: spi.c:39
HeapTuple tg_trigtuple
Definition: trigger.h:35
char * SPI_gettype(TupleDesc tupdesc, int fnumber)
Definition: spi.c:851
char * SPI_fname(TupleDesc tupdesc, int fnumber)
Definition: spi.c:781
char * SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Definition: spi.c:803
#define NAMEDATALEN
#define ERROR
Definition: elog.h:43
int SPI_exec(const char *src, long tcount)
Definition: spi.c:331
static int fd17b_level
Definition: regress.c:344
static bool fd17a_recursion
Definition: regress.c:347
static int fd17a_level
Definition: regress.c:345
TransactionId GetCurrentTransactionId(void)
Definition: xact.c:417
#define CStringGetDatum(X)
Definition: postgres.h:584
#define InvalidTransactionId
Definition: transam.h:31
Definition: type.h:83
static TransactionId fd17b_xid
Definition: regress.c:342
static bool fd17b_recursion
Definition: regress.c:346
TupleDesc tupdesc
Definition: spi.h:26
TupleDesc rd_att
Definition: rel.h:115
char * SPI_getrelname(Relation rel)
Definition: spi.c:909
#define CALLED_AS_TRIGGER(fcinfo)
Definition: trigger.h:25
TriggerEvent tg_event
Definition: trigger.h:33
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:88
void * palloc(Size size)
Definition: mcxt.c:849
#define elog
Definition: elog.h:219
#define UINT64_FORMAT
Definition: c.h:316
Relation tg_relation
Definition: trigger.h:34
Datum int44in ( PG_FUNCTION_ARGS  )

Definition at line 694 of file regress.c.

References i, palloc(), PG_GETARG_CSTRING, PG_RETURN_POINTER, and result.

695 {
696  char *input_string = PG_GETARG_CSTRING(0);
697  int32 *result = (int32 *) palloc(4 * sizeof(int32));
698  int i;
699 
700  i = sscanf(input_string,
701  "%d, %d, %d, %d",
702  &result[0],
703  &result[1],
704  &result[2],
705  &result[3]);
706  while (i < 4)
707  result[i++] = 0;
708 
709  PG_RETURN_POINTER(result);
710 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
return result
Definition: formatting.c:1618
signed int int32
Definition: c.h:256
void * palloc(Size size)
Definition: mcxt.c:849
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum int44out ( PG_FUNCTION_ARGS  )

Definition at line 718 of file regress.c.

References i, palloc(), PG_GETARG_POINTER, pg_ltoa(), PG_RETURN_CSTRING, and result.

719 {
720  int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
721  char *result = (char *) palloc(16 * 4); /* Allow 14 digits +
722  * sign */
723  int i;
724  char *walk;
725 
726  walk = result;
727  for (i = 0; i < 4; i++)
728  {
729  pg_ltoa(an_array[i], walk);
730  while (*++walk != '\0')
731  ;
732  *walk++ = ' ';
733  }
734  *--walk = '\0';
735  PG_RETURN_CSTRING(result);
736 }
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
signed int int32
Definition: c.h:256
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:849
int i
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:132
Datum interpt_pp ( PG_FUNCTION_ARGS  )

Definition at line 168 of file regress.c.

References DatumGetBool, DirectFunctionCall2, i, lseg_interpt(), lseg_intersect(), LsegPGetDatum, PATH::npts, PATH::p, PG_GETARG_PATH_P, PG_RETURN_DATUM, PG_RETURN_NULL, and regress_lseg_construct().

169 {
170  PATH *p1 = PG_GETARG_PATH_P(0);
171  PATH *p2 = PG_GETARG_PATH_P(1);
172  int i,
173  j;
174  LSEG seg1,
175  seg2;
176  bool found; /* We've found the intersection */
177 
178  found = false; /* Haven't found it yet */
179 
180  for (i = 0; i < p1->npts - 1 && !found; i++)
181  {
182  regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
183  for (j = 0; j < p2->npts - 1 && !found; j++)
184  {
185  regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
187  LsegPGetDatum(&seg1),
188  LsegPGetDatum(&seg2))))
189  found = true;
190  }
191  }
192 
193  if (!found)
194  PG_RETURN_NULL();
195 
196  /*
197  * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
198  * returns NULL, but that should be impossible since we know the two
199  * segments intersect.
200  */
202  LsegPGetDatum(&seg1),
203  LsegPGetDatum(&seg2)));
204 }
void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:209
Definition: geo_decls.h:68
Datum lseg_interpt(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2310
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:83
int32 npts
Definition: geo_decls.h:80
#define DatumGetBool(X)
Definition: postgres.h:399
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:150
Datum lseg_intersect(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2051
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
Definition: geo_decls.h:77
int i
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum make_tuple_indirect ( PG_FUNCTION_ARGS  )

Definition at line 740 of file regress.c.

References tupleDesc::attrs, DatumGetPointer, heap_deform_tuple(), heap_form_tuple(), heap_tuple_fetch_attr(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, i, INDIRECT_POINTER_SIZE, InvalidOid, ItemPointerSetInvalid, lookup_rowtype_tupdesc(), MemoryContextSwitchTo(), tupleDesc::natts, palloc(), palloc0(), pfree(), PG_GETARG_HEAPTUPLEHEADER, PG_RETURN_POINTER, varatt_indirect::pointer, PointerGetDatum, ReleaseTupleDesc, SET_VARTAG_EXTERNAL, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, TopTransactionContext, values, VARATT_IS_EXTERNAL_INDIRECT, VARATT_IS_EXTERNAL_ONDISK, VARDATA_EXTERNAL, VARSIZE_ANY, and VARTAG_INDIRECT.

741 {
743  HeapTupleData tuple;
744  int ncolumns;
745  Datum *values;
746  bool *nulls;
747 
748  Oid tupType;
749  int32 tupTypmod;
750  TupleDesc tupdesc;
751 
752  HeapTuple newtup;
753 
754  int i;
755 
756  MemoryContext old_context;
757 
758  /* Extract type info from the tuple itself */
759  tupType = HeapTupleHeaderGetTypeId(rec);
760  tupTypmod = HeapTupleHeaderGetTypMod(rec);
761  tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
762  ncolumns = tupdesc->natts;
763 
764  /* Build a temporary HeapTuple control structure */
766  ItemPointerSetInvalid(&(tuple.t_self));
767  tuple.t_tableOid = InvalidOid;
768  tuple.t_data = rec;
769 
770  values = (Datum *) palloc(ncolumns * sizeof(Datum));
771  nulls = (bool *) palloc(ncolumns * sizeof(bool));
772 
773  heap_deform_tuple(&tuple, tupdesc, values, nulls);
774 
776 
777  for (i = 0; i < ncolumns; i++)
778  {
779  struct varlena *attr;
780  struct varlena *new_attr;
781  struct varatt_indirect redirect_pointer;
782 
783  /* only work on existing, not-null varlenas */
784  if (tupdesc->attrs[i]->attisdropped ||
785  nulls[i] ||
786  tupdesc->attrs[i]->attlen != -1)
787  continue;
788 
789  attr = (struct varlena *) DatumGetPointer(values[i]);
790 
791  /* don't recursively indirect */
792  if (VARATT_IS_EXTERNAL_INDIRECT(attr))
793  continue;
794 
795  /* copy datum, so it still lives later */
796  if (VARATT_IS_EXTERNAL_ONDISK(attr))
797  attr = heap_tuple_fetch_attr(attr);
798  else
799  {
800  struct varlena *oldattr = attr;
801 
802  attr = palloc0(VARSIZE_ANY(oldattr));
803  memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
804  }
805 
806  /* build indirection Datum */
807  new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
808  redirect_pointer.pointer = attr;
810  memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
811  sizeof(redirect_pointer));
812 
813  values[i] = PointerGetDatum(new_attr);
814  }
815 
816  newtup = heap_form_tuple(tupdesc, values, nulls);
817  pfree(values);
818  pfree(nulls);
819  ReleaseTupleDesc(tupdesc);
820 
821  MemoryContextSwitchTo(old_context);
822 
823  /*
824  * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
825  * would cause the indirect toast pointers to be flattened out of the
826  * tuple immediately, rendering subsequent testing irrelevant. So just
827  * return the HeapTupleHeader pointer as-is. This violates the general
828  * rule that composite Datums shouldn't contain toast pointers, but so
829  * long as the regression test scripts don't insert the result of this
830  * function into a container type (record, array, etc) it should be OK.
831  */
832  PG_RETURN_POINTER(newtup->t_data);
833 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: postgres.h:315
MemoryContext TopTransactionContext
Definition: mcxt.c:48
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1257
#define PointerGetDatum(X)
Definition: postgres.h:562
struct varlena * heap_tuple_fetch_attr(struct varlena *attr)
Definition: tuptoaster.c:101
Form_pg_attribute * attrs
Definition: tupdesc.h:74
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:276
unsigned int Oid
Definition: postgres_ext.h:31
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:311
int natts
Definition: tupdesc.h:73
signed int int32
Definition: c.h:256
HeapTupleHeader t_data
Definition: htup.h:67
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:455
void pfree(void *pointer)
Definition: mcxt.c:950
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
Definition: postgres.h:317
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: postgres.h:332
Oid t_tableOid
Definition: htup.h:66
#define INDIRECT_POINTER_SIZE
Definition: tuptoaster.h:102
void * palloc0(Size size)
Definition: mcxt.c:878
uintptr_t Datum
Definition: postgres.h:372
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:445
#define VARSIZE_ANY(PTR)
Definition: postgres.h:334
#define InvalidOid
Definition: postgres_ext.h:36
#define DatumGetPointer(X)
Definition: postgres.h:555
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:935
static Datum values[MAXATTR]
Definition: bootstrap.c:162
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:149
void * palloc(Size size)
Definition: mcxt.c:849
int i
Definition: c.h:439
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:107
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:439
int oldstyle_length ( int  n,
text t 
)

Definition at line 331 of file regress.c.

References VARHDRSZ, and VARSIZE.

332 {
333  int len = 0;
334 
335  if (t)
336  len = VARSIZE(t) - VARHDRSZ;
337 
338  return n + len;
339 }
#define VARSIZE(PTR)
Definition: postgres.h:304
#define VARHDRSZ
Definition: c.h:445
Datum overpaid ( PG_FUNCTION_ARGS  )

Definition at line 220 of file regress.c.

References DatumGetInt32, GetAttributeByName(), PG_GETARG_HEAPTUPLEHEADER, PG_RETURN_BOOL, and PG_RETURN_NULL.

221 {
223  bool isnull;
224  int32 salary;
225 
226  salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
227  if (isnull)
228  PG_RETURN_NULL();
229  PG_RETURN_BOOL(salary > 699);
230 }
#define DatumGetInt32(X)
Definition: postgres.h:478
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:850
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:276
signed int int32
Definition: c.h:256
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_RETURN_NULL()
Definition: fmgr.h:305
PG_FUNCTION_INFO_V1 ( regress_dist_ptpath  )
PG_FUNCTION_INFO_V1 ( regress_path_dist  )
PG_FUNCTION_INFO_V1 ( interpt_pp  )
PG_FUNCTION_INFO_V1 ( overpaid  )
PG_FUNCTION_INFO_V1 ( pt_in_widget  )
PG_FUNCTION_INFO_V1 ( boxarea  )
PG_FUNCTION_INFO_V1 ( funny_dup17  )
PG_FUNCTION_INFO_V1 ( ttdummy  )
PG_FUNCTION_INFO_V1 ( set_ttdummy  )
PG_FUNCTION_INFO_V1 ( int44in  )
PG_FUNCTION_INFO_V1 ( int44out  )
PG_FUNCTION_INFO_V1 ( make_tuple_indirect  )
PG_FUNCTION_INFO_V1 ( regress_putenv  )
PG_FUNCTION_INFO_V1 ( wait_pid  )
PG_FUNCTION_INFO_V1 ( test_atomic_ops  )
PATH * poly2path ( POLYGON poly)

Definition at line 143 of file regress.c.

References buf, CStringGetDatum, DatumGetPathP, DirectFunctionCall1, i, POLYGON::npts, output(), POLYGON::p, P_MAXDIG, palloc(), path_in(), RDELIM, snprintf(), Point::x, and Point::y.

144 {
145  int i;
146  char *output = (char *) palloc(2 * (P_MAXDIG + 1) * poly->npts + 64);
147  char buf[2 * (P_MAXDIG) + 20];
148 
149  sprintf(output, "(1, %*d", P_MAXDIG, poly->npts);
150 
151  for (i = 0; i < poly->npts; i++)
152  {
153  snprintf(buf, sizeof(buf), ",%*g,%*g",
154  P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
155  strcat(output, buf);
156  }
157 
158  snprintf(buf, sizeof(buf), "%c", RDELIM);
159  strcat(output, buf);
161  CStringGetDatum(output)));
162 }
#define DatumGetPathP(X)
Definition: geo_decls.h:147
#define RDELIM
Definition: regress.c:43
static void output(uint64 loop_count)
double y
Definition: geo_decls.h:60
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
int32 npts
Definition: geo_decls.h:116
double x
Definition: geo_decls.h:60
#define P_MAXDIG
Definition: regress.c:41
static char * buf
Definition: pg_test_fsync.c:65
#define CStringGetDatum(X)
Definition: postgres.h:584
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:118
Datum path_in(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1307
void * palloc(Size size)
Definition: mcxt.c:849
int i
Datum pt_in_widget ( PG_FUNCTION_ARGS  )

Definition at line 286 of file regress.c.

References WIDGET::center, PG_GETARG_POINT_P, PG_GETARG_POINTER, PG_RETURN_BOOL, point_dt(), and WIDGET::radius.

287 {
288  Point *point = PG_GETARG_POINT_P(0);
289  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
290 
291  PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius);
292 }
double radius
Definition: regress.c:240
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1906
Point center
Definition: regress.c:239
Datum regress_dist_ptpath ( PG_FUNCTION_ARGS  )

Definition at line 62 of file regress.c.

References Assert, DatumGetFloat8, DirectFunctionCall2, dist_ps(), i, LsegPGetDatum, PATH::npts, PATH::p, PG_GETARG_PATH_P, PG_GETARG_POINT_P, PG_RETURN_FLOAT8, PG_RETURN_NULL, point_dt(), PointPGetDatum, regress_lseg_construct(), and result.

63 {
64  Point *pt = PG_GETARG_POINT_P(0);
65  PATH *path = PG_GETARG_PATH_P(1);
66  float8 result = 0.0; /* keep compiler quiet */
67  float8 tmp;
68  int i;
69  LSEG lseg;
70 
71  switch (path->npts)
72  {
73  case 0:
75  case 1:
76  result = point_dt(pt, &path->p[0]);
77  break;
78  default:
79 
80  /*
81  * the distance from a point to a path is the smallest distance
82  * from the point to any of its constituent segments.
83  */
84  Assert(path->npts > 1);
85  for (i = 0; i < path->npts - 1; ++i)
86  {
87  regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]);
89  PointPGetDatum(pt),
90  LsegPGetDatum(&lseg)));
91  if (i == 0 || tmp < result)
92  result = tmp;
93  }
94  break;
95  }
96  PG_RETURN_FLOAT8(result);
97 }
void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:209
Definition: geo_decls.h:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
return result
Definition: formatting.c:1618
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
double float8
Definition: c.h:381
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:83
int32 npts
Definition: geo_decls.h:80
Datum dist_ps(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2358
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:150
#define DatumGetFloat8(X)
Definition: postgres.h:734
#define Assert(condition)
Definition: c.h:675
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1906
Definition: geo_decls.h:77
int i
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PointPGetDatum(X)
Definition: geo_decls.h:138
void regress_lseg_construct ( LSEG lseg,
Point pt1,
Point pt2 
)

Definition at line 209 of file regress.c.

References LSEG::p, Point::x, and Point::y.

Referenced by interpt_pp(), regress_dist_ptpath(), and regress_path_dist().

210 {
211  lseg->p[0].x = pt1->x;
212  lseg->p[0].y = pt1->y;
213  lseg->p[1].x = pt2->x;
214  lseg->p[1].y = pt2->y;
215 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point p[2]
Definition: geo_decls.h:70
Datum regress_path_dist ( PG_FUNCTION_ARGS  )

Definition at line 106 of file regress.c.

References DatumGetFloat8, DirectFunctionCall2, i, lseg_distance(), LsegPGetDatum, PATH::npts, PATH::p, PG_GETARG_PATH_P, PG_RETURN_FLOAT8, PG_RETURN_NULL, and regress_lseg_construct().

107 {
108  PATH *p1 = PG_GETARG_PATH_P(0);
109  PATH *p2 = PG_GETARG_PATH_P(1);
110  bool have_min = false;
111  float8 min = 0.0; /* initialize to keep compiler quiet */
112  float8 tmp;
113  int i,
114  j;
115  LSEG seg1,
116  seg2;
117 
118  for (i = 0; i < p1->npts - 1; i++)
119  {
120  for (j = 0; j < p2->npts - 1; j++)
121  {
122  regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
123  regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
124 
126  LsegPGetDatum(&seg1),
127  LsegPGetDatum(&seg2)));
128  if (!have_min || tmp < min)
129  {
130  min = tmp;
131  have_min = true;
132  }
133  }
134  }
135 
136  if (!have_min)
137  PG_RETURN_NULL();
138 
139  PG_RETURN_FLOAT8(min);
140 }
void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:209
Definition: geo_decls.h:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
double float8
Definition: c.h:381
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:83
int32 npts
Definition: geo_decls.h:80
Datum lseg_distance(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2209
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:150
#define DatumGetFloat8(X)
Definition: postgres.h:734
Definition: geo_decls.h:77
int i
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum regress_putenv ( PG_FUNCTION_ARGS  )

Definition at line 838 of file regress.c.

References elog, ERROR, MemoryContextSwitchTo(), PG_GETARG_POINTER, PG_RETURN_VOID, putenv, superuser(), text_to_cstring(), and TopMemoryContext.

839 {
840  MemoryContext oldcontext;
841  char *envbuf;
842 
843  if (!superuser())
844  elog(ERROR, "must be superuser to change environment variables");
845 
847  envbuf = text_to_cstring((text *) PG_GETARG_POINTER(0));
848  MemoryContextSwitchTo(oldcontext);
849 
850  if (putenv(envbuf) != 0)
851  elog(ERROR, "could not set environment variable: %m");
852 
853  PG_RETURN_VOID();
854 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:47
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define putenv(x)
Definition: win32.h:421
#define ERROR
Definition: elog.h:43
MemoryContext TopMemoryContext
Definition: mcxt.c:43
#define PG_RETURN_VOID()
Definition: fmgr.h:309
char * text_to_cstring(const text *t)
Definition: varlena.c:182
Definition: c.h:439
#define elog
Definition: elog.h:219
char * reverse_name ( char *  string)

Definition at line 309 of file regress.c.

References i, NAMEDATALEN, and palloc0().

310 {
311  int i;
312  int len;
313  char *new_string;
314 
315  new_string = palloc0(NAMEDATALEN);
316  for (i = 0; i < NAMEDATALEN && string[i]; ++i)
317  ;
318  if (i == NAMEDATALEN || !string[i])
319  --i;
320  len = i;
321  for (; i >= 0; --i)
322  new_string[len - i] = string[i];
323  return new_string;
324 }
#define NAMEDATALEN
void * palloc0(Size size)
Definition: mcxt.c:878
int i
Datum set_ttdummy ( PG_FUNCTION_ARGS  )

Definition at line 656 of file regress.c.

References PG_GETARG_INT32, PG_RETURN_INT32, and ttoff.

657 {
658  int32 on = PG_GETARG_INT32(0);
659 
660  if (ttoff) /* OFF currently */
661  {
662  if (on == 0)
663  PG_RETURN_INT32(0);
664 
665  /* turn ON */
666  ttoff = false;
667  PG_RETURN_INT32(0);
668  }
669 
670  /* ON currently */
671  if (on != 0)
672  PG_RETURN_INT32(1);
673 
674  /* turn OFF */
675  ttoff = true;
676 
677  PG_RETURN_INT32(1);
678 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
static bool ttoff
Definition: regress.c:462
Datum test_atomic_ops ( PG_FUNCTION_ARGS  )

Definition at line 1092 of file regress.c.

References PG_RETURN_BOOL, and test_atomic_uint32().

1093 {
1094  /* ---
1095  * Can't run the test under the semaphore emulation, it doesn't handle
1096  * checking two edge cases well:
1097  * - pg_atomic_unlocked_test_flag() always returns true
1098  * - locking a already locked flag blocks
1099  * it seems better to not test the semaphore fallback here, than weaken
1100  * the checks for the other cases. The semaphore code will be the same
1101  * everywhere, whereas the efficient implementations wont.
1102  * ---
1103  */
1104 #ifndef PG_HAVE_ATOMIC_FLAG_SIMULATION
1105  test_atomic_flag();
1106 #endif
1107 
1109 
1110 #ifdef PG_HAVE_ATOMIC_U64_SUPPORT
1111  test_atomic_uint64();
1112 #endif
1113 
1114  PG_RETURN_BOOL(true);
1115 }
static void test_atomic_uint32(void)
Definition: regress.c:912
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static void test_atomic_uint32 ( void  )
static

Definition at line 912 of file regress.c.

References elog, ERROR, i, pg_atomic_add_fetch_u32(), pg_atomic_compare_exchange_u32(), pg_atomic_exchange_u32(), pg_atomic_fetch_add_u32(), pg_atomic_fetch_and_u32(), pg_atomic_fetch_or_u32(), pg_atomic_fetch_sub_u32(), pg_atomic_init_u32(), pg_atomic_read_u32(), pg_atomic_sub_fetch_u32(), and pg_atomic_write_u32().

Referenced by test_atomic_ops().

913 {
914  pg_atomic_uint32 var;
915  uint32 expected;
916  int i;
917 
918  pg_atomic_init_u32(&var, 0);
919 
920  if (pg_atomic_read_u32(&var) != 0)
921  elog(ERROR, "atomic_read_u32() #1 wrong");
922 
923  pg_atomic_write_u32(&var, 3);
924 
925  if (pg_atomic_read_u32(&var) != 3)
926  elog(ERROR, "atomic_read_u32() #2 wrong");
927 
928  if (pg_atomic_fetch_add_u32(&var, 1) != 3)
929  elog(ERROR, "atomic_fetch_add_u32() #1 wrong");
930 
931  if (pg_atomic_fetch_sub_u32(&var, 1) != 4)
932  elog(ERROR, "atomic_fetch_sub_u32() #1 wrong");
933 
934  if (pg_atomic_sub_fetch_u32(&var, 3) != 0)
935  elog(ERROR, "atomic_sub_fetch_u32() #1 wrong");
936 
937  if (pg_atomic_add_fetch_u32(&var, 10) != 10)
938  elog(ERROR, "atomic_add_fetch_u32() #1 wrong");
939 
940  if (pg_atomic_exchange_u32(&var, 5) != 10)
941  elog(ERROR, "pg_atomic_exchange_u32() #1 wrong");
942 
943  if (pg_atomic_exchange_u32(&var, 0) != 5)
944  elog(ERROR, "pg_atomic_exchange_u32() #0 wrong");
945 
946  /* test around numerical limits */
947  if (pg_atomic_fetch_add_u32(&var, INT_MAX) != 0)
948  elog(ERROR, "pg_atomic_fetch_add_u32() #2 wrong");
949 
950  if (pg_atomic_fetch_add_u32(&var, INT_MAX) != INT_MAX)
951  elog(ERROR, "pg_atomic_add_fetch_u32() #3 wrong");
952 
953  pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
954 
955  if (pg_atomic_read_u32(&var) != UINT_MAX)
956  elog(ERROR, "atomic_read_u32() #2 wrong");
957 
958  if (pg_atomic_fetch_sub_u32(&var, INT_MAX) != UINT_MAX)
959  elog(ERROR, "pg_atomic_fetch_sub_u32() #2 wrong");
960 
961  if (pg_atomic_read_u32(&var) != (uint32) INT_MAX + 1)
962  elog(ERROR, "atomic_read_u32() #3 wrong: %u", pg_atomic_read_u32(&var));
963 
964  expected = pg_atomic_sub_fetch_u32(&var, INT_MAX);
965  if (expected != 1)
966  elog(ERROR, "pg_atomic_sub_fetch_u32() #3 wrong: %u", expected);
967 
968  pg_atomic_sub_fetch_u32(&var, 1);
969 
970  /* fail exchange because of old expected */
971  expected = 10;
972  if (pg_atomic_compare_exchange_u32(&var, &expected, 1))
973  elog(ERROR, "atomic_compare_exchange_u32() changed value spuriously");
974 
975  /* CAS is allowed to fail due to interrupts, try a couple of times */
976  for (i = 0; i < 1000; i++)
977  {
978  expected = 0;
979  if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
980  break;
981  }
982  if (i == 1000)
983  elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
984  if (pg_atomic_read_u32(&var) != 1)
985  elog(ERROR, "atomic_compare_exchange_u32() didn't set value properly");
986 
987  pg_atomic_write_u32(&var, 0);
988 
989  /* try setting flagbits */
990  if (pg_atomic_fetch_or_u32(&var, 1) & 1)
991  elog(ERROR, "pg_atomic_fetch_or_u32() #1 wrong");
992 
993  if (!(pg_atomic_fetch_or_u32(&var, 2) & 1))
994  elog(ERROR, "pg_atomic_fetch_or_u32() #2 wrong");
995 
996  if (pg_atomic_read_u32(&var) != 3)
997  elog(ERROR, "invalid result after pg_atomic_fetch_or_u32()");
998 
999  /* try clearing flagbits */
1000  if ((pg_atomic_fetch_and_u32(&var, ~2) & 3) != 3)
1001  elog(ERROR, "pg_atomic_fetch_and_u32() #1 wrong");
1002 
1003  if (pg_atomic_fetch_and_u32(&var, ~1) != 1)
1004  elog(ERROR, "pg_atomic_fetch_and_u32() #2 wrong: is %u",
1005  pg_atomic_read_u32(&var));
1006  /* no bits set anymore */
1007  if (pg_atomic_fetch_and_u32(&var, ~0) != 0)
1008  elog(ERROR, "pg_atomic_fetch_and_u32() #3 wrong");
1009 }
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:353
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.h:321
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:411
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:396
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:302
#define ERROR
Definition: elog.h:43
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
Definition: atomics.h:368
unsigned int uint32
Definition: c.h:268
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:338
int i
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:382
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:233
#define elog
Definition: elog.h:219
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:268
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:251
Datum ttdummy ( PG_FUNCTION_ARGS  )

Definition at line 467 of file regress.c.

References generate_unaccent_rules::args, CALLED_AS_TRIGGER, CStringGetTextDatum, DatumGetInt64, DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, i, Int32GetDatum, INT4OID, nextval(), NULL, palloc(), pfree(), PointerGetDatum, SPI_connect(), SPI_execp(), SPI_finish(), SPI_fnumber(), SPI_getbinval(), SPI_getrelname(), SPI_gettypeid(), SPI_keepplan(), SPI_modifytuple(), SPI_prepare(), SPI_result, TriggerData::tg_event, TriggerData::tg_newtuple, TriggerData::tg_relation, TriggerData::tg_trigger, TriggerData::tg_trigtuple, TRIGGER_FIRED_BEFORE, TRIGGER_FIRED_BY_INSERT, TRIGGER_FIRED_BY_UPDATE, TRIGGER_FIRED_FOR_ROW, TTDUMMY_INFINITY, and ttoff.

468 {
469  TriggerData *trigdata = (TriggerData *) fcinfo->context;
470  Trigger *trigger; /* to get trigger name */
471  char **args; /* arguments */
472  int attnum[2]; /* fnumbers of start/stop columns */
473  Datum oldon,
474  oldoff;
475  Datum newon,
476  newoff;
477  Datum *cvals; /* column values */
478  char *cnulls; /* column nulls */
479  char *relname; /* triggered relation name */
480  Relation rel; /* triggered relation */
481  HeapTuple trigtuple;
482  HeapTuple newtuple = NULL;
483  HeapTuple rettuple;
484  TupleDesc tupdesc; /* tuple description */
485  int natts; /* # of attributes */
486  bool isnull; /* to know is some column NULL or not */
487  int ret;
488  int i;
489 
490  if (!CALLED_AS_TRIGGER(fcinfo))
491  elog(ERROR, "ttdummy: not fired by trigger manager");
492  if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
493  elog(ERROR, "ttdummy: must be fired for row");
494  if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
495  elog(ERROR, "ttdummy: must be fired before event");
496  if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
497  elog(ERROR, "ttdummy: cannot process INSERT event");
498  if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
499  newtuple = trigdata->tg_newtuple;
500 
501  trigtuple = trigdata->tg_trigtuple;
502 
503  rel = trigdata->tg_relation;
504  relname = SPI_getrelname(rel);
505 
506  /* check if TT is OFF for this relation */
507  if (ttoff) /* OFF - nothing to do */
508  {
509  pfree(relname);
510  return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);
511  }
512 
513  trigger = trigdata->tg_trigger;
514 
515  if (trigger->tgnargs != 2)
516  elog(ERROR, "ttdummy (%s): invalid (!= 2) number of arguments %d",
517  relname, trigger->tgnargs);
518 
519  args = trigger->tgargs;
520  tupdesc = rel->rd_att;
521  natts = tupdesc->natts;
522 
523  for (i = 0; i < 2; i++)
524  {
525  attnum[i] = SPI_fnumber(tupdesc, args[i]);
526  if (attnum[i] <= 0)
527  elog(ERROR, "ttdummy (%s): there is no attribute %s",
528  relname, args[i]);
529  if (SPI_gettypeid(tupdesc, attnum[i]) != INT4OID)
530  elog(ERROR, "ttdummy (%s): attribute %s must be of integer type",
531  relname, args[i]);
532  }
533 
534  oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);
535  if (isnull)
536  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
537 
538  oldoff = SPI_getbinval(trigtuple, tupdesc, attnum[1], &isnull);
539  if (isnull)
540  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
541 
542  if (newtuple != NULL) /* UPDATE */
543  {
544  newon = SPI_getbinval(newtuple, tupdesc, attnum[0], &isnull);
545  if (isnull)
546  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
547  newoff = SPI_getbinval(newtuple, tupdesc, attnum[1], &isnull);
548  if (isnull)
549  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
550 
551  if (oldon != newon || oldoff != newoff)
552  ereport(ERROR,
553  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
554  errmsg("ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
555  relname, args[0], args[1])));
556 
557  if (newoff != TTDUMMY_INFINITY)
558  {
559  pfree(relname); /* allocated in upper executor context */
560  return PointerGetDatum(NULL);
561  }
562  }
563  else if (oldoff != TTDUMMY_INFINITY) /* DELETE */
564  {
565  pfree(relname);
566  return PointerGetDatum(NULL);
567  }
568 
569  newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
570  /* nextval now returns int64; coerce down to int32 */
571  newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
572 
573  /* Connect to SPI manager */
574  if ((ret = SPI_connect()) < 0)
575  elog(ERROR, "ttdummy (%s): SPI_connect returned %d", relname, ret);
576 
577  /* Fetch tuple values and nulls */
578  cvals = (Datum *) palloc(natts * sizeof(Datum));
579  cnulls = (char *) palloc(natts * sizeof(char));
580  for (i = 0; i < natts; i++)
581  {
582  cvals[i] = SPI_getbinval((newtuple != NULL) ? newtuple : trigtuple,
583  tupdesc, i + 1, &isnull);
584  cnulls[i] = (isnull) ? 'n' : ' ';
585  }
586 
587  /* change date column(s) */
588  if (newtuple) /* UPDATE */
589  {
590  cvals[attnum[0] - 1] = newoff; /* start_date eq current date */
591  cnulls[attnum[0] - 1] = ' ';
592  cvals[attnum[1] - 1] = TTDUMMY_INFINITY; /* stop_date eq INFINITY */
593  cnulls[attnum[1] - 1] = ' ';
594  }
595  else
596  /* DELETE */
597  {
598  cvals[attnum[1] - 1] = newoff; /* stop_date eq current date */
599  cnulls[attnum[1] - 1] = ' ';
600  }
601 
602  /* if there is no plan ... */
603  if (splan == NULL)
604  {
605  SPIPlanPtr pplan;
606  Oid *ctypes;
607  char *query;
608 
609  /* allocate space in preparation */
610  ctypes = (Oid *) palloc(natts * sizeof(Oid));
611  query = (char *) palloc(100 + 16 * natts);
612 
613  /*
614  * Construct query: INSERT INTO _relation_ VALUES ($1, ...)
615  */
616  sprintf(query, "INSERT INTO %s VALUES (", relname);
617  for (i = 1; i <= natts; i++)
618  {
619  sprintf(query + strlen(query), "$%d%s",
620  i, (i < natts) ? ", " : ")");
621  ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
622  }
623 
624  /* Prepare plan for query */
625  pplan = SPI_prepare(query, natts, ctypes);
626  if (pplan == NULL)
627  elog(ERROR, "ttdummy (%s): SPI_prepare returned %d", relname, SPI_result);
628 
629  if (SPI_keepplan(pplan))
630  elog(ERROR, "ttdummy (%s): SPI_keepplan failed", relname);
631 
632  splan = pplan;
633  }
634 
635  ret = SPI_execp(splan, cvals, cnulls, 0);
636 
637  if (ret < 0)
638  elog(ERROR, "ttdummy (%s): SPI_execp returned %d", relname, ret);
639 
640  /* Tuple to return to upper Executor ... */
641  if (newtuple) /* UPDATE */
642  rettuple = SPI_modifytuple(rel, trigtuple, 1, &(attnum[1]), &newoff, NULL);
643  else /* DELETE */
644  rettuple = trigtuple;
645 
646  SPI_finish(); /* don't forget say Bye to SPI mgr */
647 
648  pfree(relname);
649 
650  return PointerGetDatum(rettuple);
651 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:760
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:891
int SPI_connect(void)
Definition: spi.c:84
#define PointerGetDatum(X)
Definition: postgres.h:562
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
Definition: spi.c:481
int SPI_finish(void)
Definition: spi.c:147
Datum nextval(PG_FUNCTION_ARGS)
Definition: sequence.c:539
#define INT4OID
Definition: pg_type.h:316
int errcode(int sqlerrcode)
Definition: elog.c:575
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
HeapTuple tg_trigtuple
Definition: trigger.h:35
signed int int32
Definition: c.h:256
static bool ttoff
Definition: regress.c:462
int SPI_result
Definition: spi.c:42
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:835
#define DatumGetInt64(X)
Definition: postgres.h:613
int SPI_keepplan(SPIPlanPtr plan)
Definition: spi.c:559
static SPIPlanPtr splan
Definition: regress.c:461
HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls)
Definition: spi.c:689
#define ereport(elevel, rest)
Definition: elog.h:122
#define TTDUMMY_INFINITY
Definition: regress.c:459
uintptr_t Datum
Definition: postgres.h:372
Trigger * tg_trigger
Definition: trigger.h:37
HeapTuple tg_newtuple
Definition: trigger.h:36
char * SPI_getrelname(Relation rel)
Definition: spi.c:909
#define NULL
Definition: c.h:229
#define CALLED_AS_TRIGGER(fcinfo)
Definition: trigger.h:25
TriggerEvent tg_event
Definition: trigger.h:33
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:88
#define Int32GetDatum(X)
Definition: postgres.h:485
#define TRIGGER_FIRED_BY_INSERT(event)
Definition: trigger.h:70
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls, long tcount)
Definition: spi.c:365
#define CStringGetTextDatum(s)
Definition: builtins.h:91
#define elog
Definition: elog.h:219
#define TRIGGER_FIRED_FOR_ROW(event)
Definition: trigger.h:82
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition: trigger.h:76
Relation tg_relation
Definition: trigger.h:34
Datum wait_pid ( PG_FUNCTION_ARGS  )

Definition at line 860 of file regress.c.

References CHECK_FOR_INTERRUPTS, elog, ERROR, PG_GETARG_INT32, PG_RETURN_VOID, pg_usleep(), and superuser().

861 {
862  int pid = PG_GETARG_INT32(0);
863 
864  if (!superuser())
865  elog(ERROR, "must be superuser to check PID liveness");
866 
867  while (kill(pid, 0) == 0)
868  {
870  pg_usleep(50000);
871  }
872 
873  if (errno != ESRCH)
874  elog(ERROR, "could not check PID %d liveness: %m", pid);
875 
876  PG_RETURN_VOID();
877 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
bool superuser(void)
Definition: superuser.c:47
void pg_usleep(long microsec)
Definition: signal.c:53
#define ERROR
Definition: elog.h:43
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
#define elog
Definition: elog.h:219
WIDGET * widget_in ( char *  str)

Definition at line 249 of file regress.c.

References WIDGET::center, DELIM, ereport, errcode(), errmsg(), ERROR, i, LDELIM, NARGS, palloc(), WIDGET::radius, RDELIM, result, Point::x, and Point::y.

250 {
251  char *p,
252  *coord[NARGS];
253  int i;
254  WIDGET *result;
255 
256  for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
257  {
258  if (*p == DELIM || (*p == LDELIM && i == 0))
259  coord[i++] = p + 1;
260  }
261 
262  if (i < NARGS)
263  ereport(ERROR,
264  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
265  errmsg("invalid input syntax for type widget: \"%s\"",
266  str)));
267 
268  result = (WIDGET *) palloc(sizeof(WIDGET));
269  result->center.x = atof(coord[0]);
270  result->center.y = atof(coord[1]);
271  result->radius = atof(coord[2]);
272 
273  return result;
274 }
double radius
Definition: regress.c:240
#define RDELIM
Definition: regress.c:43
double y
Definition: geo_decls.h:60
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
double x
Definition: geo_decls.h:60
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define DELIM
Definition: regress.c:44
#define NARGS
Definition: regress.c:246
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
Point center
Definition: regress.c:239
int i
#define LDELIM
Definition: regress.c:42
char * widget_out ( WIDGET widget)

Definition at line 277 of file regress.c.

References WIDGET::center, psprintf(), WIDGET::radius, Point::x, and Point::y.

278 {
279  return psprintf("(%g,%g,%g)",
280  widget->center.x, widget->center.y, widget->radius);
281 }
double radius
Definition: regress.c:240
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point center
Definition: regress.c:239

Variable Documentation

int fd17a_level = 0
static

Definition at line 345 of file regress.c.

Referenced by funny_dup17().

bool fd17a_recursion = true
static

Definition at line 347 of file regress.c.

Referenced by funny_dup17().

TransactionId fd17a_xid = InvalidTransactionId
static

Definition at line 343 of file regress.c.

Referenced by funny_dup17().

int fd17b_level = 0
static

Definition at line 344 of file regress.c.

Referenced by funny_dup17().

bool fd17b_recursion = true
static

Definition at line 346 of file regress.c.

Referenced by funny_dup17().

TransactionId fd17b_xid = InvalidTransactionId
static

Definition at line 342 of file regress.c.

Referenced by funny_dup17().

PG_MODULE_MAGIC

Definition at line 52 of file regress.c.

SPIPlanPtr splan = NULL
static

Definition at line 461 of file regress.c.

Referenced by build_subplan(), ExecReScan(), get_rule_expr(), set_plan_refs(), and SS_process_ctes().

bool ttoff = false
static

Definition at line 462 of file regress.c.

Referenced by set_ttdummy(), and ttdummy().