Skip to content

Commit 9e57c2d

Browse files
committed
Merge pull request osm2pgsql-dev#399 from pnorman/nullptr
Move from NULL to nullptr
2 parents 778d47d + 6b5a0ff commit 9e57c2d

29 files changed

+152
-149
lines changed

expire-tiles.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int _mark_tile(struct expire_tiles::tile ** tree, int x, int y, int zoom, int th
8383
(*tree)->complete[rel_x][rel_y] = 1;
8484
/* We can destroy the subtree to save memory now all the children are dirty */
8585
destroy_tree((*tree)->subtiles[rel_x][rel_y]);
86-
(*tree)->subtiles[rel_x][rel_y] = NULL;
86+
(*tree)->subtiles[rel_x][rel_y] = nullptr;
8787
}
8888
}
8989
}
@@ -129,7 +129,7 @@ struct tile_output_file : public expire_tiles::tile_output {
129129
tile_output_file(const std::string &expire_tiles_filename)
130130
: outcount(0)
131131
, outfile(fopen(expire_tiles_filename.c_str(), "a")) {
132-
if (outfile == NULL) {
132+
if (outfile == nullptr) {
133133
fprintf(stderr, "Failed to open expired tiles file (%s). Tile expiry list will not be written!\n", strerror(errno));
134134
}
135135
}
@@ -159,28 +159,28 @@ void _output_and_destroy_tree(expire_tiles::tile_output *output, struct expire_t
159159
out = output;
160160
if ((tree->complete[0][0]) && output) {
161161
output->output_dirty_tile(sub_x + 0, sub_y + 0, this_zoom + 1, min_zoom);
162-
out = NULL;
162+
out = nullptr;
163163
}
164164
if (tree->subtiles[0][0]) _output_and_destroy_tree(out, tree->subtiles[0][0], sub_x + 0, sub_y + 0, this_zoom + 1, min_zoom);
165165

166166
out = output;
167167
if ((tree->complete[0][1]) && output) {
168168
output->output_dirty_tile(sub_x + 0, sub_y + 1, this_zoom + 1, min_zoom);
169-
out = NULL;
169+
out = nullptr;
170170
}
171171
if (tree->subtiles[0][1]) _output_and_destroy_tree(out, tree->subtiles[0][1], sub_x + 0, sub_y + 1, this_zoom + 1, min_zoom);
172172

173173
out = output;
174174
if ((tree->complete[1][0]) && output) {
175175
output->output_dirty_tile(sub_x + 1, sub_y + 0, this_zoom + 1, min_zoom);
176-
out = NULL;
176+
out = nullptr;
177177
}
178178
if (tree->subtiles[1][0]) _output_and_destroy_tree(out, tree->subtiles[1][0], sub_x + 1, sub_y + 0, this_zoom + 1, min_zoom);
179179

180180
out = output;
181181
if ((tree->complete[1][1]) && output) {
182182
output->output_dirty_tile(sub_x + 1, sub_y + 1, this_zoom + 1, min_zoom);
183-
out = NULL;
183+
out = nullptr;
184184
}
185185
if (tree->subtiles[1][1]) _output_and_destroy_tree(out, tree->subtiles[1][1], sub_x + 1, sub_y + 1, this_zoom + 1, min_zoom);
186186

@@ -191,19 +191,19 @@ void _output_and_destroy_tree(expire_tiles::tile_output *output, struct expire_t
191191
// number of completed subtrees.
192192
int _tree_merge(struct expire_tiles::tile **a,
193193
struct expire_tiles::tile **b) {
194-
if (*a == NULL) {
194+
if (*a == nullptr) {
195195
*a = *b;
196-
*b = NULL;
196+
*b = nullptr;
197197

198-
} else if (*b != NULL) {
198+
} else if (*b != nullptr) {
199199
for (int x = 0; x < 2; ++x) {
200200
for (int y = 0; y < 2; ++y) {
201201
// if b is complete on a subtree, then the merged tree must
202202
// be complete too.
203203
if ((*b)->complete[x][y]) {
204204
(*a)->complete[x][y] = (*b)->complete[x][y];
205205
destroy_tree((*a)->subtiles[x][y]);
206-
(*a)->subtiles[x][y] = NULL;
206+
(*a)->subtiles[x][y] = nullptr;
207207

208208
// but if a is already complete, don't bother moving across
209209
// anything
@@ -213,12 +213,12 @@ int _tree_merge(struct expire_tiles::tile **a,
213213
if (complete >= 4) {
214214
(*a)->complete[x][y] = 1;
215215
destroy_tree((*a)->subtiles[x][y]);
216-
(*a)->subtiles[x][y] = NULL;
216+
(*a)->subtiles[x][y] = nullptr;
217217
}
218218
}
219219

220220
destroy_tree((*b)->subtiles[x][y]);
221-
(*b)->subtiles[x][y] = NULL;
221+
(*b)->subtiles[x][y] = nullptr;
222222
}
223223
}
224224
}
@@ -227,7 +227,7 @@ int _tree_merge(struct expire_tiles::tile **a,
227227
int a_complete = 0;
228228
for (int x = 0; x < 2; ++x) {
229229
for (int y = 0; y < 2; ++y) {
230-
if ((*a != NULL) && ((*a)->complete[x][y])) {
230+
if ((*a != nullptr) && ((*a)->complete[x][y])) {
231231
++a_complete;
232232
}
233233
}
@@ -240,7 +240,7 @@ int _tree_merge(struct expire_tiles::tile **a,
240240

241241
void expire_tiles::output_and_destroy(tile_output *output) {
242242
_output_and_destroy_tree(output, dirty, 0, 0, 0, Options->expire_tiles_zoom_min);
243-
dirty = NULL;
243+
dirty = nullptr;
244244
}
245245

246246
void expire_tiles::output_and_destroy() {
@@ -252,15 +252,15 @@ void expire_tiles::output_and_destroy() {
252252
}
253253

254254
expire_tiles::~expire_tiles() {
255-
if (dirty != NULL) {
255+
if (dirty != nullptr) {
256256
destroy_tree(dirty);
257-
dirty = NULL;
257+
dirty = nullptr;
258258
}
259259
}
260260

261261
expire_tiles::expire_tiles(const struct options_t *options)
262262
: map_width(0), tile_width(0), Options(options),
263-
dirty(NULL)
263+
dirty(nullptr)
264264
{
265265
if (Options->expire_tiles_zoom < 0) return;
266266
map_width = 1 << Options->expire_tiles_zoom;
@@ -499,7 +499,7 @@ int expire_tiles::from_db(table_t* table, osmid_t osm_id) {
499499
boost::shared_ptr<table_t::wkt_reader> wkts = table->get_wkt_reader(osm_id);
500500

501501
//dirty the stuff
502-
const char* wkt = NULL;
502+
const char* wkt = nullptr;
503503
while((wkt = wkts->get_next()))
504504
from_wkt(wkt, osm_id);
505505

@@ -523,5 +523,5 @@ void expire_tiles::merge_and_destroy(expire_tiles &other) {
523523
_tree_merge(&dirty, &other.dirty);
524524

525525
destroy_tree(other.dirty);
526-
other.dirty = NULL;
526+
other.dirty = nullptr;
527527
}

middle-pgsql.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ middle_pgsql_t::table_desc::table_desc(const char *name_,
8181
array_indexes(array_indexes_),
8282
copyMode(0),
8383
transactionMode(0),
84-
sql_conn(NULL)
84+
sql_conn(nullptr)
8585
{}
8686

8787
#define HELPER_STATE_UNINITIALIZED -1
@@ -169,7 +169,7 @@ inline char *escape_tag( char *ptr, const std::string &in, bool escape )
169169
return ptr;
170170
}
171171

172-
// escape means we return '\N' for copy mode, otherwise we return just NULL */
172+
// escape means we return '\N' for copy mode, otherwise we return just nullptr */
173173
const char *pgsql_store_tags(const taglist_t &tags, bool escape)
174174
{
175175
static char *buffer;
@@ -181,7 +181,7 @@ const char *pgsql_store_tags(const taglist_t &tags, bool escape)
181181
if( escape )
182182
return "\\N";
183183
else
184-
return NULL;
184+
return nullptr;
185185
}
186186

187187
if( buflen <= countlist * 24 ) // LE so 0 always matches */
@@ -294,7 +294,7 @@ int pgsql_endCopy(middle_pgsql_t::table_desc *table)
294294
// Terminate any pending COPY */
295295
if (table->copyMode) {
296296
PGconn *sql_conn = table->sql_conn;
297-
int stop = PQputCopyEnd(sql_conn, NULL);
297+
int stop = PQputCopyEnd(sql_conn, nullptr);
298298
if (stop != 1) {
299299
fprintf(stderr, "COPY_END for %s failed: %s\n", table->copy, PQerrorMessage(sql_conn));
300300
util::exit_nicely();
@@ -364,7 +364,7 @@ size_t middle_pgsql_t::local_nodes_get_list(nodelist_t &out, const idlist_t nds)
364364
char tmp[16];
365365

366366
char *tmp2 = (char *)malloc(sizeof(char) * nds.size() * 16);
367-
if (tmp2 == NULL) return 0; //failed to allocate memory, return */
367+
if (tmp2 == nullptr) return 0; //failed to allocate memory, return */
368368

369369

370370
// create a list of ids in tmp2 to query the database */
@@ -405,17 +405,17 @@ size_t middle_pgsql_t::local_nodes_get_list(nodelist_t &out, const idlist_t nds)
405405
boost::unordered_map<osmid_t, osmNode> pg_nodes(countPG);
406406

407407
for (int i = 0; i < countPG; i++) {
408-
osmid_t id = strtoosmid(PQgetvalue(res, i, 0), NULL, 10);
408+
osmid_t id = strtoosmid(PQgetvalue(res, i, 0), nullptr, 10);
409409
osmNode node;
410410
#ifdef FIXED_POINT
411-
ramNode n((int) strtol(PQgetvalue(res, i, 2), NULL, 10),
412-
(int) strtol(PQgetvalue(res, i, 1), NULL, 10));
411+
ramNode n((int) strtol(PQgetvalue(res, i, 2), nullptr, 10),
412+
(int) strtol(PQgetvalue(res, i, 1), nullptr, 10));
413413

414414
node.lat = n.lat();
415415
node.lon = n.lon();
416416
#else
417-
node.lat = strtod(PQgetvalue(res, i, 1), NULL);
418-
node.lon = strtod(PQgetvalue(res, i, 2), NULL);
417+
node.lat = strtod(PQgetvalue(res, i, 1), nullptr);
418+
node.lon = strtod(PQgetvalue(res, i, 2), nullptr);
419419
#endif
420420
pg_nodes.emplace(id, node);
421421
}
@@ -568,7 +568,7 @@ bool middle_pgsql_t::ways_get(osmid_t id, taglist_t &tags, nodelist_t &nodes) co
568568

569569
pgsql_parse_tags( PQgetvalue(res, 0, 1), tags );
570570

571-
size_t num_nodes = strtoul(PQgetvalue(res, 0, 2), NULL, 10);
571+
size_t num_nodes = strtoul(PQgetvalue(res, 0, 2), nullptr, 10);
572572
idlist_t list;
573573
pgsql_parse_nodes( PQgetvalue(res, 0, 0), list);
574574
if (num_nodes != list.size()) {
@@ -592,7 +592,7 @@ size_t middle_pgsql_t::ways_get_list(const idlist_t &ids, idlist_t &way_ids,
592592
char const *paramValues[1];
593593

594594
tmp2 = (char *)malloc(sizeof(char)*ids.size()*16);
595-
if (tmp2 == NULL) return 0; //failed to allocate memory, return */
595+
if (tmp2 == nullptr) return 0; //failed to allocate memory, return */
596596

597597
// create a list of ids in tmp2 to query the database */
598598
sprintf(tmp2, "{");
@@ -613,7 +613,7 @@ size_t middle_pgsql_t::ways_get_list(const idlist_t &ids, idlist_t &way_ids,
613613
idlist_t wayidspg;
614614

615615
for (int i = 0; i < countPG; i++) {
616-
wayidspg.push_back(strtoosmid(PQgetvalue(res, i, 0), NULL, 10));
616+
wayidspg.push_back(strtoosmid(PQgetvalue(res, i, 0), nullptr, 10));
617617
}
618618

619619

@@ -626,7 +626,7 @@ size_t middle_pgsql_t::ways_get_list(const idlist_t &ids, idlist_t &way_ids,
626626
tags.push_back(taglist_t());
627627
pgsql_parse_tags(PQgetvalue(res, j, 2), tags.back());
628628

629-
size_t num_nodes = strtoul(PQgetvalue(res, j, 3), NULL, 10);
629+
size_t num_nodes = strtoul(PQgetvalue(res, j, 3), nullptr, 10);
630630
idlist_t list;
631631
pgsql_parse_nodes( PQgetvalue(res, j, 1), list);
632632
if (num_nodes != list.size()) {
@@ -798,7 +798,7 @@ bool middle_pgsql_t::relations_get(osmid_t id, memberlist_t &members, taglist_t
798798
pgsql_parse_tags(PQgetvalue(res, 0, 1), tags);
799799
pgsql_parse_tags(PQgetvalue(res, 0, 0), member_temp);
800800

801-
if (member_temp.size() != strtoul(PQgetvalue(res, 0, 2), NULL, 10)) {
801+
if (member_temp.size() != strtoul(PQgetvalue(res, 0, 2), nullptr, 10)) {
802802
fprintf(stderr, "Unexpected member_count reading relation %" PRIdOSMID "\n", id);
803803
util::exit_nicely();
804804
}
@@ -809,7 +809,7 @@ bool middle_pgsql_t::relations_get(osmid_t id, memberlist_t &members, taglist_t
809809
char tag = it->key[0];
810810
OsmType type = (tag == 'n')?OSMTYPE_NODE:(tag == 'w')?OSMTYPE_WAY:(tag == 'r')?OSMTYPE_RELATION:((OsmType)-1);
811811
members.push_back(member(type,
812-
strtoosmid(it->key.c_str()+1, NULL, 10 ),
812+
strtoosmid(it->key.c_str()+1, nullptr, 10 ),
813813
it->value));
814814
}
815815
return true;
@@ -895,7 +895,7 @@ idlist_t middle_pgsql_t::relations_using_way(osmid_t way_id) const
895895
const int ntuples = PQntuples(result);
896896
idlist_t rel_ids(ntuples);
897897
for (int i = 0; i < ntuples; ++i) {
898-
rel_ids[i] = strtoosmid(PQgetvalue(result, i, 0), NULL, 10);
898+
rel_ids[i] = strtoosmid(PQgetvalue(result, i, 0), nullptr, 10);
899899
}
900900
PQclear(result);
901901

@@ -954,10 +954,12 @@ static void set_prefix_and_tbls(const struct options_t *options, const char **st
954954
char buffer[1024];
955955
const char *source;
956956
char *dest;
957-
char *openbrace = NULL;
957+
char *openbrace = nullptr;
958958
int copied = 0;
959959

960-
if (*string == NULL) return;
960+
if (*string == nullptr) {
961+
return;
962+
}
961963
source = *string;
962964
dest = buffer;
963965

@@ -1056,7 +1058,7 @@ void middle_pgsql_t::start(const options_t *out_options_)
10561058
// and pass that via the constructor to middle_t, so that middle_t
10571059
// itself doesn't need to know about details of the output.
10581060
if (out_options->output_backend == "gazetteer") {
1059-
way_table->array_indexes = NULL;
1061+
way_table->array_indexes = nullptr;
10601062
mark_pending = false;
10611063
}
10621064

@@ -1123,7 +1125,7 @@ void middle_pgsql_t::start(const options_t *out_options_)
11231125
snprintf(sql, 2047, "SELECT id FROM %s LIMIT 1", tables[t_node].name);
11241126
res = PQexec(sql_conn, sql );
11251127
free(sql);
1126-
sql = NULL;
1128+
sql = nullptr;
11271129
if(PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
11281130
{
11291131
int size = PQfsize(res, 0);
@@ -1215,10 +1217,10 @@ void *middle_pgsql_t::pgsql_stop_one(void *arg)
12151217
}
12161218

12171219
PQfinish(sql_conn);
1218-
table->sql_conn = NULL;
1220+
table->sql_conn = nullptr;
12191221
time(&end);
12201222
fprintf(stderr, "Stopped table: %s in %is\n", table->name, (int)(end - start));
1221-
return NULL;
1223+
return nullptr;
12221224
}
12231225

12241226
namespace {
@@ -1253,15 +1255,15 @@ void middle_pgsql_t::stop(void)
12531255
}
12541256

12551257
for (i=0; i<num_tables; i++) {
1256-
int ret = pthread_create(&threads[i], NULL, pthread_middle_pgsql_stop_one, &thunks[i]);
1258+
int ret = pthread_create(&threads[i], nullptr, pthread_middle_pgsql_stop_one, &thunks[i]);
12571259
if (ret) {
12581260
fprintf(stderr, "pthread_create() returned an error (%d)", ret);
12591261
util::exit_nicely();
12601262
}
12611263
}
12621264

12631265
for (i=0; i<num_tables; i++) {
1264-
int ret = pthread_join(threads[i], NULL);
1266+
int ret = pthread_join(threads[i], nullptr);
12651267
if (ret) {
12661268
fprintf(stderr, "pthread_join() returned an error (%d)", ret);
12671269
util::exit_nicely();
@@ -1274,7 +1276,7 @@ void middle_pgsql_t::stop(void)
12741276
}
12751277

12761278
middle_pgsql_t::middle_pgsql_t()
1277-
: tables(), num_tables(0), node_table(NULL), way_table(NULL), rel_table(NULL),
1279+
: tables(), num_tables(0), node_table(nullptr), way_table(nullptr), rel_table(nullptr),
12781280
append(false), mark_pending(true), cache(), persistent_cache(), build_indexes(0)
12791281
{
12801282
/*table = t_node,*/
@@ -1283,17 +1285,17 @@ middle_pgsql_t::middle_pgsql_t()
12831285
/*start*/ "BEGIN;\n",
12841286
#ifdef FIXED_POINT
12851287
/*create*/ "CREATE %m TABLE %p_nodes (id " POSTGRES_OSMID_TYPE " PRIMARY KEY {USING INDEX TABLESPACE %i}, lat int4 not null, lon int4 not null, tags text[]) {TABLESPACE %t};\n",
1286-
/*create_index*/ NULL,
1288+
/*create_index*/ nullptr,
12871289
/*prepare*/ "PREPARE insert_node (" POSTGRES_OSMID_TYPE ", int4, int4, text[]) AS INSERT INTO %p_nodes VALUES ($1,$2,$3,$4);\n"
12881290
#else
12891291
/*create*/ "CREATE %m TABLE %p_nodes (id " POSTGRES_OSMID_TYPE " PRIMARY KEY {USING INDEX TABLESPACE %i}, lat double precision not null, lon double precision not null, tags text[]) {TABLESPACE %t};\n",
1290-
/*create_index*/ NULL,
1292+
/*create_index*/ nullptr,
12911293
/*prepare*/ "PREPARE insert_node (" POSTGRES_OSMID_TYPE ", double precision, double precision, text[]) AS INSERT INTO %p_nodes VALUES ($1,$2,$3,$4);\n"
12921294
#endif
12931295
"PREPARE get_node (" POSTGRES_OSMID_TYPE ") AS SELECT lat,lon,tags FROM %p_nodes WHERE id = $1 LIMIT 1;\n"
12941296
"PREPARE get_node_list(" POSTGRES_OSMID_TYPE "[]) AS SELECT id, lat, lon FROM %p_nodes WHERE id = ANY($1::" POSTGRES_OSMID_TYPE "[]);\n"
12951297
"PREPARE delete_node (" POSTGRES_OSMID_TYPE ") AS DELETE FROM %p_nodes WHERE id = $1;\n",
1296-
/*prepare_intarray*/ NULL,
1298+
/*prepare_intarray*/ nullptr,
12971299
/*copy*/ "COPY %p_nodes FROM STDIN;\n",
12981300
/*analyze*/ "ANALYZE %p_nodes;\n",
12991301
/*stop*/ "COMMIT;\n"
@@ -1303,7 +1305,7 @@ middle_pgsql_t::middle_pgsql_t()
13031305
/*name*/ "%p_ways",
13041306
/*start*/ "BEGIN;\n",
13051307
/*create*/ "CREATE %m TABLE %p_ways (id " POSTGRES_OSMID_TYPE " PRIMARY KEY {USING INDEX TABLESPACE %i}, nodes " POSTGRES_OSMID_TYPE "[] not null, tags text[]) {TABLESPACE %t};\n",
1306-
/*create_index*/ NULL,
1308+
/*create_index*/ nullptr,
13071309
/*prepare*/ "PREPARE insert_way (" POSTGRES_OSMID_TYPE ", " POSTGRES_OSMID_TYPE "[], text[]) AS INSERT INTO %p_ways VALUES ($1,$2,$3);\n"
13081310
"PREPARE get_way (" POSTGRES_OSMID_TYPE ") AS SELECT nodes, tags, array_upper(nodes,1) FROM %p_ways WHERE id = $1;\n"
13091311
"PREPARE get_way_list (" POSTGRES_OSMID_TYPE "[]) AS SELECT id, nodes, tags, array_upper(nodes,1) FROM %p_ways WHERE id = ANY($1::" POSTGRES_OSMID_TYPE "[]);\n"
@@ -1322,7 +1324,7 @@ middle_pgsql_t::middle_pgsql_t()
13221324
/*name*/ "%p_rels",
13231325
/*start*/ "BEGIN;\n",
13241326
/*create*/ "CREATE %m TABLE %p_rels(id " POSTGRES_OSMID_TYPE " PRIMARY KEY {USING INDEX TABLESPACE %i}, way_off int2, rel_off int2, parts " POSTGRES_OSMID_TYPE "[], members text[], tags text[]) {TABLESPACE %t};\n",
1325-
/*create_index*/ NULL,
1327+
/*create_index*/ nullptr,
13261328
/*prepare*/ "PREPARE insert_rel (" POSTGRES_OSMID_TYPE ", int2, int2, " POSTGRES_OSMID_TYPE "[], text[], text[]) AS INSERT INTO %p_rels VALUES ($1,$2,$3,$4,$5,$6);\n"
13271329
"PREPARE get_rel (" POSTGRES_OSMID_TYPE ") AS SELECT members, tags, array_upper(members,1)/2 FROM %p_rels WHERE id = $1;\n"
13281330
"PREPARE delete_rel(" POSTGRES_OSMID_TYPE ") AS DELETE FROM %p_rels WHERE id = $1;\n",

middle-ram.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void middle_ram_t::start(const options_t *out_options_)
180180

181181
void middle_ram_t::stop(void)
182182
{
183-
cache.reset(NULL);
183+
cache.reset(nullptr);
184184

185185
release_ways();
186186
release_relations();

0 commit comments

Comments
 (0)