Skip to content

Commit 4a1d131

Browse files
committed
Use nullptr in extensions
This uses clang-tidy's `modernize-use-nullptr` check.
1 parent 2e9dae2 commit 4a1d131

File tree

9 files changed

+107
-100
lines changed

9 files changed

+107
-100
lines changed

src/_backend_agg.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
1010
height(height),
1111
dpi(dpi),
1212
NUMBYTES((size_t)width * (size_t)height * 4),
13-
pixBuffer(NULL),
13+
pixBuffer(nullptr),
1414
renderingBuffer(),
15-
alphaBuffer(NULL),
15+
alphaBuffer(nullptr),
1616
alphaMaskRenderingBuffer(),
1717
alphaMask(alphaMaskRenderingBuffer),
1818
pixfmtAlphaMask(alphaMaskRenderingBuffer),
@@ -26,7 +26,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
2626
rendererAA(),
2727
rendererBin(),
2828
theRasterizer(32768),
29-
lastclippath(NULL),
29+
lastclippath(nullptr),
3030
_fill_color(agg::rgba(1, 1, 1, 0))
3131
{
3232
if (dpi <= 0.0) {
@@ -75,7 +75,7 @@ BufferRegion *RendererAgg::copy_from_bbox(agg::rect_d in_rect)
7575
agg::rect_i rect(
7676
(int)in_rect.x1, height - (int)in_rect.y2, (int)in_rect.x2, height - (int)in_rect.y1);
7777

78-
BufferRegion *reg = NULL;
78+
BufferRegion *reg = nullptr;
7979
reg = new BufferRegion(rect);
8080

8181
agg::rendering_buffer rbuf;
@@ -90,21 +90,21 @@ BufferRegion *RendererAgg::copy_from_bbox(agg::rect_d in_rect)
9090

9191
void RendererAgg::restore_region(BufferRegion &region)
9292
{
93-
if (region.get_data() == NULL) {
93+
if (region.get_data() == nullptr) {
9494
throw std::runtime_error("Cannot restore_region from NULL data");
9595
}
9696

9797
agg::rendering_buffer rbuf;
9898
rbuf.attach(region.get_data(), region.get_width(), region.get_height(), region.get_stride());
9999

100-
rendererBase.copy_from(rbuf, 0, region.get_rect().x1, region.get_rect().y1);
100+
rendererBase.copy_from(rbuf, nullptr, region.get_rect().x1, region.get_rect().y1);
101101
}
102102

103103
// Restore the part of the saved region with offsets
104104
void
105105
RendererAgg::restore_region(BufferRegion &region, int xx1, int yy1, int xx2, int yy2, int x, int y )
106106
{
107-
if (region.get_data() == NULL) {
107+
if (region.get_data() == nullptr) {
108108
throw std::runtime_error("Cannot restore_region from NULL data");
109109
}
110110

src/_backend_agg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ inline void RendererAgg::draw_image(GCAgg &gc,
890890
} else {
891891
set_clipbox(gc.cliprect, rendererBase);
892892
rendererBase.blend_from(
893-
pixf, 0, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255));
893+
pixf, nullptr, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255));
894894
}
895895

896896
rendererBase.reset_clipping(true);

src/_c_internal_utils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ mpl_xdisplay_is_valid(void)
4343
&& (libX11 = dlopen("libX11.so.6", RTLD_LAZY))) {
4444
typedef struct Display* (*XOpenDisplay_t)(char const*);
4545
typedef int (*XCloseDisplay_t)(struct Display*);
46-
struct Display* display = NULL;
46+
struct Display* display = nullptr;
4747
XOpenDisplay_t XOpenDisplay = (XOpenDisplay_t)dlsym(libX11, "XOpenDisplay");
4848
XCloseDisplay_t XCloseDisplay = (XCloseDisplay_t)dlsym(libX11, "XCloseDisplay");
4949
if (XOpenDisplay && XCloseDisplay
50-
&& (display = XOpenDisplay(NULL))) {
50+
&& (display = XOpenDisplay(nullptr))) {
5151
XCloseDisplay(display);
5252
}
5353
if (dlclose(libX11)) {
@@ -75,13 +75,13 @@ mpl_display_is_valid(void)
7575
&& (libwayland_client = dlopen("libwayland-client.so.0", RTLD_LAZY))) {
7676
typedef struct wl_display* (*wl_display_connect_t)(char const*);
7777
typedef void (*wl_display_disconnect_t)(struct wl_display*);
78-
struct wl_display* display = NULL;
78+
struct wl_display* display = nullptr;
7979
wl_display_connect_t wl_display_connect =
8080
(wl_display_connect_t)dlsym(libwayland_client, "wl_display_connect");
8181
wl_display_disconnect_t wl_display_disconnect =
8282
(wl_display_disconnect_t)dlsym(libwayland_client, "wl_display_disconnect");
8383
if (wl_display_connect && wl_display_disconnect
84-
&& (display = wl_display_connect(NULL))) {
84+
&& (display = wl_display_connect(nullptr))) {
8585
wl_display_disconnect(display);
8686
}
8787
if (dlclose(libwayland_client)) {

src/_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ void __add_number(double val, char format_code, int precision,
10821082
buffer += str;
10831083
} else {
10841084
char *str = PyOS_double_to_string(
1085-
val, format_code, precision, Py_DTSF_ADD_DOT_0, NULL);
1085+
val, format_code, precision, Py_DTSF_ADD_DOT_0, nullptr);
10861086
// Delete trailing zeros and decimal point
10871087
char *c = str + strlen(str) - 1; // Start at last character.
10881088
// Rewind through all the zeros and, if present, the trailing decimal

src/_qhull_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
167167
}
168168

169169
/* qhull expects a FILE* to write errors to. */
170-
FILE* error_file = NULL;
170+
FILE* error_file = nullptr;
171171
if (hide_qhull_errors) {
172172
/* qhull errors are ignored by writing to OS-equivalent of /dev/null.
173173
* Rather than have OS-specific code here, instead it is determined by
174174
* meson.build and passed in via the macro MPL_DEVNULL. */
175175
error_file = fopen(STRINGIFY(MPL_DEVNULL), "w");
176-
if (error_file == NULL) {
176+
if (error_file == nullptr) {
177177
throw std::runtime_error("Could not open devnull");
178178
}
179179
}
@@ -186,7 +186,7 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
186186
QhullInfo info(error_file, qh);
187187
qh_zero(qh, error_file);
188188
exitcode = qh_new_qhull(qh, ndim, (int)npoints, points.data(), False,
189-
(char*)"qhull d Qt Qbb Qc Qz", NULL, error_file);
189+
(char*)"qhull d Qt Qbb Qc Qz", nullptr, error_file);
190190
if (exitcode != qh_ERRnone) {
191191
std::string msg =
192192
py::str("Error in qhull Delaunay triangulation calculation: {} (exitcode={})")

src/_tkagg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ load_tkinter_funcs()
312312
// Load tkinter global funcs from tkinter compiled module.
313313

314314
// Try loading from the main program namespace first.
315-
auto main_program = dlopen(NULL, RTLD_LAZY);
315+
auto main_program = dlopen(nullptr, RTLD_LAZY);
316316
auto success = load_tcl_tk(main_program);
317317
// We don't need to keep a reference open as the main program always exists.
318318
if (dlclose(main_program)) {

src/ft2font.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ void throw_ft_error(std::string message, FT_Error error) {
6363
throw std::runtime_error(os.str());
6464
}
6565

66-
FT2Image::FT2Image() : m_buffer(NULL), m_width(0), m_height(0)
66+
FT2Image::FT2Image() : m_buffer(nullptr), m_width(0), m_height(0)
6767
{
6868
}
6969

7070
FT2Image::FT2Image(unsigned long width, unsigned long height)
71-
: m_buffer(NULL), m_width(0), m_height(0)
71+
: m_buffer(nullptr), m_width(0), m_height(0)
7272
{
7373
resize(width, height);
7474
}
@@ -91,7 +91,7 @@ void FT2Image::resize(long width, long height)
9191
if ((unsigned long)width != m_width || (unsigned long)height != m_height) {
9292
if (numBytes > m_width * m_height) {
9393
delete[] m_buffer;
94-
m_buffer = NULL;
94+
m_buffer = nullptr;
9595
m_buffer = new unsigned char[numBytes];
9696
}
9797

@@ -259,7 +259,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args,
259259
long hinting_factor_,
260260
std::vector<FT2Font *> &fallback_list,
261261
FT2Font::WarnFunc warn)
262-
: ft_glyph_warn(warn), image(), face(NULL)
262+
: ft_glyph_warn(warn), image(), face(nullptr)
263263
{
264264
clear();
265265

@@ -280,12 +280,12 @@ FT2Font::FT2Font(FT_Open_Args &open_args,
280280
throw_ft_error("Could not set the fontsize", error);
281281
}
282282

283-
if (open_args.stream != NULL) {
283+
if (open_args.stream != nullptr) {
284284
face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
285285
}
286286

287287
FT_Matrix transform = { 65536 / hinting_factor, 0, 0, 65536 };
288-
FT_Set_Transform(face, &transform, 0);
288+
FT_Set_Transform(face, &transform, nullptr);
289289

290290
// Set fallbacks
291291
std::copy(fallback_list.begin(), fallback_list.end(), std::back_inserter(fallbacks));
@@ -329,7 +329,7 @@ void FT2Font::set_size(double ptsize, double dpi)
329329
throw_ft_error("Could not set the fontsize", error);
330330
}
331331
FT_Matrix transform = { 65536 / hinting_factor, 0, 0, 65536 };
332-
FT_Set_Transform(face, &transform, 0);
332+
FT_Set_Transform(face, &transform, nullptr);
333333

334334
for (auto & fallback : fallbacks) {
335335
fallback->set_size(ptsize, dpi);
@@ -420,7 +420,7 @@ void FT2Font::set_text(
420420
bbox.xMax = bbox.yMax = -32000;
421421

422422
FT_UInt previous = 0;
423-
FT2Font *previous_ft_object = NULL;
423+
FT2Font *previous_ft_object = nullptr;
424424

425425
for (auto codepoint : text) {
426426
FT_UInt glyph_index = 0;
@@ -456,8 +456,8 @@ void FT2Font::set_text(
456456
FT_Glyph &thisGlyph = glyphs[glyphs.size() - 1];
457457

458458
last_advance = ft_object_with_glyph->get_face()->glyph->advance.x;
459-
FT_Glyph_Transform(thisGlyph, 0, &pen);
460-
FT_Glyph_Transform(thisGlyph, &matrix, 0);
459+
FT_Glyph_Transform(thisGlyph, nullptr, &pen);
460+
FT_Glyph_Transform(thisGlyph, &matrix, nullptr);
461461
xys.push_back(pen.x);
462462
xys.push_back(pen.y);
463463

@@ -492,7 +492,7 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool
492492
if (fallback && char_to_font.find(charcode) != char_to_font.end()) {
493493
ft_object = char_to_font[charcode];
494494
// since it will be assigned to ft_object anyway
495-
FT2Font *throwaway = NULL;
495+
FT2Font *throwaway = nullptr;
496496
ft_object->load_char(charcode, flags, throwaway, false);
497497
} else if (fallback) {
498498
FT_UInt final_glyph_index;
@@ -517,7 +517,7 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool
517517
ft_object = this;
518518
FT_UInt glyph_index = FT_Get_Char_Index(face, (FT_ULong) charcode);
519519
if (!glyph_index){
520-
glyph_seen_fonts.insert((face != NULL)?face->family_name: NULL);
520+
glyph_seen_fonts.insert((face != nullptr)?face->family_name: nullptr);
521521
ft_glyph_warn((FT_ULong)charcode, glyph_seen_fonts);
522522
}
523523
if (FT_Error error = FT_Load_Glyph(face, glyph_index, flags)) {
@@ -636,7 +636,7 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
636636

637637
FT_UInt FT2Font::get_char_index(FT_ULong charcode, bool fallback = false)
638638
{
639-
FT2Font *ft_object = NULL;
639+
FT2Font *ft_object = nullptr;
640640
if (fallback && char_to_font.find(charcode) != char_to_font.end()) {
641641
// fallback denotes whether we want to search fallback list.
642642
// should call set_text/load_char_with_fallback to parent FT2Font before
@@ -676,7 +676,7 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
676676

677677
for (auto & glyph : glyphs) {
678678
FT_Error error = FT_Glyph_To_Bitmap(
679-
&glyph, antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
679+
&glyph, antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, nullptr, 1);
680680
if (error) {
681681
throw_ft_error("Could not convert glyph to bitmap", error);
682682
}

src/ft2font_wrapper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,9 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
447447
}
448448

449449
PyFT2Font *self = new PyFT2Font();
450-
self->x = NULL;
450+
self->x = nullptr;
451451
memset(&self->stream, 0, sizeof(FT_StreamRec));
452-
self->stream.base = NULL;
452+
self->stream.base = nullptr;
453453
self->stream.size = 0x7fffffff; // Unknown size.
454454
self->stream.pos = 0;
455455
self->stream.descriptor.pointer = self;
@@ -486,7 +486,7 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
486486
"First argument must be a path to a font file or a binary-mode file object");
487487
}
488488
self->py_file = filename;
489-
self->stream.close = NULL;
489+
self->stream.close = nullptr;
490490
}
491491

492492
self->x = new FT2Font(open_args, hinting_factor, fallback_fonts, ft_glyph_warn);
@@ -762,7 +762,7 @@ PyFT2Font_load_char(PyFT2Font *self, long charcode,
762762
std::variant<LoadFlags, FT_Int32> flags_or_int = LoadFlags::FORCE_AUTOHINT)
763763
{
764764
bool fallback = true;
765-
FT2Font *ft_object = NULL;
765+
FT2Font *ft_object = nullptr;
766766
LoadFlags flags;
767767

768768
if (auto value = std::get_if<FT_Int32>(&flags_or_int)) {
@@ -816,7 +816,7 @@ PyFT2Font_load_glyph(PyFT2Font *self, FT_UInt glyph_index,
816816
std::variant<LoadFlags, FT_Int32> flags_or_int = LoadFlags::FORCE_AUTOHINT)
817817
{
818818
bool fallback = true;
819-
FT2Font *ft_object = NULL;
819+
FT2Font *ft_object = nullptr;
820820
LoadFlags flags;
821821

822822
if (auto value = std::get_if<FT_Int32>(&flags_or_int)) {
@@ -1433,7 +1433,7 @@ static const char *
14331433
PyFT2Font_postscript_name(PyFT2Font *self)
14341434
{
14351435
const char *ps_name = FT_Get_Postscript_Name(self->x->get_face());
1436-
if (ps_name == NULL) {
1436+
if (ps_name == nullptr) {
14371437
ps_name = "UNAVAILABLE";
14381438
}
14391439

@@ -1450,7 +1450,7 @@ static const char *
14501450
PyFT2Font_family_name(PyFT2Font *self)
14511451
{
14521452
const char *name = self->x->get_face()->family_name;
1453-
if (name == NULL) {
1453+
if (name == nullptr) {
14541454
name = "UNAVAILABLE";
14551455
}
14561456
return name;
@@ -1460,7 +1460,7 @@ static const char *
14601460
PyFT2Font_style_name(PyFT2Font *self)
14611461
{
14621462
const char *name = self->x->get_face()->style_name;
1463-
if (name == NULL) {
1463+
if (name == nullptr) {
14641464
name = "UNAVAILABLE";
14651465
}
14661466
return name;

0 commit comments

Comments
 (0)