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

Skip to content

Commit 059d7d6

Browse files
committed
fixed a string mem allocation bug
svn path=/trunk/matplotlib/; revision=421
1 parent 25e6095 commit 059d7d6

6 files changed

Lines changed: 54 additions & 36 deletions

File tree

MANIFEST

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GOALS
55
INSTALL
66
INTERACTIVE
77
KNOWN_BUGS
8+
MANIFEST
89
MANIFEST.in
910
Makefile
1011
README
@@ -21,6 +22,9 @@ CXX/Objects.hxx
2122
CXX/cxx_extensions.cxx
2223
CXX/cxxextensions.c
2324
CXX/cxxsupport.cxx
25+
agg2/.cvsignore
26+
agg2/gpc/copying.txt
27+
agg2/gpc/gpc.c
2428
agg2/gpc/gpc.h
2529
agg2/include/agg_affine_matrix.h
2630
agg2/include/agg_alpha_mask_u8.h
@@ -137,6 +141,7 @@ agg2/src/agg_arrowhead.cpp
137141
agg2/src/agg_bezier_arc.cpp
138142
agg2/src/agg_bspline.cpp
139143
agg2/src/agg_curves.cpp
144+
agg2/src/agg_embedded_raster_fonts.cpp
140145
agg2/src/agg_gen_contour.cpp
141146
agg2/src/agg_gen_dash.cpp
142147
agg2/src/agg_gen_markers_term.cpp
@@ -261,15 +266,10 @@ examples/stock_demo.py
261266
examples/subplot_demo.py
262267
examples/system_monitor.py
263268
examples/table_demo.py
264-
examples/test.py
265-
examples/test2.py
266-
examples/test3.py
267-
examples/test4.py
268-
examples/test5.py
269-
examples/test6.py
270269
examples/text_handles.py
271270
examples/text_themes.py
272271
examples/to_numeric.py
272+
examples/two_dymamic_images.py
273273
examples/two_scales.py
274274
examples/vertical_ticklabels.py
275275
examples/vline_demo.py
@@ -332,37 +332,32 @@ fonts/afm/pzdr.afm
332332
fonts/ttf/COPYRIGHT.TXT
333333
fonts/ttf/README.TXT
334334
fonts/ttf/RELEASENOTES.TXT
335-
fonts/ttf/Vera.pfa
336335
fonts/ttf/Vera.ttf
337-
fonts/ttf/VeraBI.pfa
338336
fonts/ttf/VeraBI.ttf
339-
fonts/ttf/VeraBd.pfa
340337
fonts/ttf/VeraBd.ttf
341-
fonts/ttf/VeraIt.pfa
342338
fonts/ttf/VeraIt.ttf
343-
fonts/ttf/VeraMoBI.pfa
344339
fonts/ttf/VeraMoBI.ttf
345-
fonts/ttf/VeraMoBd.pfa
346340
fonts/ttf/VeraMoBd.ttf
347-
fonts/ttf/VeraMoIt.pfa
348341
fonts/ttf/VeraMoIt.ttf
349-
fonts/ttf/VeraMono.pfa
350342
fonts/ttf/VeraMono.ttf
351-
fonts/ttf/VeraSe.pfa
352343
fonts/ttf/VeraSe.ttf
353-
fonts/ttf/VeraSeBd.pfa
354344
fonts/ttf/VeraSeBd.ttf
355-
fonts/ttf/cmex10.pfa
356345
fonts/ttf/cmex10.ttf
357-
fonts/ttf/cmmi10.pfa
358346
fonts/ttf/cmmi10.ttf
359-
fonts/ttf/cmr10.pfa
360347
fonts/ttf/cmr10.ttf
361-
fonts/ttf/cmsy10.pfa
362348
fonts/ttf/cmsy10.ttf
363-
fonts/ttf/cmtt10.pfa
364349
fonts/ttf/cmtt10.ttf
365350
fonts/ttf/local.conf
351+
images/back.ppm
352+
images/back.xpm
353+
images/filesave.ppm
354+
images/filesave.xpm
355+
images/forward.ppm
356+
images/forward.xpm
357+
images/hand.ppm
358+
images/hand.xpm
359+
images/home.ppm
360+
images/home.xpm
366361
images/stock_close.ppm
367362
images/stock_close.xpm
368363
images/stock_down.ppm
@@ -381,6 +376,8 @@ images/stock_zoom-in.ppm
381376
images/stock_zoom-in.xpm
382377
images/stock_zoom-out.ppm
383378
images/stock_zoom-out.xpm
379+
images/zoom_to_rect.ppm
380+
images/zoom_to_rect.xpm
384381
license/LICENSE
385382
license/LICENSE_PAINT
386383
license/LICENSE_PIL

TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,5 @@
474474
-- track down transforms memleak
475475

476476
-- DONE make sure you handle cacheing of rotated mathtext properly
477+
478+
- handle deprecated connect across backends graciously

examples/coords_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def on_move(event):
1616
# get the x and y pixel coords
1717
x, y = event.x, event.y
1818

19-
if event.inaxes is not None:
19+
if event.inaxes:
20+
ax = event.inaxes # the axes instance
2021
print 'data coords', event.xdata, event.ydata
2122

2223
def on_click(event):

examples/embedding_in_wx2.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ def __init__(self):
3838
self.canvas = FigureCanvas(self, -1, self.figure)
3939

4040
self.sizer = wxBoxSizer(wxVERTICAL)
41-
self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
41+
self.sizer.Add(self.canvas, 1, wxLEFT | wxTOP | wxGROW)
4242
self.SetSizer(self.sizer)
4343
self.Fit()
4444

