Skip to content

Commit

Permalink
Pick up SIZEOF_INT via ModelConstants
Browse files Browse the repository at this point in the history
In backporting, sometimes the git history shows that something
has always had the same type, but the type was plain int rather
than an explicit-width type. So, for such things, there is no
need for a plethora of SIZEOF_FOO constants, but SIZEOF_INT may
be generally useful to detect if a platform has a surprising
value for that width.
  • Loading branch information
jcflack committed Sep 8, 2023
1 parent dc62b4e commit d1e1db3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions pljava-so/src/main/c/ModelConstants.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static int32 constants[] = {
CONSTANT(PG_VERSION_NUM),

CONSTANT(SIZEOF_DATUM),
CONSTANTEXPR(SIZEOF_INT, sizeof (int)),
CONSTANTEXPR(SIZEOF_SIZE, sizeof (Size)),

CONSTANT(ALIGNOF_SHORT),
Expand Down
20 changes: 14 additions & 6 deletions pljava/src/main/java/org/postgresql/pljava/pg/ModelConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,15 @@ public void close()
@Native private static final int IDX_PG_VERSION_NUM = 0;

@Native private static final int IDX_SIZEOF_DATUM = 1;
@Native private static final int IDX_SIZEOF_SIZE = 2;
@Native private static final int IDX_SIZEOF_INT = 2;
@Native private static final int IDX_SIZEOF_SIZE = 3;

@Native private static final int IDX_ALIGNOF_SHORT = 3;
@Native private static final int IDX_ALIGNOF_INT = 4;
@Native private static final int IDX_ALIGNOF_DOUBLE = 5;
@Native private static final int IDX_MAXIMUM_ALIGNOF = 6;
@Native private static final int IDX_ALIGNOF_SHORT = 4;
@Native private static final int IDX_ALIGNOF_INT = 5;
@Native private static final int IDX_ALIGNOF_DOUBLE = 6;
@Native private static final int IDX_MAXIMUM_ALIGNOF = 7;

@Native private static final int IDX_NAMEDATALEN = 7;
@Native private static final int IDX_NAMEDATALEN = 8;



Expand Down Expand Up @@ -298,6 +299,12 @@ public void close()
public static final int PG_VERSION_NUM;

public static final int SIZEOF_DATUM;
/*
* In backporting, can be useful when the git history shows something was
* always of 'int' type, so it doesn't need a dedicated SIZEOF_FOO, but does
* need to notice if a platform has an unexpected 'int' width.
*/
public static final int SIZEOF_INT;
public static final int SIZEOF_SIZE;

public static final int ALIGNOF_SHORT;
Expand Down Expand Up @@ -413,6 +420,7 @@ public void close()
PG_VERSION_NUM = n.get(IDX_PG_VERSION_NUM);

SIZEOF_DATUM = n.get(IDX_SIZEOF_DATUM);
SIZEOF_INT = n.get(IDX_SIZEOF_INT);
SIZEOF_SIZE = n.get(IDX_SIZEOF_SIZE);

ALIGNOF_SHORT = n.get(IDX_ALIGNOF_SHORT);
Expand Down

0 comments on commit d1e1db3

Please sign in to comment.