Skip to content

Allow declaration after statement and reformat code to use it #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
48 changes: 0 additions & 48 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ BITCODE_CXXFLAGS
BITCODE_CFLAGS
CFLAGS_VECTORIZE
CFLAGS_UNROLL_LOOPS
PERMIT_DECLARATION_AFTER_STATEMENT
LLVM_BINPATH
LLVM_CXXFLAGS
LLVM_CFLAGS
Expand Down Expand Up @@ -5295,53 +5294,6 @@ if test "$GCC" = yes -a "$ICC" = no; then
CXXFLAGS="-Wall -Wpointer-arith"
# These work in some but not all gcc versions
save_CFLAGS=$CFLAGS

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wdeclaration-after-statement, for CFLAGS" >&5
$as_echo_n "checking whether ${CC} supports -Wdeclaration-after-statement, for CFLAGS... " >&6; }
if ${pgac_cv_prog_CC_cflags__Wdeclaration_after_statement+:} false; then :
$as_echo_n "(cached) " >&6
else
pgac_save_CFLAGS=$CFLAGS
pgac_save_CC=$CC
CC=${CC}
CFLAGS="${CFLAGS} -Wdeclaration-after-statement"
ac_save_c_werror_flag=$ac_c_werror_flag
ac_c_werror_flag=yes
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

int
main ()
{

;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
pgac_cv_prog_CC_cflags__Wdeclaration_after_statement=yes
else
pgac_cv_prog_CC_cflags__Wdeclaration_after_statement=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_c_werror_flag=$ac_save_c_werror_flag
CFLAGS="$pgac_save_CFLAGS"
CC="$pgac_save_CC"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wdeclaration_after_statement" >&5
$as_echo "$pgac_cv_prog_CC_cflags__Wdeclaration_after_statement" >&6; }
if test x"$pgac_cv_prog_CC_cflags__Wdeclaration_after_statement" = x"yes"; then
CFLAGS="${CFLAGS} -Wdeclaration-after-statement"
fi


# -Wdeclaration-after-statement isn't applicable for C++. Specific C files
# disable it, so AC_SUBST the negative form.
PERMIT_DECLARATION_AFTER_STATEMENT=
if test x"$save_CFLAGS" != x"$CFLAGS"; then
PERMIT_DECLARATION_AFTER_STATEMENT=-Wno-declaration-after-statement
fi

# Really don't want VLAs to be used in our dialect of C

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Werror=vla, for CFLAGS" >&5
Expand Down
8 changes: 0 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,6 @@ if test "$GCC" = yes -a "$ICC" = no; then
CXXFLAGS="-Wall -Wpointer-arith"
# These work in some but not all gcc versions
save_CFLAGS=$CFLAGS
PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
# -Wdeclaration-after-statement isn't applicable for C++. Specific C files
# disable it, so AC_SUBST the negative form.
PERMIT_DECLARATION_AFTER_STATEMENT=
if test x"$save_CFLAGS" != x"$CFLAGS"; then
PERMIT_DECLARATION_AFTER_STATEMENT=-Wno-declaration-after-statement
fi
AC_SUBST(PERMIT_DECLARATION_AFTER_STATEMENT)
# Really don't want VLAs to be used in our dialect of C
PGAC_PROG_CC_CFLAGS_OPT([-Werror=vla])
# On macOS, complain about usage of symbols newer than the deployment target
Expand Down
68 changes: 26 additions & 42 deletions contrib/adminpack/adminpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ pg_file_write(PG_FUNCTION_ARGS)
text *file = PG_GETARG_TEXT_PP(0);
text *data = PG_GETARG_TEXT_PP(1);
bool replace = PG_GETARG_BOOL(2);
int64 count = 0;

requireSuperuser();

count = pg_file_write_internal(file, data, replace);
int64 count = pg_file_write_internal(file, data, replace);

PG_RETURN_INT64(count);
}
Expand All @@ -160,9 +159,8 @@ pg_file_write_v1_1(PG_FUNCTION_ARGS)
text *file = PG_GETARG_TEXT_PP(0);
text *data = PG_GETARG_TEXT_PP(1);
bool replace = PG_GETARG_BOOL(2);
int64 count = 0;

count = pg_file_write_internal(file, data, replace);
int64 count = pg_file_write_internal(file, data, replace);

PG_RETURN_INT64(count);
}
Expand All @@ -176,10 +174,8 @@ static int64
pg_file_write_internal(text *file, text *data, bool replace)
{
FILE *f;
char *filename;
int64 count = 0;

filename = convert_and_check_filename(file);
char *filename = convert_and_check_filename(file);

if (!replace)
{
Expand All @@ -201,7 +197,8 @@ pg_file_write_internal(text *file, text *data, bool replace)
errmsg("could not open file \"%s\" for writing: %m",
filename)));

count = fwrite(VARDATA_ANY(data), 1, VARSIZE_ANY_EXHDR(data), f);
int64 count = fwrite(VARDATA_ANY(data), 1, VARSIZE_ANY_EXHDR(data), f);

