Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Apply some modernization to C++ extensions #29280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions 14 src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
height(height),
dpi(dpi),
NUMBYTES((size_t)width * (size_t)height * 4),
pixBuffer(NULL),
pixBuffer(nullptr),
renderingBuffer(),
alphaBuffer(NULL),
alphaBuffer(nullptr),
alphaMaskRenderingBuffer(),
alphaMask(alphaMaskRenderingBuffer),
pixfmtAlphaMask(alphaMaskRenderingBuffer),
Expand All @@ -26,7 +26,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
rendererAA(),
rendererBin(),
theRasterizer(32768),
lastclippath(NULL),
lastclippath(nullptr),
_fill_color(agg::rgba(1, 1, 1, 0))
{
if (dpi <= 0.0) {
Expand Down Expand Up @@ -75,7 +75,7 @@ BufferRegion *RendererAgg::copy_from_bbox(agg::rect_d in_rect)
agg::rect_i rect(
(int)in_rect.x1, height - (int)in_rect.y2, (int)in_rect.x2, height - (int)in_rect.y1);

BufferRegion *reg = NULL;
BufferRegion *reg = nullptr;
reg = new BufferRegion(rect);

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

void RendererAgg::restore_region(BufferRegion &region)
{
if (region.get_data() == NULL) {
if (region.get_data() == nullptr) {
throw std::runtime_error("Cannot restore_region from NULL data");
}

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

rendererBase.copy_from(rbuf, 0, region.get_rect().x1, region.get_rect().y1);
rendererBase.copy_from(rbuf, nullptr, region.get_rect().x1, region.get_rect().y1);
}

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

Expand Down
11 changes: 5 additions & 6 deletions 11 src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class BufferRegion
delete[] data;
};

// prevent copying
BufferRegion(const BufferRegion &) = delete;
BufferRegion &operator=(const BufferRegion &) = delete;

agg::int8u *get_data()
{
return data;
Expand Down Expand Up @@ -96,11 +100,6 @@ class BufferRegion
int width;
int height;
int stride;

private:
// prevent copying
BufferRegion(const BufferRegion &);
BufferRegion &operator=(const BufferRegion &);
};

#define MARKER_CACHE_SIZE 512
Expand Down Expand Up @@ -890,7 +889,7 @@ inline void RendererAgg::draw_image(GCAgg &gc,
} else {
set_clipbox(gc.cliprect, rendererBase);
rendererBase.blend_from(
pixf, 0, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255));
pixf, nullptr, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255));
}

