Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
This fixes #13

commit 3603e3e
Author: Jan Wieck <jan@wi3ck.info>
Date:   Mon Nov 21 08:43:02 2022 -0500

    Fix for crash on 32bit systems

    On 32bit platforms a literal number or a 32bit integer
    cannot be casted into type Datum. Using int64 variables
    instead.

    Also correct set-returning functions to end with
    PG_RETURN_VOID() as they should.

commit 7b1341d
Author: Jan Wieck <jan@wi3ck.info>
Date:   Sun Nov 20 15:09:46 2022 -0500

    Small fix for a build problem on 32-bit systems

    The macro Int64GetDatumFast() has a problem on 32-bit
    systems when the argument is 'variable++' instead of
    just 'variable'. Separating the increment into a second
    statement avoids this.
  • Loading branch information
wieck committed Nov 22, 2022
1 parent fbf9244 commit 88f0a24
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions plprofiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ pl_profiler_linestats_local(PG_FUNCTION_ARGS)
hash_seq_init(&hash_seq, functions_hash);
while ((entry = hash_seq_search(&hash_seq)) != NULL)
{
int lno;
int64 lno;

for (lno = 0; lno < entry->line_count; lno++)
{
Expand Down Expand Up @@ -1330,7 +1330,7 @@ pl_profiler_linestats_local(PG_FUNCTION_ARGS)
/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);

return (Datum)0;
PG_RETURN_VOID();
}

/* -------------------------------------------------------------------
Expand Down Expand Up @@ -1388,7 +1388,7 @@ pl_profiler_linestats_shared(PG_FUNCTION_ARGS)
hash_seq_init(&hash_seq, functions_shared);
while ((entry = hash_seq_search(&hash_seq)) != NULL)
{
int lno;
int64 lno;

if (entry->key.db_oid != MyDatabaseId)
continue;
Expand Down Expand Up @@ -1427,7 +1427,7 @@ pl_profiler_linestats_shared(PG_FUNCTION_ARGS)
/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);

return (Datum)0;
PG_RETURN_VOID();
}

/* -------------------------------------------------------------------
Expand Down Expand Up @@ -1509,7 +1509,7 @@ pl_profiler_callgraph_local(PG_FUNCTION_ARGS)
/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);

return (Datum)0;
PG_RETURN_VOID();
}

/* -------------------------------------------------------------------
Expand Down Expand Up @@ -1610,7 +1610,7 @@ pl_profiler_callgraph_shared(PG_FUNCTION_ARGS)
/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);

return (Datum)0;
PG_RETURN_VOID();
}

/* -------------------------------------------------------------------
Expand Down Expand Up @@ -1792,19 +1792,21 @@ pl_profiler_funcs_source(PG_FUNCTION_ARGS)
int i = 0;
char *cp;
char *linestart;
int64 line_number = 1;
int64 line_number = 0;

/* Create the line-0 entry. */
MemSet(values, 0, sizeof(values));
MemSet(nulls, 0, sizeof(nulls));

values[i++] = func_oids[fidx];
values[i++] = (Datum)0;
values[i++] = Int64GetDatumFast(line_number);
values[i++] = PointerGetDatum(cstring_to_text("-- Line 0"));

Assert(i == PL_FUNCS_SRC_COLS);
tuplestore_putvalues(tupstore, tupdesc, values, nulls);

line_number++;

/* Find the source code and split it. */
procSrc = find_source(func_oids[fidx], &procTuple, &funcName);
if (procSrc == NULL)
Expand All @@ -1826,13 +1828,14 @@ pl_profiler_funcs_source(PG_FUNCTION_ARGS)
*cp++ = '\0';
i = 0;
values[i++] = func_oids[fidx];
values[i++] = Int64GetDatumFast(line_number++);
values[i++] = Int64GetDatumFast(line_number);
values[i++] = PointerGetDatum(cstring_to_text(linestart));

Assert(i == PL_FUNCS_SRC_COLS);
tuplestore_putvalues(tupstore, tupdesc, values, nulls);

linestart = cp;
line_number++;
}

ReleaseSysCache(procTuple);
Expand All @@ -1842,7 +1845,7 @@ pl_profiler_funcs_source(PG_FUNCTION_ARGS)
/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);

return (Datum)0;
PG_RETURN_VOID();
}

/* -------------------------------------------------------------------
Expand Down

0 comments on commit 88f0a24

Please sign in to comment.