if (count != VARSIZE_ANY_EXHDR(data) || FreeFile(f))
ereport(ERROR,
(errcode_for_file_access(),
Expand All @@ -219,10 +216,9 @@ pg_file_write_internal(text *file, text *data, bool replace)
Datum
pg_file_sync(PG_FUNCTION_ARGS)
{
char *filename;
struct stat fst;

filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
char *filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));

if (stat(filename, &fst) < 0)
ereport(ERROR,
Expand All @@ -244,25 +240,22 @@ pg_file_sync(PG_FUNCTION_ARGS)
Datum
pg_file_rename(PG_FUNCTION_ARGS)
{
text *file1;
text *file2;
text *file3;
bool result;

requireSuperuser();

if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
PG_RETURN_NULL();

file1 = PG_GETARG_TEXT_PP(0);
file2 = PG_GETARG_TEXT_PP(1);
text *file1 = PG_GETARG_TEXT_PP(0);
text *file2 = PG_GETARG_TEXT_PP(1);

if (PG_ARGISNULL(2))
file3 = NULL;
else
file3 = PG_GETARG_TEXT_PP(2);

result = pg_file_rename_internal(file1, file2, file3);
bool result = pg_file_rename_internal(file1, file2, file3);

PG_RETURN_BOOL(result);
}
Expand All @@ -279,23 +272,20 @@ pg_file_rename(PG_FUNCTION_ARGS)
Datum
pg_file_rename_v1_1(PG_FUNCTION_ARGS)
{
text *file1;
text *file2;
text *file3;
bool result;

if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
PG_RETURN_NULL();

file1 = PG_GETARG_TEXT_PP(0);
file2 = PG_GETARG_TEXT_PP(1);
text *file1 = PG_GETARG_TEXT_PP(0);
text *file2 = PG_GETARG_TEXT_PP(1);

if (PG_ARGISNULL(2))
file3 = NULL;
else
file3 = PG_GETARG_TEXT_PP(2);

result = pg_file_rename_internal(file1, file2, file3);
bool result = pg_file_rename_internal(file1, file2, file3);

PG_RETURN_BOOL(result);
}
Expand All @@ -311,7 +301,6 @@ pg_file_rename_internal(text *file1, text *file2, text *file3)
char *fn1,
*fn2,
*fn3;
int rc;

fn1 = convert_and_check_filename(file1);
fn2 = convert_and_check_filename(file2);
Expand Down Expand Up @@ -339,7 +328,8 @@ pg_file_rename_internal(text *file1, text *file2, text *file3)
return false;
}

rc = access(fn3 ? fn3 : fn2, W_OK);
int rc = access(fn3 ? fn3 : fn2, W_OK);

if (rc >= 0 || errno != ENOENT)
{
ereport(ERROR,
Expand Down Expand Up @@ -401,11 +391,10 @@ pg_file_rename_internal(text *file1, text *file2, text *file3)
Datum
pg_file_unlink(PG_FUNCTION_ARGS)
{
char *filename;

requireSuperuser();

filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
char *filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));

if (access(filename, W_OK) < 0)
{
Expand Down Expand Up @@ -441,9 +430,8 @@ pg_file_unlink(PG_FUNCTION_ARGS)
Datum
pg_file_unlink_v1_1(PG_FUNCTION_ARGS)
{
char *filename;

filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
char *filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));

if (access(filename, W_OK) < 0)
{
Expand Down Expand Up @@ -503,13 +491,7 @@ static Datum
pg_logdir_ls_internal(FunctionCallInfo fcinfo)
{
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
bool randomAccess;
TupleDesc tupdesc;
Tuplestorestate *tupstore;
AttInMetadata *attinmeta;
DIR *dirdesc;
struct dirent *de;
MemoryContext oldcontext;

if (strcmp(Log_filename, "postgresql-%Y-%m-%d_%H%M%S.log") != 0)
ereport(ERROR,
Expand All @@ -527,29 +509,31 @@ pg_logdir_ls_internal(FunctionCallInfo fcinfo)
errmsg("materialize mode required, but it is not allowed in this context")));

/* The tupdesc and tuplestore must be created in ecxt_per_query_memory */
oldcontext = MemoryContextSwitchTo(rsinfo->econtext->ecxt_per_query_memory);
MemoryContext oldcontext = MemoryContextSwitchTo(rsinfo->econtext->ecxt_per_query_memory);

TupleDesc tupdesc = CreateTemplateTupleDesc(2);

tupdesc = CreateTemplateTupleDesc(2);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "starttime",
TIMESTAMPOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "filename",
TEXTOID, -1, 0);

randomAccess = (rsinfo->allowedModes & SFRM_Materialize_Random) != 0;
tupstore = tuplestore_begin_heap(randomAccess, false, work_mem);
bool randomAccess = (rsinfo->allowedModes & SFRM_Materialize_Random) != 0;
Tuplestorestate *tupstore = tuplestore_begin_heap(randomAccess, false, work_mem);

rsinfo->returnMode = SFRM_Materialize;
rsinfo->setResult = tupstore;
rsinfo->setDesc = tupdesc;

MemoryContextSwitchTo(oldcontext);

attinmeta = TupleDescGetAttInMetadata(tupdesc);
AttInMetadata *attinmeta = TupleDescGetAttInMetadata(tupdesc);

DIR *dirdesc = AllocateDir(Log_directory);

dirdesc = AllocateDir(Log_directory);
while ((de = ReadDir(dirdesc, Log_directory)) != NULL)
{
char *values[2];
HeapTuple tuple;
char timestampbuf[32];
char *field[MAXDATEFIELDS];
char lowstr[MAXDATELEN + 1];
Expand Down Expand Up @@ -585,7 +569,7 @@ pg_logdir_ls_internal(FunctionCallInfo fcinfo)
values[0] = timestampbuf;
values[1] = psprintf("%s/%s", Log_directory, de->d_name);

tuple = BuildTupleFromCStrings(attinmeta, values);
HeapTuple tuple = BuildTupleFromCStrings(attinmeta, values);

tuplestore_puttuple(tupstore, tuple);
}
Expand Down
Loading