rendererBase.reset_clipping(true);
Expand Down
6 changes: 2 additions & 4 deletions 6 src/_backend_agg_basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Dashes
}
void add_dash_pair(double length, double skip)
{
dashes.push_back(std::make_pair(length, skip));
dashes.emplace_back(length, skip);
}
size_t size() const
{
Expand All @@ -59,9 +59,7 @@ class Dashes
void dash_to_stroke(T &stroke, double dpi, bool isaa)
{
double scaleddpi = dpi / 72.0;
for (dash_t::const_iterator i = dashes.begin(); i != dashes.end(); ++i) {
double val0 = i->first;
double val1 = i->second;
for (auto [val0, val1] : dashes) {
val0 = val0 * scaleddpi;
val1 = val1 * scaleddpi;
if (!isaa) {
Expand Down
8 changes: 4 additions & 4 deletions 8 src/_c_internal_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ mpl_xdisplay_is_valid(void)
&& (libX11 = dlopen("libX11.so.6", RTLD_LAZY))) {
typedef struct Display* (*XOpenDisplay_t)(char const*);
typedef int (*XCloseDisplay_t)(struct Display*);
struct Display* display = NULL;
struct Display* display = nullptr;
XOpenDisplay_t XOpenDisplay = (XOpenDisplay_t)dlsym(libX11, "XOpenDisplay");
XCloseDisplay_t XCloseDisplay = (XCloseDisplay_t)dlsym(libX11, "XCloseDisplay");
if (XOpenDisplay && XCloseDisplay
&& (display = XOpenDisplay(NULL))) {
&& (display = XOpenDisplay(nullptr))) {
XCloseDisplay(display);
}
if (dlclose(libX11)) {
Expand Down Expand Up @@ -75,13 +75,13 @@ mpl_display_is_valid(void)
&& (libwayland_client = dlopen("libwayland-client.so.0", RTLD_LAZY))) {
typedef struct wl_display* (*wl_display_connect_t)(char const*);
typedef void (*wl_display_disconnect_t)(struct wl_display*);
struct wl_display* display = NULL;
struct wl_display* display = nullptr;
wl_display_connect_t wl_display_connect =
(wl_display_connect_t)dlsym(libwayland_client, "wl_display_connect");
wl_display_disconnect_t wl_display_disconnect =
(wl_display_disconnect_t)dlsym(libwayland_client, "wl_display_disconnect");
if (wl_display_connect && wl_display_disconnect
&& (display = wl_display_connect(NULL))) {
&& (display = wl_display_connect(nullptr))) {
wl_display_disconnect(display);
}
if (dlclose(libwayland_client)) {
Expand Down
63 changes: 30 additions & 33 deletions 63 src/_image_resample.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@ namespace agg
value_type a;

//--------------------------------------------------------------------
gray64() {}
gray64() = default;

//--------------------------------------------------------------------
explicit gray64(value_type v_, value_type a_ = 1) :
v(v_), a(a_) {}
explicit gray64(value_type v_, value_type a_ = 1) : v(v_), a(a_) {}

//--------------------------------------------------------------------
gray64(const self_type& c, value_type a_) :
v(c.v), a(a_) {}
gray64(const self_type& c, value_type a_) : v(c.v), a(a_) {}

//--------------------------------------------------------------------
gray64(const gray64& c) :
v(c.v),
a(c.a) {}
gray64(const gray64& c) = default;

//--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a)
Expand Down Expand Up @@ -246,7 +242,7 @@ namespace agg
value_type a;

//--------------------------------------------------------------------
rgba64() {}
rgba64() = default;

//--------------------------------------------------------------------
rgba64(value_type r_, value_type g_, value_type b_, value_type a_= 1) :
Expand Down Expand Up @@ -503,51 +499,52 @@ typedef enum {
// T is rgba if and only if it has an T::r field.
template<typename T, typename = void> struct is_grayscale : std::true_type {};
template<typename T> struct is_grayscale<T, std::void_t<decltype(T::r)>> : std::false_type {};
template<typename T> constexpr bool is_grayscale_v = is_grayscale<T>::value;


template<typename color_type>
struct type_mapping
{
using blender_type = typename std::conditional<
is_grayscale<color_type>::value,
using blender_type = std::conditional_t<
is_grayscale_v<color_type>,
agg::blender_gray<color_type>,
typename std::conditional<
std::is_same<color_type, agg::rgba8>::value,
std::conditional_t<
std::is_same_v<color_type, agg::rgba8>,
fixed_blender_rgba_plain<color_type, agg::order_rgba>,
agg::blender_rgba_plain<color_type, agg::order_rgba>
>::type
>::type;
using pixfmt_type = typename std::conditional<
is_grayscale<color_type>::value,
>
>;
using pixfmt_type = std::conditional_t<
is_grayscale_v<color_type>,
agg::pixfmt_alpha_blend_gray<blender_type, agg::rendering_buffer>,
agg::pixfmt_alpha_blend_rgba<blender_type, agg::rendering_buffer>
>::type;
using pixfmt_pre_type = typename std::conditional<
is_grayscale<color_type>::value,
>;
using pixfmt_pre_type = std::conditional_t<
is_grayscale_v<color_type>,
pixfmt_type,
agg::pixfmt_alpha_blend_rgba<
typename std::conditional<
std::is_same<color_type, agg::rgba8>::value,
std::conditional_t<
std::is_same_v<color_type, agg::rgba8>,
fixed_blender_rgba_pre<color_type, agg::order_rgba>,
agg::blender_rgba_pre<color_type, agg::order_rgba>
>::type,
>,
agg::rendering_buffer>
>::type;
template<typename A> using span_gen_affine_type = typename std::conditional<
is_grayscale<color_type>::value,
>;
template<typename A> using span_gen_affine_type = std::conditional_t<
is_grayscale_v<color_type>,
agg::span_image_resample_gray_affine<A>,
agg::span_image_resample_rgba_affine<A>
>::type;
template<typename A, typename B> using span_gen_filter_type = typename std::conditional<
is_grayscale<color_type>::value,
>;
template<typename A, typename B> using span_gen_filter_type = std::conditional_t<
is_grayscale_v<color_type>,
agg::span_image_filter_gray<A, B>,
agg::span_image_filter_rgba<A, B>
>::type;
template<typename A, typename B> using span_gen_nn_type = typename std::conditional<
is_grayscale<color_type>::value,
>;
template<typename A, typename B> using span_gen_nn_type = std::conditional_t<
is_grayscale_v<color_type>,
agg::span_image_filter_gray_nn<A, B>,
agg::span_image_filter_rgba_nn<A, B>
>::type;
>;
};


Expand Down
31 changes: 12 additions & 19 deletions 31 src/_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,30 +602,26 @@ struct ygt : public bisecty
template <class Filter>
inline void clip_to_rect_one_step(const Polygon &polygon, Polygon &result, const Filter &filter)
{
double sx, sy, px, py, bx, by;
bool sinside, pinside;
result.clear();

if (polygon.size() == 0) {
return;
}

sx = polygon.back().x;
sy = polygon.back().y;
for (Polygon::const_iterator i = polygon.begin(); i != polygon.end(); ++i) {
px = i->x;
py = i->y;

auto [sx, sy] = polygon.back();
for (auto [px, py] : polygon) {
sinside = filter.is_inside(sx, sy);
pinside = filter.is_inside(px, py);

if (sinside ^ pinside) {
double bx, by;
filter.bisect(sx, sy, px, py, &bx, &by);
result.push_back(XY(bx, by));
result.emplace_back(bx, by);
}

if (pinside) {
result.push_back(XY(px, py));
result.emplace_back(px, py);
}

sx = px;
Expand Down Expand Up @@ -672,7 +668,7 @@ clip_path_to_rect(PathIterator &path, agg::rect_d &rect, bool inside, std::vecto
polygon1.clear();
do {
if (code == agg::path_cmd_move_to) {
polygon1.push_back(XY(x, y));
polygon1.emplace_back(x, y);
}

code = curve.vertex(&x, &y);
Expand All @@ -682,7 +678,7 @@ clip_path_to_rect(PathIterator &path, agg::rect_d &rect, bool inside, std::vecto
}

if (code != agg::path_cmd_move_to) {
polygon1.push_back(XY(x, y));
polygon1.emplace_back(x, y);
}
} while ((code & agg::path_cmd_end_poly) != agg::path_cmd_end_poly);

Expand Down Expand Up @@ -978,23 +974,20 @@ void convert_path_to_polygons(PathIterator &path,
simplify_t simplified(clipped, simplify, path.simplify_threshold());
curve_t curve(simplified);

result.push_back(Polygon());
Polygon *polygon = &result.back();
Polygon *polygon = &result.emplace_back();
double x, y;
unsigned code;

while ((code = curve.vertex(&x, &y)) != agg::path_cmd_stop) {
if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) {
_finalize_polygon(result, 1);
result.push_back(Polygon());
polygon = &result.back();
polygon = &result.emplace_back();
} else {
if (code == agg::path_cmd_move_to) {
_finalize_polygon(result, closed_only);
result.push_back(Polygon());
polygon = &result.back();
polygon = &result.emplace_back();
}
polygon->push_back(XY(x, y));
polygon->emplace_back(x, y);
}
}

Expand Down Expand Up @@ -1086,7 +1079,7 @@ void __add_number(double val, char format_code, int precision,
buffer += str;
} else {
char *str = PyOS_double_to_string(
val, format_code, precision, Py_DTSF_ADD_DOT_0, NULL);
val, format_code, precision, Py_DTSF_ADD_DOT_0, nullptr);
// Delete trailing zeros and decimal point
char *c = str + strlen(str) - 1; // Start at last character.
// Rewind through all the zeros and, if present, the trailing decimal
Expand Down
6 changes: 3 additions & 3 deletions 6 src/_qhull_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
}

/* qhull expects a FILE* to write errors to. */
FILE* error_file = NULL;
FILE* error_file = nullptr;
if (hide_qhull_errors) {
/* qhull errors are ignored by writing to OS-equivalent of /dev/null.
* Rather than have OS-specific code here, instead it is determined by
* meson.build and passed in via the macro MPL_DEVNULL. */
error_file = fopen(STRINGIFY(MPL_DEVNULL), "w");
if (error_file == NULL) {
if (error_file == nullptr) {
throw std::runtime_error("Could not open devnull");
}
}
Expand All @@ -186,7 +186,7 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
QhullInfo info(error_file, qh);
qh_zero(qh, error_file);
exitcode = qh_new_qhull(qh, ndim, (int)npoints, points.data(), False,
(char*)"qhull d Qt Qbb Qc Qz", NULL, error_file);
(char*)"qhull d Qt Qbb Qc Qz", nullptr, error_file);
if (exitcode != qh_ERRnone) {
std::string msg =
py::str("Error in qhull Delaunay triangulation calculation: {} (exitcode={})")
Expand Down
2 changes: 1 addition & 1 deletion 2 src/_tkagg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ load_tkinter_funcs()
// Load tkinter global funcs from tkinter compiled module.

// Try loading from the main program namespace first.
auto main_program = dlopen(NULL, RTLD_LAZY);
auto main_program = dlopen(nullptr, RTLD_LAZY);
auto success = load_tcl_tk(main_program);
// We don't need to keep a reference open as the main program always exists.
if (dlclose(main_program)) {
Expand Down
4 changes: 1 addition & 3 deletions 4 src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ class empty
public:
typedef empty<T> sub_t;

empty()
{
}
empty() = default;

T &operator()(int i, int j = 0, int k = 0)
{
Expand Down
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.