4545
self.add_toolbar() # comment this out for no toolbar
4646

4747

48-
# Capture the paint message
49-
#EVT_PAINT(self, self.OnPaint)
50-
5148
def add_toolbar(self):
5249
self.toolbar = NavigationToolbar(self.canvas, True)
5350
self.toolbar.Realize()

src/_backend_agg.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,11 @@ RendererAgg::tostring_rgb(const Py::Tuple& args) {
10121012

10131013
args.verify_length(0);
10141014
int row_len = width*3;
1015-
unsigned char buf_tmp[row_len * height];
1015+
unsigned char* buf_tmp = new unsigned char[row_len * height];
1016+
if (buf_tmp ==NULL) {
1017+
//todo: also handle allocation throw
1018+
throw Py::MemoryError("RendererAgg::tostring_rgb could not allocate memory");
1019+
}
10161020
agg::rendering_buffer renderingBufferTmp;
10171021
renderingBufferTmp.attach(buf_tmp,
10181022
width,
@@ -1023,13 +1027,13 @@ RendererAgg::tostring_rgb(const Py::Tuple& args) {
10231027

10241028

10251029
//todo: how to do this with native CXX
1026-
return Py::asObject(Py_BuildValue("s#",
1027-
buf_tmp,
1028-
row_len * height));
1029-
//len = row_len * height
1030-
//std::string s(buf_tmp);
1031-
//return Py::String(buf_tmp, row_len * height);
1030+
PyObject* o = Py_BuildValue("s#",
1031+
buf_tmp,
1032+
row_len * height);
1033+
delete [] buf_tmp;
1034+
return Py::asObject(o);
10321035
}
1036+
10331037
agg::rgba
10341038
RendererAgg::get_color(const Py::Object& gc) {
10351039

src/_image.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,21 @@ Image::as_str(const Py::Tuple& args) {
178178
const size_t NUMBYTES(rowsOut * colsOut * BPP);
179179
const size_t BPR = colsOut * BPP; // bytes per row
180180

181-
agg::int8u buffer[NUMBYTES];
181+
agg::int8u* buffer = new agg::int8u[NUMBYTES];
182+
if (buffer ==NULL) //todo: also handle allocation throw
183+
throw Py::MemoryError("Image::as_str could not allocate memory");
184+
182185
size_t ind=0;
183186
for (long rowNum=rowsOut-1; rowNum>=0; rowNum--) { //not unsigned!
184187
size_t start = rowNum*BPR;
185188
for (size_t j=0; j<BPR; j++) {
186189
buffer[ind++] = *(bufferOut + start + j);
187190
}
188191
}
189-
return Py::asObject(Py_BuildValue("lls#", rowsOut, colsOut,
190-
buffer, NUMBYTES));
192+
PyObject* o = Py_BuildValue("lls#", rowsOut, colsOut,
193+
buffer, NUMBYTES);
194+
delete [] buffer;
195+
return Py::asObject(o);
191196

192197
}
193198

@@ -235,6 +240,9 @@ Image::resize(const Py::Tuple& args) {
235240

236241
size_t NUMBYTES(numrows * numcols * BPP);
237242
agg::int8u *buffer = new agg::int8u[NUMBYTES];
243+
if (buffer ==NULL) //todo: also handle allocation throw
244+
throw Py::MemoryError("Image::resize could not allocate memory");
245+
238246
rbufOut = new agg::rendering_buffer;
239247
rbufOut->attach(buffer, numcols, numrows, numcols * BPP);
240248

@@ -557,6 +565,9 @@ _image_module::from_images(const Py::Tuple& args) {
557565

558566
size_t NUMBYTES(numrows * numcols * imo->BPP);
559567
imo->bufferOut = new agg::int8u[NUMBYTES];
568+
if (imo->bufferOut==NULL) //todo: also handle allocation throw
569+
throw Py::MemoryError("_image_module::from_images could not allocate memory");
570+
560571
imo->rbufOut = new agg::rendering_buffer;
561572
imo->rbufOut->attach(imo->bufferOut, imo->colsOut, imo->rowsOut, imo->colsOut * imo->BPP);
562573

@@ -627,6 +638,9 @@ _image_module::fromarray(const Py::Tuple& args) {
627638

628639
size_t NUMBYTES(imo->colsIn * imo->rowsIn * imo->BPP);
629640
agg::int8u *buffer = new agg::int8u[NUMBYTES];
641+
if (buffer==NULL) //todo: also handle allocation throw
642+
throw Py::MemoryError("_image_module::fromarray could not allocate memory");
643+
630644
imo->bufferIn = buffer;
631645
imo->rbufIn = new agg::rendering_buffer;
632646
imo->rbufIn->attach(buffer, imo->colsIn, imo->rowsIn, imo->colsIn*imo->BPP);
@@ -695,6 +709,9 @@ _image_module::fromarray(const Py::Tuple& args) {
695709
imo->colsOut = imo->colsIn;
696710

697711
imo->bufferOut = new agg::int8u[NUMBYTES];
712+
if (buffer == imo->bufferOut) //todo: also handle allocation throw
713+
throw Py::MemoryError("_image_module::fromarray could not allocate memory");
714+
698715
imo->rbufOut = new agg::rendering_buffer;
699716
imo->rbufOut->attach(imo->bufferOut, imo->colsOut, imo->rowsOut, imo->colsOut * imo->BPP);
700717

0 commit comments

Comments
 (0)