From: <and...@us...> - 2011-01-11 15:54:26
|
Revision: 11481 http://plplot.svn.sourceforge.net/plplot/?rev=11481&view=rev Author: andrewross Date: 2011-01-11 15:54:19 +0000 (Tue, 11 Jan 2011) Log Message: ----------- Swig interfaces now specify whether or not an array is allowed to be NULL. This is used for unused arguments in pllegend. Octave example 4 and 33 demonstrate this. Python was already slacker in allowing NULL arrays in all cases, but java and octave did not. Modified Paths: -------------- trunk/bindings/lua/plplotluac.i trunk/bindings/octave/plplot_octave.i trunk/bindings/python/plplotcmodule.i trunk/examples/octave/x04c.m trunk/examples/octave/x33c.m Modified: trunk/bindings/lua/plplotluac.i =================================================================== --- trunk/bindings/lua/plplotluac.i 2011-01-11 15:52:26 UTC (rev 11480) +++ trunk/bindings/lua/plplotluac.i 2011-01-11 15:54:19 UTC (rev 11481) @@ -159,6 +159,17 @@ } %typemap(freearg) PLINT *ArrayCk { LUA_FREE_ARRAY($1); } +/* No count but check consistency with previous, or NULL */ +%typemap(in) PLINT *ArrayCkNull (int temp) { + $1 = (PLINT*)LUA_get_int_num_array_var(L, $input, &temp); + if(!$1) SWIG_fail; + if(temp != Alen) { + lua_pushfstring(L, "Tables must be of same length."); + SWIG_fail; + } +} +%typemap(freearg) PLINT *ArrayCkNull { LUA_FREE_ARRAY($1); } +%typemap(default) PLINT *ArrayCkNull { $1=NULL; } /* Weird case to allow argument to be one shorter than others */ %typemap(in) PLINT *ArrayCkMinus1 (int temp) { @@ -232,6 +243,18 @@ %typemap(freearg) PLFLT *ArrayCk { LUA_FREE_ARRAY($1); } +/* no count, but check consistency with previous, or NULL */ +%typemap(in) PLFLT *ArrayCkNull (int temp) { + $1 = (PLFLT*)LUA_get_double_num_array_var(L, $input, &temp); + if(!$1) SWIG_fail; + if(temp != Alen) { + lua_pushfstring(L, "Tables must be of same length."); + SWIG_fail; + } +} +%typemap(freearg) PLFLT *ArrayCkNull { LUA_FREE_ARRAY($1); } + + /* No length but remember size to check others */ %typemap(in) PLFLT *Array { int temp; @@ -240,8 +263,8 @@ Alen = temp; } %typemap(freearg) (PLFLT *Array) { LUA_FREE_ARRAY($1); } +%typemap(default) PLFLT *ArrayCkNull { $1=NULL; } - /* with trailing count */ %typemap(in) (PLFLT *Array, PLINT n) { int temp; Modified: trunk/bindings/octave/plplot_octave.i =================================================================== --- trunk/bindings/octave/plplot_octave.i 2011-01-11 15:52:26 UTC (rev 11480) +++ trunk/bindings/octave/plplot_octave.i 2011-01-11 15:54:19 UTC (rev 11481) @@ -220,6 +220,23 @@ } %typemap(freearg) PLINT *ArrayCk {delete [] $1;} +// No count but check consistency with previous +%typemap(in) PLINT *ArrayCkNull (Matrix temp) { + if ( _n_dims($input) > 1 ) + { error("argument must be a scalar or vector"); SWIG_fail; } + if ( ! $input.is_empty() ) { + if ( _dim($input, 0) != Alen ) + { error("argument vectors must be same length"); SWIG_fail; } + temp = $input.matrix_value(); + $1 = new PLINT[Alen]; + _cvt_double_to($1, &temp(0,0), Alen); + } + else { + $1 = NULL; + } +} +%typemap(freearg) PLINT *ArrayCkNull {if ($1 != NULL) delete [] $1;} + // No count but remember size to check others %typemap(in) PLINT *Array (Matrix temp) { if ( _n_dims($input) > 1 ) @@ -295,6 +312,22 @@ } %typemap(freearg) PLFLT *ArrayCk {} +// No count but check consistency with previous or NULL +%typemap(in) PLFLT *ArrayCkNull (Matrix temp) { + if ( _n_dims($input) > 1 ) + { error("argument must be a scalar or vector"); SWIG_fail; } + if ( ! $input.is_empty() ) { + if ( _dim($input, 0) != Alen ) + { error("argument vectors must be same length"); SWIG_fail; } + temp = $input.matrix_value(); + $1 = &temp(0,0); + } + else { + $1 = NULL; + } +} +%typemap(freearg) PLFLT *ArrayCkNull {} + // No count but remember size to check others %typemap(in) PLFLT *Array (Matrix temp) { if ( _n_dims($input) > 1 ) @@ -1138,7 +1171,7 @@ printf("nlegend = %d\n", nlegend); for(i=0;i<nlegend;i++) { printf("opt_array[%d] = %d\n", i, opt_array[i]); - printf("strlen(text[%d]) = %d\n", i, strlen(text[i])); + printf("strlen(text[%d]) = %d\n", i, (int) strlen(text[i])); printf("text[%d] = %s\n", i, text[i]); } } @@ -1156,6 +1189,7 @@ { error("argument must be a scalar or vector or matrix"); SWIG_fail; } + if ( ! $input.is_empty() ) { if ( _dim($input, 0) != Alen ) { error("first dimension must be same length as previous vector"); SWIG_fail; @@ -1224,14 +1258,20 @@ $1[i][non_blank_length+1] = '\0'; } } + } + else { + $1 = NULL; + } } %typemap(freearg) char **ArrayCk { int i; + if ($1 != NULL) { for(i=0; i<Alen; i++) { delete[] $1[i]; } delete[] $1; + } } // This test function should be removed when we are confident of our Modified: trunk/bindings/python/plplotcmodule.i =================================================================== --- trunk/bindings/python/plplotcmodule.i 2011-01-11 15:52:26 UTC (rev 11480) +++ trunk/bindings/python/plplotcmodule.i 2011-01-11 15:54:19 UTC (rev 11481) @@ -178,6 +178,18 @@ } %typemap(freearg) PLINT *ArrayCk { Py_DECREF(tmp$argnum);} +/* No count but check consistency with previous or NULL */ +%typemap(in) PLINT *ArrayCkNull (PyArrayObject* tmp) { + tmp = (PyArrayObject *)myIntArray_ContiguousFromObject($input, PyArray_PLINT, 1, 1); + if(tmp == NULL) return NULL; + if(tmp->dimensions[0] != Alen) { + PyErr_SetString(PyExc_ValueError, "Vectors must be same length."); + return NULL; + } + $1 = (PLINT*)tmp->data; +} +%typemap(freearg) PLINT *ArrayCkNull { Py_DECREF(tmp$argnum);} + /* Weird case to allow argument to be one shorter than others */ %typemap(in) PLINT *ArrayCkMinus1 (PyArrayObject* tmp) { tmp = (PyArrayObject *)myIntArray_ContiguousFromObject($input, PyArray_PLINT, 1, 1); @@ -271,6 +283,18 @@ } %typemap(freearg) PLFLT *ArrayCk { Py_DECREF(tmp$argnum);} +/* no count, but check consistency with previous, or NULL */ +%typemap(in) PLFLT *ArrayCkNull (PyArrayObject* tmp) { + tmp = (PyArrayObject *)myArray_ContiguousFromObject($input, PyArray_PLFLT, 1, 1); + if(tmp == NULL) return NULL; + if(tmp->dimensions[0] != Alen) { + PyErr_SetString(PyExc_ValueError, "Vectors must be same length."); + return NULL; + } + $1 = (PLFLT*)tmp->data; +} +%typemap(freearg) PLFLT *ArrayCkNull { Py_DECREF(tmp$argnum);} + /* check consistency with X dimension of previous */ %typemap(in) PLFLT *ArrayCkX (PyArrayObject* tmp) { tmp = (PyArrayObject *)myArray_ContiguousFromObject($input, PyArray_PLFLT, 1, 1); @@ -460,7 +484,7 @@ /*************************** special for pllegend, char ** ArrayCk ****************************/ -/* no count, but check consistency with previous */ +/* no count, but check consistency with previous. Always allow NULL strings. */ %typemap(in) char **ArrayCk (PyArrayObject* tmp) { int i; tmp = (PyArrayObject *)PyArray_ContiguousFromObject($input, NPY_STRING, 1, 1); Modified: trunk/examples/octave/x04c.m =================================================================== --- trunk/examples/octave/x04c.m 2011-01-11 15:52:26 UTC (rev 11480) +++ trunk/examples/octave/x04c.m 2011-01-11 15:54:19 UTC (rev 11481) @@ -109,10 +109,6 @@ opt_array = 0; text_colors = 0; text = " "; - box_colors = 0; - box_patterns = 0; - box_scales = 0.; - box_line_widths = 0; line_colors = 0; line_styles = 0; line_widths = 0; @@ -124,10 +120,6 @@ opt_array(nlegend,1) = 0; text_colors(nlegend,1) = 0; text(nlegend,1:length(" ")) = " "; - box_colors(nlegend,1) = 0; - box_patterns(nlegend,1) = 0; - box_scales(nlegend,1) = 0.; - box_line_widths(nlegend,1) = 0; line_colors(nlegend,1) = 0; line_styles(nlegend,1) = 0; line_widths(nlegend,1) = 0; @@ -167,7 +159,7 @@ pllegend( bitor(PL_LEGEND_BACKGROUND, PL_LEGEND_BOUNDING_BOX), 0.0, 0.0, 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); Modified: trunk/examples/octave/x33c.m =================================================================== --- trunk/examples/octave/x33c.m 2011-01-11 15:52:26 UTC (rev 11480) +++ trunk/examples/octave/x33c.m 2011-01-11 15:54:19 UTC (rev 11481) @@ -216,10 +216,6 @@ opt_array(nlegend,1) = 0; text_colors(nlegend,1) = 0; text(nlegend,1:length(" ")) = " "; - box_colors(nlegend,1) = 0; - box_patterns(nlegend,1) = 0; - box_scales(nlegend,1) = 0.; - box_line_widths(nlegend,1) = 0; line_colors(nlegend,1) = 0; line_styles(nlegend,1) = 0; line_widths(nlegend,1) = 0; @@ -253,7 +249,7 @@ pllegend( opt, 0.05, 0.05, 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); endfor @@ -294,10 +290,6 @@ opt_array(nlegend,1) = 0; text_colors(nlegend,1) = 0; text(nlegend,1:length(" ")) = " "; - box_colors(nlegend,1) = 0; - box_patterns(nlegend,1) = 0; - box_scales(nlegend,1) = 0.; - box_line_widths(nlegend,1) = 0; line_colors(nlegend,1) = 0; line_styles(nlegend,1) = 0; line_widths(nlegend,1) = 0; @@ -336,7 +328,7 @@ pllegend( opt, x, y, 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); @@ -349,7 +341,7 @@ pllegend( opt, x, y, 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); @@ -362,7 +354,7 @@ pllegend( opt, x, y, 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); @@ -375,7 +367,7 @@ pllegend( opt, x, y, 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); @@ -388,7 +380,7 @@ pllegend( opt, x, y, 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); @@ -401,7 +393,7 @@ pllegend( opt, x, y, 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); @@ -414,7 +406,7 @@ pllegend( opt, x, y, 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); @@ -503,7 +495,7 @@ pllegend( opt, x, y, 0.025, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 1.5, 1., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, symbols ); if(i == nturn) @@ -649,8 +641,8 @@ pllegend( opt, x, y, 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, - line_colors, line_styles, line_widths, + [], [], [], [], + [], [], [], symbol_colors, symbol_scales, symbol_numbers, symbols ); max_height = max(max_height, legend_height); @@ -680,8 +672,8 @@ pllegend( opt, x, y, 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text, - box_colors, box_patterns, box_scales, box_line_widths, - line_colors, line_styles, line_widths, + [], [], [], [], + [], [], [], symbol_colors, symbol_scales, symbol_numbers, symbols ); max_height = max(max_height, legend_height); @@ -715,8 +707,8 @@ 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text, box_colors, box_patterns, box_scales, box_line_widths, - line_colors, line_styles, line_widths, - symbol_colors, symbol_scales, symbol_numbers, symbols ); + [], [], [], + [], [], [], [] ); max_height = max(max_height, legend_height); ## Set up box legend entries with various patterns. @@ -746,8 +738,8 @@ 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text, box_colors, box_patterns, box_scales, box_line_widths, - line_colors, line_styles, line_widths, - symbol_colors, symbol_scales, symbol_numbers, symbols ); + [], [], [], + [], [], [], [] ); max_height = max(max_height, legend_height); ## Set up box legend entries with various box pattern line widths. @@ -777,8 +769,8 @@ 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text, box_colors, box_patterns, box_scales, box_line_widths, - line_colors, line_styles, line_widths, - symbol_colors, symbol_scales, symbol_numbers, symbols ); + [], [], [], + [], [], [], [] ); max_height = max(max_height, legend_height); ## Set up line legend entries with various colours. @@ -811,9 +803,9 @@ pllegend( opt, x, y, 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text', - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, - symbol_colors, symbol_scales, symbol_numbers, symbols' ); + [], [], [], [] ); max_height = max(max_height, legend_height); ## Set up line legend entries with various styles @@ -838,9 +830,9 @@ pllegend( opt, x, y, 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text', - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, - symbol_colors, symbol_scales, symbol_numbers, symbols' ); + [], [], [], [] ); max_height = max(max_height, legend_height); ## Set up line legend entries with various widths. @@ -866,9 +858,9 @@ pllegend( opt, x, y, 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 0., text_colors, text', - box_colors, box_patterns, box_scales, box_line_widths, + [], [], [], [], line_colors, line_styles, line_widths, - symbol_colors, symbol_scales, symbol_numbers, symbols' ); + [], [], [], [] ); max_height = max(max_height, legend_height); ## Color bar examples This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |