Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed95382

Browse files
committed
Merge pull request #3691 from mdboom/more-cpp-cleanup
Minor C++ improvements
2 parents 6091d11 + 001eb3d commit ed95382

12 files changed

+35
-61
lines changed

extern/ttconv/pprdrv_tt.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
#include "pprdrv.h"
3232
#include "truetype.h"
3333
#include <sstream>
34+
#ifdef _POSIX_C_SOURCE
35+
# undef _POSIX_C_SOURCE
36+
#endif
37+
#ifdef _XOPEN_SOURCE
38+
# undef _XOPEN_SOURCE
39+
#endif
3440
#include <Python.h>
3541

3642
/*==========================================================================

src/_backend_agg_wrapper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,7 @@ extern "C" {
670670

671671
struct module_state
672672
{
673-
/* The Sun compiler can't handle empty structs */
674-
#if defined(__SUNPRO_C) || defined(_MSC_VER)
675673
int _dummy;
676-
#endif
677674
};
678675

679676
#if PY3K

src/_gtkagg.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ extern "C" {
110110

111111
struct module_state
112112
{
113-
/* The Sun compiler can't handle empty structs */
114-
#if defined(__SUNPRO_C) || defined(_MSC_VER)
115113
int _dummy;
116-
#endif
117114
};
118115

119116
#if PY3K

src/_image_wrapper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,7 @@ extern "C" {
722722

723723
struct module_state
724724
{
725-
/* The Sun compiler can't handle empty structs */
726-
#if defined(__SUNPRO_C) || defined(_MSC_VER)
727725
int _dummy;
728-
#endif
729726
};
730727

731728
#if PY3K

src/_path_wrapper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,7 @@ extern "C" {
669669

670670
struct module_state
671671
{
672-
/* The Sun compiler can't handle empty structs */
673-
#if defined(__SUNPRO_C) || defined(_MSC_VER)
674672
int _dummy;
675-
#endif
676673
};
677674

678675
#if PY3K

src/_png.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,7 @@ extern "C" {
490490

491491
struct module_state
492492
{
493-
/* The Sun compiler can't handle empty structs */
494-
#if defined(__SUNPRO_C) || defined(_MSC_VER)
495493
int _dummy;
496-
#endif
497494
};
498495

499496
#if PY3K

src/cntr.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ slit_cutter (Csite * site, int up, int pass2)
722722
* -- this never happens on the first pass */
723723
long p1 = site->edge;
724724
int z1;
725+
726+
assert(pass2);
727+
725728
for (;;)
726729
{
727730
z1 = data[p1] & Z_VALUE;
@@ -1406,7 +1409,11 @@ int reorder(double *xpp, double *ypp, short *kpp,
14061409

14071410
/* Find the subpaths as sets of connected segments. */
14081411

1409-
subp = (int *)malloc(nsegs * sizeof(int));
1412+
if (nsegs) {
1413+
subp = (int *)malloc(nsegs * sizeof(int));
1414+
} else {
1415+
subp = NULL;
1416+
}
14101417
for (i=0; i<nsegs; i++) subp[i] = -1;
14111418

14121419
nsp = 0;
@@ -2025,5 +2032,3 @@ init_cntr(void)
20252032
return m;
20262033
#endif
20272034
}
2028-
2029-

src/ft2font.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void FT2Image::resize(long width, long height)
7474
m_height = (unsigned long)height;
7575
}
7676

77-
if (numBytes) {
77+
if (numBytes && m_buffer) {
7878
memset(m_buffer, 0, numBytes);
7979
}
8080

src/ft2font_wrapper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,10 +1618,7 @@ extern "C" {
16181618

16191619
struct module_state
16201620
{
1621-
/* The Sun compiler can't handle empty structs */
1622-
#if defined(__SUNPRO_C) || defined(_MSC_VER)
16231621
int _dummy;
1624-
#endif
16251622
};
16261623

16271624
#if PY3K

src/mplutils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ typedef unsigned __int8 uint8_t;
1111
#include <stdint.h>
1212
#endif
1313

14+
#ifdef _POSIX_C_SOURCE
15+
# undef _POSIX_C_SOURCE
16+
#endif
17+
#ifdef _XOPEN_SOURCE
18+
# undef _XOPEN_SOURCE
19+
#endif
20+
1421
#include <Python.h>
1522

1623
#if PY_MAJOR_VERSION >= 3

src/numpy_cpp.h

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818

1919
#include <complex>
2020

21+
#ifdef _POSIX_C_SOURCE
22+
# undef _POSIX_C_SOURCE
23+
#endif
24+
#ifdef _XOPEN_SOURCE
25+
# undef _XOPEN_SOURCE
26+
#endif
27+
2128
#include <Python.h>
2229
#include <numpy/ndarrayobject.h>
2330

@@ -317,39 +324,6 @@ class array_view_accessors<AV, T, 3>
317324

318325
};
319326

320-
// /* These are converter functions designed for use with the "O&"
321-
// functionality of PyArg_ParseTuple and friends. */
322-
323-
// template<class T>
324-
// class array_converter {
325-
// public:
326-
// int operator()(PyObject *obj, void *arrp)
327-
// {
328-
// T *arr = (T *)arrp;
329-
330-
// if (!arr->set(obj)) {
331-
// return 0;
332-
// }
333-
334-
// return 1;
335-
// }
336-
// };
337-
338-
// template <class T>
339-
// class array_converter_contiguous {
340-
// public:
341-
// int operator()(PyObject *obj, void *arrp)
342-
// {
343-
// T *arr = (T *)arrp;
344-
345-
// if (!arr->set(obj, true)) {
346-
// return 0;
347-
// }
348-
349-
// return 1;
350-
// }
351-
// };
352-
353327
}
354328

355329
static npy_intp zeros[] = { 0, 0, 0 };
@@ -425,6 +399,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
425399
PyArrayObject *tmp;
426400

427401
if (arr == NULL || arr == Py_None) {
402+
Py_XDECREF(m_arr);
428403
m_arr = NULL;
429404
m_data = NULL;
430405
m_shape = zeros;
@@ -440,6 +415,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
440415
}
441416

442417
if (PyArray_NDIM(tmp) == 0 || PyArray_DIM(tmp, 0) == 0) {
418+
Py_XDECREF(m_arr);
443419
m_arr = NULL;
444420
m_data = NULL;
445421
m_shape = zeros;

src/py_converters.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,14 @@ int convert_offset_position(PyObject *obj, void *offsetp)
493493
e_offset_position *offset = (e_offset_position *)offsetp;
494494
const char *names[] = {"data", NULL};
495495
int values[] = {OFFSET_POSITION_DATA};
496-
int result;
497-
498-
*offset = OFFSET_POSITION_FIGURE;
496+
int result = (int)OFFSET_POSITION_FIGURE;
499497

500-
if (convert_string_enum(obj, "offset_position", names, values, &result)) {
501-
*offset = (e_offset_position)result;
502-
} else {
498+
if (!convert_string_enum(obj, "offset_position", names, values, &result)) {
503499
PyErr_Clear();
504500
}
505501

502+
*offset = (e_offset_position)result;
503+
506504
return 1;
507505
}
508506

0 commit comments

Comments
 (0)