Re: pgsql: In pg_upgrade, properly handle oids > 2^31 by using strtoul() in - Mailing list pgsql-committers
From | Bruce Momjian |
---|---|
Subject | Re: pgsql: In pg_upgrade, properly handle oids > 2^31 by using strtoul() in |
Date | |
Msg-id | 201009282214.o8SMENO25830@momjian.us Whole thread Raw |
In response to | Re: pgsql: In pg_upgrade, properly handle oids > 2^31 by using strtoul() in (Tom Lane <tgl@sss.pgh.pa.us>) |
Responses |
Re: pgsql: In pg_upgrade, properly handle oids > 2^31 by using strtoul() in
|
List | pgsql-committers |
Tom Lane wrote: > Bruce Momjian <bruce@momjian.us> writes: > > In pg_upgrade, properly handle oids > 2^31 by using strtoul() internally > > rather than atol(). > > It would be a lot better if this code adhered to the project-standard > coding convention of defining and using an atooid() macro for the > purpose of converting text representations of OIDs to bits. OK, I used your idea for conversion directly to oid from the system catalogs, patch attached. All the pg_controldata returned integers are defined as uint32 in pg_upgrade. Should I use atooid() for some of them and define some of them as OID? I thought that might just add more confusion. On a quick look, it seems only chkpnt_nxtoid is an oid, but I am not sure. -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c index 55489ac..3b31622 100644 --- a/contrib/pg_upgrade/info.c +++ b/contrib/pg_upgrade/info.c @@ -242,7 +242,7 @@ get_db_infos(migratorContext *ctx, DbInfoArr *dbinfs_arr, Cluster whichCluster) for (tupnum = 0; tupnum < ntups; tupnum++) { - dbinfos[tupnum].db_oid = str2uint(PQgetvalue(res, tupnum, i_oid)); + dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid)); snprintf(dbinfos[tupnum].db_name, sizeof(dbinfos[tupnum].db_name), "%s", PQgetvalue(res, tupnum, i_datname)); @@ -360,7 +360,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo, RelInfo *curr = &relinfos[num_rels++]; const char *tblspace; - curr->reloid = str2uint(PQgetvalue(res, relnum, i_oid)); + curr->reloid = atooid(PQgetvalue(res, relnum, i_oid)); nspname = PQgetvalue(res, relnum, i_nspname); strlcpy(curr->nspname, nspname, sizeof(curr->nspname)); @@ -368,8 +368,8 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo, relname = PQgetvalue(res, relnum, i_relname); strlcpy(curr->relname, relname, sizeof(curr->relname)); - curr->relfilenode = str2uint(PQgetvalue(res, relnum, i_relfilenode)); - curr->toastrelid = str2uint(PQgetvalue(res, relnum, i_reltoastrelid)); + curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode)); + curr->toastrelid = atooid(PQgetvalue(res, relnum, i_reltoastrelid)); tblspace = PQgetvalue(res, relnum, i_spclocation); /* if no table tablespace, use the database tablespace */ diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h index 296b80f..73070c6 100644 --- a/contrib/pg_upgrade/pg_upgrade.h +++ b/contrib/pg_upgrade/pg_upgrade.h @@ -52,6 +52,8 @@ #define CLUSTERNAME(cluster) ((cluster) == CLUSTER_OLD ? "old" : "new") +#define atooid(x) ((Oid) strtoul((x), NULL, 10)) + /* OID system catalog preservation added during PG 9.0 development */ #define TABLE_SPACE_SUBDIRS 201001111 diff --git a/contrib/pg_upgrade/relfilenode.c b/contrib/pg_upgrade/relfilenode.c index dd605bb..3a11bab 100644 --- a/contrib/pg_upgrade/relfilenode.c +++ b/contrib/pg_upgrade/relfilenode.c @@ -94,9 +94,9 @@ get_pg_database_relfilenode(migratorContext *ctx, Cluster whichCluster) i_relfile = PQfnumber(res, "relfilenode"); if (whichCluster == CLUSTER_OLD) - ctx->old.pg_database_oid = str2uint(PQgetvalue(res, 0, i_relfile)); + ctx->old.pg_database_oid = atooid(PQgetvalue(res, 0, i_relfile)); else - ctx->new.pg_database_oid = str2uint(PQgetvalue(res, 0, i_relfile)); + ctx->new.pg_database_oid = atooid(PQgetvalue(res, 0, i_relfile)); PQclear(res); PQfinish(conn);
pgsql-committers by date: