From c5e3869c32dd139a76661274c5ca79eae5a530b2 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 18 Feb 2011 10:36:18 +0000 Subject: [PATCH] replaced alloca() (a.k.a. cvStackAlloc) with AutoBuffer or vector() everywhere. cvStackAlloc() is still defined, but we do not need alloca() anymore to compile and run OpenCV (fixes #889 and may be some others) --- modules/calib3d/src/stereogc.cpp | 4 ++-- modules/core/src/persistence.cpp | 3 +-- modules/ml/src/rtrees.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/calib3d/src/stereogc.cpp b/modules/calib3d/src/stereogc.cpp index 96a3a79758..52ec20d387 100644 --- a/modules/calib3d/src/stereogc.cpp +++ b/modules/calib3d/src/stereogc.cpp @@ -483,7 +483,7 @@ icvComputeK( CvStereoGCState* state ) int x, y, x1, d, i, j, rows = state->left->rows, cols = state->left->cols, n = 0; int mind = state->minDisparity, nd = state->numberOfDisparities, maxd = mind + nd; int k = MIN(MAX((nd + 2)/4, 3), nd), delta, t, sum = 0; - vector _arr(k); + std::vector _arr(k+1); int *arr = &_arr[0]; for( y = 0; y < rows; y++ ) @@ -902,7 +902,7 @@ CV_IMPL void cvFindStereoCorrespondenceGC( const CvArr* _left, const CvArr* _rig icvInitStereoConstTabs(); icvInitGraySubpix( left, right, state->left, state->right ); - vector disp(state->numberOfDisparities); + std::vector disp(state->numberOfDisparities); CvMat _disp = cvMat( 1, (int)disp.size(), CV_32S, &disp[0] ); cvRange( &_disp, state->minDisparity, state->minDisparity + state->numberOfDisparities ); cvRandShuffle( &_disp, &rng ); diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index c802fa3053..35fbfa582f 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -3619,7 +3619,6 @@ icvReadSparseMat( CvFileStorage* fs, CvFileNode* node ) CvFileNode* sizes_node; CvSeqReader reader; CvSeq* elements; - int* idx; int sizes[CV_MAX_DIM_HEAP], dims, elem_type, cn; int i; @@ -3645,7 +3644,7 @@ icvReadSparseMat( CvFileStorage* fs, CvFileNode* node ) mat = cvCreateSparseMat( dims, sizes, elem_type ); cn = CV_MAT_CN(elem_type); - idx = (int*)alloca( dims*sizeof(idx[0]) ); + int idx[CV_MAX_DIM_HEAP]; elements = data->data.seq; cvStartReadRawData( fs, data, &reader ); diff --git a/modules/ml/src/rtrees.cpp b/modules/ml/src/rtrees.cpp index 56075652d2..79ae66566f 100644 --- a/modules/ml/src/rtrees.cpp +++ b/modules/ml/src/rtrees.cpp @@ -646,7 +646,8 @@ float CvRTrees::predict( const CvMat* sample, const CvMat* missing ) const if( nclasses > 0 ) //classification { int max_nvotes = 0; - int* votes = (int*)alloca( sizeof(int)*nclasses ); + cv::AutoBuffer _votes(nclasses); + int* votes = _votes; memset( votes, 0, sizeof(*votes)*nclasses ); for( k = 0; k < ntrees; k++ ) { @@ -682,7 +683,8 @@ float CvRTrees::predict_prob( const CvMat* sample, const CvMat* missing) const if( nclasses == 2 ) //classification { int max_nvotes = 0; - int* votes = (int*)alloca( sizeof(int)*nclasses ); + cv::AutoBuffer _votes(nclasses); + int* votes = _votes; memset( votes, 0, sizeof(*votes)*nclasses ); for( k = 0; k < ntrees; k++ ) { -- GitLab