Skip to content

Commit 8737067

Browse files
author
Commitfest Bot
committed
[CF 5649] v2 - remove open-coded popcount in acl.c
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5649 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/Z9HQHX21PVAK-xea@nathan Author(s): Nathan Bossart
2 parents f4e7756 + e83ee3e commit 8737067

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

src/backend/utils/adt/acl.c

+1-19
Original file line numberDiff line numberDiff line change
@@ -5432,24 +5432,6 @@ select_best_admin(Oid member, Oid role)
54325432
return admin_role;
54335433
}
54345434

5435-
5436-
/* does what it says ... */
5437-
static int
5438-
count_one_bits(AclMode mask)
5439-
{
5440-
int nbits = 0;
5441-
5442-
/* this code relies on AclMode being an unsigned type */
5443-
while (mask)
5444-
{
5445-
if (mask & 1)
5446-
nbits++;
5447-
mask >>= 1;
5448-
}
5449-
return nbits;
5450-
}
5451-
5452-
54535435
/*
54545436
* Select the effective grantor ID for a GRANT or REVOKE operation.
54555437
*
@@ -5532,7 +5514,7 @@ select_best_grantor(Oid roleId, AclMode privileges,
55325514
*/
55335515
if (otherprivs != ACL_NO_RIGHTS)
55345516
{
5535-
int nnewrights = count_one_bits(otherprivs);
5517+
int nnewrights = pg_popcount64(otherprivs);
55365518

55375519
if (nnewrights > nrights)
55385520
{

src/test/regress/expected/privileges.out

+27
Original file line numberDiff line numberDiff line change
@@ -3293,3 +3293,30 @@ DROP SCHEMA reindex_test;
32933293
DROP ROLE regress_no_maintain;
32943294
DROP ROLE regress_maintain;
32953295
DROP ROLE regress_maintain_all;
3296+
-- grantor selection
3297+
CREATE ROLE regress_grantor1;
3298+
CREATE ROLE regress_grantor2 ROLE regress_grantor1;
3299+
CREATE ROLE regress_grantor3;
3300+
CREATE TABLE grantor_test1 ();
3301+
CREATE TABLE grantor_test2 ();
3302+
CREATE TABLE grantor_test3 ();
3303+
GRANT SELECT ON grantor_test2 TO regress_grantor1 WITH GRANT OPTION;
3304+
GRANT SELECT, UPDATE ON grantor_test3 TO regress_grantor2 WITH GRANT OPTION;
3305+
SET ROLE regress_grantor1;
3306+
GRANT SELECT, UPDATE ON grantor_test1 TO regress_grantor3;
3307+
ERROR: permission denied for table grantor_test1
3308+
GRANT SELECT, UPDATE ON grantor_test2 TO regress_grantor3;
3309+
WARNING: not all privileges were granted for "grantor_test2"
3310+
GRANT SELECT, UPDATE ON grantor_test3 TO regress_grantor3;
3311+
RESET ROLE;
3312+
SELECT * FROM information_schema.table_privileges t
3313+
WHERE grantor LIKE 'regress_grantor%' ORDER BY ROW(t.*);
3314+
grantor | grantee | table_catalog | table_schema | table_name | privilege_type | is_grantable | with_hierarchy
3315+
------------------+------------------+---------------+--------------+---------------+----------------+--------------+----------------
3316+
regress_grantor1 | regress_grantor3 | regression | public | grantor_test2 | SELECT | NO | YES
3317+
regress_grantor2 | regress_grantor3 | regression | public | grantor_test3 | SELECT | NO | YES
3318+
regress_grantor2 | regress_grantor3 | regression | public | grantor_test3 | UPDATE | NO | NO
3319+
(3 rows)
3320+
3321+
DROP TABLE grantor_test1, grantor_test2, grantor_test3;
3322+
DROP ROLE regress_grantor1, regress_grantor2, regress_grantor3;

src/test/regress/sql/privileges.sql

+22
Original file line numberDiff line numberDiff line change
@@ -2042,3 +2042,25 @@ DROP SCHEMA reindex_test;
20422042
DROP ROLE regress_no_maintain;
20432043
DROP ROLE regress_maintain;
20442044
DROP ROLE regress_maintain_all;
2045+
2046+
-- grantor selection
2047+
CREATE ROLE regress_grantor1;
2048+
CREATE ROLE regress_grantor2 ROLE regress_grantor1;
2049+
CREATE ROLE regress_grantor3;
2050+
CREATE TABLE grantor_test1 ();
2051+
CREATE TABLE grantor_test2 ();
2052+
CREATE TABLE grantor_test3 ();
2053+
GRANT SELECT ON grantor_test2 TO regress_grantor1 WITH GRANT OPTION;
2054+
GRANT SELECT, UPDATE ON grantor_test3 TO regress_grantor2 WITH GRANT OPTION;
2055+
2056+
SET ROLE regress_grantor1;
2057+
GRANT SELECT, UPDATE ON grantor_test1 TO regress_grantor3;
2058+
GRANT SELECT, UPDATE ON grantor_test2 TO regress_grantor3;
2059+
GRANT SELECT, UPDATE ON grantor_test3 TO regress_grantor3;
2060+
RESET ROLE;
2061+
2062+
SELECT * FROM information_schema.table_privileges t
2063+
WHERE grantor LIKE 'regress_grantor%' ORDER BY ROW(t.*);
2064+
2065+
DROP TABLE grantor_test1, grantor_test2, grantor_test3;
2066+
DROP ROLE regress_grantor1, regress_grantor2, regress_grantor3;

0 commit comments

Comments
 (0)