<commit_before>/*-------------------------------------------------------------------------
 *
 * ipc_test.c
 *	   Simplistic testbed for shared memory and semaphore code.
 *
 * This file allows for quick "smoke testing" of a PG semaphore or shared
 * memory implementation, with less overhead than compiling up a whole
 * installation.  To use:
 *	1. Run configure, then edit src/include/pg_config.h to select the
 *	   USE_xxx_SEMAPHORES and USE_xxx_SHARED_MEMORY settings you want.
 *	   Also, adjust the pg_sema.c and pg_shmem.c symlinks in
 *	   src/backend/port/ if needed.
 *	2. In src/backend/port/, do "gmake ipc_test".
 *	3. Run ipc_test and see if it works.
 *	4. If it seems to work, try building the whole system and running
 *	   the parallel regression tests for a more complete test.
 *
 *
 * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  src/backend/port/ipc_test.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include <unistd.h>

#include "miscadmin.h"
#include "storage/ipc.h"
#include "storage/pg_sema.h"
#include "storage/pg_shmem.h"


/********* stuff needed to satisfy references in shmem/sema code *********/


volatile bool InterruptPending = false;
volatile bool QueryCancelPending = false;
volatile bool ProcDiePending = false;
volatile bool ImmediateInterruptOK = false;
volatile uint32 InterruptHoldoffCount = 0;
volatile uint32 CritSectionCount = 0;

bool		IsUnderPostmaster = false;
bool		assert_enabled = true;

int			MaxBackends = 32;
int			NBuffers = 64;

char	   *DataDir = ".";


#define MAX_ON_EXITS 20

static struct ONEXIT
{
	pg_on_exit_callback function;
	Datum		arg;
}	on_proc_exit_list[MAX_ON_EXITS], on_shmem_exit_list[MAX_ON_EXITS];

static int	on_proc_exit_index,
			on_shmem_exit_index;

void
proc_exit(int code)
{
	shmem_exit(code);
	while (--on_proc_exit_index >= 0)
		(*on_proc_exit_list[on_proc_exit_index].function) (code,
								  on_proc_exit_list[on_proc_exit_index].arg);
	exit(code);
}

void
shmem_exit(int code)
{
	while (--on_shmem_exit_index >= 0)
		(*on_shmem_exit_list[on_shmem_exit_index].function) (code,
								on_shmem_exit_list[on_shmem_exit_index].arg);
	on_shmem_exit_index = 0;
}

void
on_shmem_exit(pg_on_exit_callback function, Datum arg)
{
	if (on_shmem_exit_index >= MAX_ON_EXITS)
		elog(FATAL, "out of on_shmem_exit slots");

	on_shmem_exit_list[on_shmem_exit_index].function = function;
	on_shmem_exit_list[on_shmem_exit_index].arg = arg;

	++on_shmem_exit_index;
}

void
on_exit_reset(void)
{
	on_shmem_exit_index = 0;
	on_proc_exit_index = 0;
}

void
AddToDataDirLockFile(int target_line, const char *str)
{
}

void
ProcessInterrupts(void)
{
}

int
ExceptionalCondition(const char *conditionName,
					 const char *errorType,
					 const char *fileName,
					 int lineNumber)
{
	fprintf(stderr, "TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n",
			errorType, conditionName,
			fileName, lineNumber);
	abort();
	return 0;
}


int
errcode_for_file_access(void)
{
	return 0;
}

bool
errstart(int elevel, const char *filename, int lineno,
		 const char *funcname, const char *domain)
{
	return (elevel >= ERROR);
}

void
errfinish(int dummy,...)
{
	proc_exit(1);
}

void
elog_start(const char *filename, int lineno, const char *funcname)
{
}

