Skip to content

Commit

Permalink
Correctly handle AclMode as an uint64 (not "long")
Browse files Browse the repository at this point in the history
This mainly helps with resolving compiler warnings, and should not have
any effective difference, since the relevant struct (RTEPermissionInfo)
is not actually used in raw parsing.
  • Loading branch information
lfittl committed Dec 29, 2023
1 parent 7262c13 commit e26e74b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion protobuf/pg_query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ message RTEPermissionInfo
{
uint32 relid = 1 [json_name="relid"];
bool inh = 2 [json_name="inh"];
int64 required_perms = 3 [json_name="requiredPerms"];
uint64 required_perms = 3 [json_name="requiredPerms"];
uint32 check_as_user = 4 [json_name="checkAsUser"];
repeated uint64 selected_cols = 5 [json_name="selectedCols"];
repeated uint64 inserted_cols = 6 [json_name="insertedCols"];
Expand Down
15 changes: 14 additions & 1 deletion scripts/generate_fingerprint_outfuncs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ def initialize
EOL

FINGERPRINT_UINT64 = <<-EOL
if (node->%<name>s != 0) {
char buffer[50];
sprintf(buffer, UINT64_FORMAT, node->%<name>s);
_fingerprintString(ctx, "%<name>s");
_fingerprintString(ctx, buffer);
}
EOL

FINGERPRINT_FLOAT = <<-EOL
if (node->%<name>s != 0) {
char buffer[50];
Expand Down Expand Up @@ -258,7 +268,8 @@ def initialize
['RawStmt', 'stmt_location'] => :skip,
}
INT_TYPES = ['bits32', 'uint32', 'int', 'int32', 'uint16', 'int16', 'Oid', 'Index', 'AttrNumber', 'SubTransactionId', 'RelFileNumber']
LONG_INT_TYPES = ['long', 'uint64', 'AclMode']
LONG_INT_TYPES = ['long']
UINT64_TYPES = ['uint64', 'AclMode']
INT_ARRAY_TYPES = ['Bitmapset*', 'Bitmapset', 'Relids']
FLOAT_TYPES = ['Cost', 'double', 'Cardinality']

Expand Down Expand Up @@ -317,6 +328,8 @@ def generate_fingerprint_defs!
fingerprint_def += format(FINGERPRINT_INT, name: name)
when *LONG_INT_TYPES
fingerprint_def += format(FINGERPRINT_LONG_INT, name: name)
when *UINT64_TYPES
fingerprint_def += format(FINGERPRINT_UINT64, name: name)
when *INT_ARRAY_TYPES
fingerprint_def += format(FINGERPRINT_INT_ARRAY, name: name)
when *FLOAT_TYPES
Expand Down
7 changes: 6 additions & 1 deletion scripts/generate_protobuf_and_funcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def generate_outmethods!
@readmethods[node_type] += format(" READ_BOOL_FIELD(%s, %s, %s);\n", outname, outname_json, name)
@protobuf_messages[node_type] += format(" bool %s = %d [json_name=\"%s\"];\n", outname, protobuf_field_count, name)
protobuf_field_count += 1
elsif ['long', 'AclMode'].include?(type)
elsif ['long'].include?(type)
@outmethods[node_type] += format(" WRITE_LONG_FIELD(%s, %s, %s);\n", outname, outname_json, name)
@readmethods[node_type] += format(" READ_LONG_FIELD(%s, %s, %s);\n", outname, outname_json, name)
@protobuf_messages[node_type] += format(" int64 %s = %d [json_name=\"%s\"];\n", outname, protobuf_field_count, name)
Expand All @@ -89,6 +89,11 @@ def generate_outmethods!
@readmethods[node_type] += format(" READ_UINT_FIELD(%s, %s, %s);\n", outname, outname_json, name)
@protobuf_messages[node_type] += format(" uint32 %s = %d [json_name=\"%s\"];\n", outname, protobuf_field_count, name)
protobuf_field_count += 1
elsif ['uint64', 'AclMode'].include?(type)
@outmethods[node_type] += format(" WRITE_UINT64_FIELD(%s, %s, %s);\n", outname, outname_json, name)
@readmethods[node_type] += format(" READ_UINT64_FIELD(%s, %s, %s);\n", outname, outname_json, name)
@protobuf_messages[node_type] += format(" uint64 %s = %d [json_name=\"%s\"];\n", outname, protobuf_field_count, name)
protobuf_field_count += 1
elsif type == 'char*'
@outmethods[node_type] += format(" WRITE_STRING_FIELD(%s, %s, %s);\n", outname, outname_json, name)
@readmethods[node_type] += format(" READ_STRING_FIELD(%s, %s, %s);\n", outname, outname_json, name)
Expand Down
2 changes: 1 addition & 1 deletion src/pg_query_fingerprint_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5894,7 +5894,7 @@ _fingerprintRTEPermissionInfo(FingerprintContext *ctx, const RTEPermissionInfo *

if (node->requiredPerms != 0) {
char buffer[50];
sprintf(buffer, "%ld", node->requiredPerms);
sprintf(buffer, UINT64_FORMAT, node->requiredPerms);
_fingerprintString(ctx, "requiredPerms");
_fingerprintString(ctx, buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pg_query_outfuncs_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ _outRTEPermissionInfo(OUT_TYPE(RTEPermissionInfo, RTEPermissionInfo) out, const
{
WRITE_UINT_FIELD(relid, relid, relid);
WRITE_BOOL_FIELD(inh, inh, inh);
WRITE_LONG_FIELD(required_perms, requiredPerms, requiredPerms);
WRITE_UINT64_FIELD(required_perms, requiredPerms, requiredPerms);
WRITE_UINT_FIELD(check_as_user, checkAsUser, checkAsUser);
WRITE_BITMAPSET_FIELD(selected_cols, selectedCols, selectedCols);
WRITE_BITMAPSET_FIELD(inserted_cols, insertedCols, insertedCols);
Expand Down
6 changes: 6 additions & 0 deletions src/pg_query_outfuncs_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
appendStringInfo(out, "\"" CppAsString(outname_json) "\":%u,", node->fldname); \
}

/* Write an unsigned integer field */
#define WRITE_UINT64_FIELD(outname, outname_json, fldname) \
if (node->fldname != 0) { \
appendStringInfo(out, "\"" CppAsString(outname_json) "\":" UINT64_FORMAT ",", node->fldname); \
}

/* Write a long-integer field */
#define WRITE_LONG_FIELD(outname, outname_json, fldname) \
if (node->fldname != 0) { \
Expand Down
1 change: 1 addition & 0 deletions src/pg_query_outfuncs_protobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#define WRITE_INT_FIELD(outname, outname_json, fldname) out->outname = node->fldname;
#define WRITE_UINT_FIELD(outname, outname_json, fldname) out->outname = node->fldname;
#define WRITE_UINT64_FIELD(outname, outname_json, fldname) out->outname = node->fldname;
#define WRITE_LONG_FIELD(outname, outname_json, fldname) out->outname = node->fldname;
#define WRITE_FLOAT_FIELD(outname, outname_json, fldname) out->outname = node->fldname;
#define WRITE_BOOL_FIELD(outname, outname_json, fldname) out->outname = node->fldname;
Expand Down
1 change: 1 addition & 0 deletions src/pg_query_outfuncs_protobuf_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C"

#define WRITE_INT_FIELD(outname, outname_json, fldname) out->set_##outname(node->fldname);
#define WRITE_UINT_FIELD(outname, outname_json, fldname) out->set_##outname(node->fldname);
#define WRITE_UINT64_FIELD(outname, outname_json, fldname) out->set_##outname(node->fldname);
#define WRITE_LONG_FIELD(outname, outname_json, fldname) out->set_##outname(node->fldname);
#define WRITE_FLOAT_FIELD(outname, outname_json, fldname) out->set_##outname(node->fldname);
#define WRITE_BOOL_FIELD(outname, outname_json, fldname) out->set_##outname(node->fldname);
Expand Down
2 changes: 1 addition & 1 deletion src/pg_query_readfuncs_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ _readRTEPermissionInfo(OUT_TYPE(RTEPermissionInfo, RTEPermissionInfo) msg)
RTEPermissionInfo *node = makeNode(RTEPermissionInfo);
READ_UINT_FIELD(relid, relid, relid);
READ_BOOL_FIELD(inh, inh, inh);
READ_LONG_FIELD(required_perms, requiredPerms, requiredPerms);
READ_UINT64_FIELD(required_perms, requiredPerms, requiredPerms);
READ_UINT_FIELD(check_as_user, checkAsUser, checkAsUser);
READ_BITMAPSET_FIELD(selected_cols, selectedCols, selectedCols);
READ_BITMAPSET_FIELD(inserted_cols, insertedCols, insertedCols);
Expand Down
1 change: 1 addition & 0 deletions src/pg_query_readfuncs_protobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#define READ_INT_FIELD(outname, outname_json, fldname) node->fldname = msg->outname;
#define READ_UINT_FIELD(outname, outname_json, fldname) node->fldname = msg->outname;
#define READ_UINT64_FIELD(outname, outname_json, fldname) node->fldname = msg->outname;
#define READ_LONG_FIELD(outname, outname_json, fldname) node->fldname = msg->outname;
#define READ_FLOAT_FIELD(outname, outname_json, fldname) node->fldname = msg->outname;
#define READ_BOOL_FIELD(outname, outname_json, fldname) node->fldname = msg->outname;
Expand Down

0 comments on commit e26e74b

Please sign in to comment.