Skip to content

Commit 379d290

Browse files
committed
Use nullptr in extensions
This uses clang-tidy's `modernize-use-nullptr` check.
1 parent d661f01 commit 379d290

File tree

11 files changed

+119
-112
lines changed

11 files changed

+119
-112
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
@@ -883,7 +883,7 @@ inline void RendererAgg::draw_image(GCAgg &gc,
883883
} else {
884884
set_clipbox(gc.cliprect, rendererBase);
885885
rendererBase.blend_from(
886-
pixf, 0, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255));
886+
pixf, nullptr, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255));
887887
}
888888

889889
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_display_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)) {
@@ -62,13 +62,13 @@ mpl_display_is_valid(void)
6262
&& (libwayland_client = dlopen("libwayland-client.so.0", RTLD_LAZY))) {
6363
typedef struct wl_display* (*wl_display_connect_t)(char const*);
6464
typedef void (*wl_display_disconnect_t)(struct wl_display*);
65-
struct wl_display* display = NULL;
65+
struct wl_display* display = nullptr;
6666
wl_display_connect_t wl_display_connect =
6767
(wl_display_connect_t)dlsym(libwayland_client, "wl_display_connect");
6868
wl_display_disconnect_t wl_display_disconnect =
6969
(wl_display_disconnect_t)dlsym(libwayland_client, "wl_display_disconnect");
7070
if (wl_display_connect && wl_display_disconnect
71-
&& (display = wl_display_connect(NULL))) {
71+
&& (display = wl_display_connect(nullptr))) {
7272
wl_display_disconnect(display);
7373
}
7474
if (dlclose(libwayland_client)) {

src/_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ void __add_number(double val, char format_code, int precision,
10841084
buffer += str;
10851085
} else {
10861086
char *str = PyOS_double_to_string(
1087-
val, format_code, precision, Py_DTSF_ADD_DOT_0, NULL);
1087+
val, format_code, precision, Py_DTSF_ADD_DOT_0, nullptr);
10881088
// Delete trailing zeros and decimal point
10891089
char *c = str + strlen(str) - 1; // Start at last character.
10901090
// 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
@@ -300,7 +300,7 @@ load_tkinter_funcs()
300300
// Load tkinter global funcs from tkinter compiled module.
301301

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

src/_ttconv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PythonFileWriter : public TTStreamWriter
2828
virtual void write(const char *a)
2929
{
3030
PyObject* decoded = PyUnicode_DecodeLatin1(a, strlen(a), "");
31-
if (decoded == NULL) {
31+
if (decoded == nullptr) {
3232
throw py::error_already_set();
3333
}
3434
_write_method(py::handle(decoded));

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);
@@ -418,7 +418,7 @@ void FT2Font::set_text(
418418
bbox.xMax = bbox.yMax = -32000;
419419

420420
FT_UInt previous = 0;
421-
FT2Font *previous_ft_object = NULL;
421+
FT2Font *previous_ft_object = nullptr;
422422

423423
for (auto codepoint : text) {
424424
FT_UInt glyph_index = 0;
@@ -454,8 +454,8 @@ void FT2Font::set_text(
454454
FT_Glyph &thisGlyph = glyphs[glyphs.size() - 1];
455455

456456
last_advance = ft_object_with_glyph->get_face()->glyph->advance.x;
457-
FT_Glyph_Transform(thisGlyph, 0, &pen);
458-
FT_Glyph_Transform(thisGlyph, &matrix, 0);
457+
FT_Glyph_Transform(thisGlyph, nullptr, &pen);
458+
FT_Glyph_Transform(thisGlyph, &matrix, nullptr);
459459
xys.push_back(pen.x);
460460
xys.push_back(pen.y);
461461

@@ -490,7 +490,7 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool
490490
if (fallback && char_to_font.find(charcode) != char_to_font.end()) {
491491
ft_object = char_to_font[charcode];
492492
// since it will be assigned to ft_object anyway
493-
FT2Font *throwaway = NULL;
493+
FT2Font *throwaway = nullptr;
494494
ft_object->load_char(charcode, flags, throwaway, false);
495495
} else if (fallback) {
496496
FT_UInt final_glyph_index;
@@ -515,7 +515,7 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool
515515
ft_object = this;
516516
FT_UInt glyph_index = FT_Get_Char_Index(face, (FT_ULong) charcode);
517517
if (!glyph_index){
518-
glyph_seen_fonts.insert((face != NULL)?face->family_name: NULL);
518+
glyph_seen_fonts.insert((face != nullptr)?face->family_name: nullptr);
519519
ft_glyph_warn((FT_ULong)charcode, glyph_seen_fonts);
520520
}
521521
if (FT_Error error = FT_Load_Glyph(face, glyph_index, flags)) {
@@ -634,7 +634,7 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
634634

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

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

src/ft2font_wrapper.cpp

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

182182
PyFT2Font *self = new PyFT2Font();
183-
self->x = NULL;
183+
self->x = nullptr;
184184
memset(&self->stream, 0, sizeof(FT_StreamRec));
185-
self->stream.base = NULL;
185+
self->stream.base = nullptr;
186186
self->stream.size = 0x7fffffff; // Unknown size.
187187
self->stream.pos = 0;
188188
self->stream.descriptor.pointer = self;
@@ -219,7 +219,7 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
219219
"First argument must be a path to a font file or a binary-mode file object");
220220
}
221221
self->py_file = filename;
222-
self->stream.close = NULL;
222+
self->stream.close = nullptr;
223223
}
224224

225225
self->x = new FT2Font(open_args, hinting_factor, fallback_fonts, ft_glyph_warn);
@@ -368,7 +368,7 @@ PyFT2Font_load_char(PyFT2Font *self, long charcode,
368368
FT_Int32 flags = FT_LOAD_FORCE_AUTOHINT)
369369
{
370370
bool fallback = true;
371-
FT2Font *ft_object = NULL;
371+
FT2Font *ft_object = nullptr;
372372

373373
self->x->load_char(charcode, flags, ft_object, fallback);
374374

@@ -395,7 +395,7 @@ PyFT2Font_load_glyph(PyFT2Font *self, FT_UInt glyph_index,
395395
FT_Int32 flags = FT_LOAD_FORCE_AUTOHINT)
396396
{
397397
bool fallback = true;
398-
FT2Font *ft_object = NULL;
398+
FT2Font *ft_object = nullptr;
399399

400400
self->x->load_glyph(glyph_index, flags, ft_object, fallback);
401401

@@ -815,7 +815,7 @@ static const char *
815815
PyFT2Font_postscript_name(PyFT2Font *self)
816816
{
817817
const char *ps_name = FT_Get_Postscript_Name(self->x->get_face());
818-
if (ps_name == NULL) {
818+
if (ps_name == nullptr) {
819819
ps_name = "UNAVAILABLE";
820820
}
821821

@@ -832,7 +832,7 @@ static const char *
832832
PyFT2Font_family_name(PyFT2Font *self)
833833
{
834834
const char *name = self->x->get_face()->family_name;
835-
if (name == NULL) {
835+
if (name == nullptr) {
836836
name = "UNAVAILABLE";
837837
}
838838
return name;
@@ -842,7 +842,7 @@ static const char *
842842
PyFT2Font_style_name(PyFT2Font *self)
843843
{
844844
const char *name = self->x->get_face()->style_name;
845-
if (name == NULL) {
845+
if (name == nullptr) {
846846
name = "UNAVAILABLE";
847847
}
848848
return name;
@@ -959,7 +959,7 @@ PYBIND11_MODULE(ft2font, m)
959959
import_array();
960960
return &m;
961961
};
962-
if (ia() == NULL) {
962+
if (ia() == nullptr) {
963963
throw py::error_already_set();
964964
}
965965

0 commit comments

Comments
 (0)