void
elog_finish(int elevel, const char *fmt,...)
{
	fprintf(stderr, "ERROR: %s\n", fmt);<commit_msg>Change test ExceptionalCondition to return void<commit_after>/*-------------------------------------------------------------------------
 *
 * ipc_test.c
 *	   Simplistic testbed for shared memory and semaphore code.
 *
 * This file allows for quick "smoke testing" of a PG semaphore or shared
 * memory implementation, with less overhead than compiling up a whole
 * installation.  To use:
 *	1. Run configure, then edit src/include/pg_config.h to select the
 *	   USE_xxx_SEMAPHORES and USE_xxx_SHARED_MEMORY settings you want.
 *	   Also, adjust the pg_sema.c and pg_shmem.c symlinks in
 *	   src/backend/port/ if needed.
 *	2. In src/backend/port/, do "gmake ipc_test".
 *	3. Run ipc_test and see if it works.
 *	4. If it seems to work, try building the whole system and running
 *	   the parallel regression tests for a more complete test.
 *
 *
 * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  src/backend/port/ipc_test.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include <unistd.h>

#include "miscadmin.h"
#include "storage/ipc.h"
#include "storage/pg_sema.h"
#include "storage/pg_shmem.h"


/********* stuff needed to satisfy references in shmem/sema code *********/


volatile bool InterruptPending = false;
volatile bool QueryCancelPending = false;
volatile bool ProcDiePending = false;
volatile bool ImmediateInterruptOK = false;
volatile uint32 InterruptHoldoffCount = 0;
volatile uint32 CritSectionCount = 0;

bool		IsUnderPostmaster = false;
bool		assert_enabled = true;

int			MaxBackends = 32;
int			NBuffers = 64;

char	   *DataDir = ".";


#define MAX_ON_EXITS 20

static struct ONEXIT
{
	pg_on_exit_callback function;
	Datum		arg;
}	on_proc_exit_list[MAX_ON_EXITS], on_shmem_exit_list[MAX_ON_EXITS];

static int	on_proc_exit_index,
			on_shmem_exit_index;

void
proc_exit(int code)
{
	shmem_exit(code);
	while (--on_proc_exit_index >= 0)
		(*on_proc_exit_list[on_proc_exit_index].function) (code,
								  on_proc_exit_list[on_proc_exit_index].arg);
	exit(code);
}

void
shmem_exit(int code)
{
	while (--on_shmem_exit_index >= 0)
		(*on_shmem_exit_list[on_shmem_exit_index].function) (code,
								on_shmem_exit_list[on_shmem_exit_index].arg);
	on_shmem_exit_index = 0;
}

void
on_shmem_exit(pg_on_exit_callback function, Datum arg)
{
	if (on_shmem_exit_index >= MAX_ON_EXITS)
		elog(FATAL, "out of on_shmem_exit slots");

	on_shmem_exit_list[on_shmem_exit_index].function = function;
	on_shmem_exit_list[on_shmem_exit_index].arg = arg;

	++on_shmem_exit_index;
}

void
on_exit_reset(void)
{
	on_shmem_exit_index = 0;
	on_proc_exit_index = 0;
}

void
AddToDataDirLockFile(int target_line, const char *str)
{
}

void
ProcessInterrupts(void)
{
}

void
ExceptionalCondition(const char *conditionName,
					 const char *errorType,
					 const char *fileName,
					 int lineNumber)
{
	fprintf(stderr, "TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n",
			errorType, conditionName,
			fileName, lineNumber);
	abort();
}


int
errcode_for_file_access(void)
{
	return 0;
}

bool
errstart(int elevel, const char *filename, int lineno,
		 const char *funcname, const char *domain)
{
	return (elevel >= ERROR);
}

void
errfinish(int dummy,...)
{
	proc_exit(1);
}

void
elog_start(const char *filename, int lineno, const char *funcname)
{
}

void
elog_finish(int elevel, const char *fmt,...)
{
	fprintf(stderr, "ERROR: %s\n", fmt);
{'fraction_non_alphanumeric': 0.14560204953031597, 'fraction_numerical': 0.010105323085681753, 'mean_word_length': 3.6382838283828383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '93465', 'n_tokens_mistral': 2668, 'n_tokens_neox': 2508, 'n_words': 634}