[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FTP functions
From: |
Xavier Delacour |
Subject: |
Re: FTP functions |
Date: |
Mon, 24 Mar 2008 23:24:21 -0400 |
On Mon, Mar 24, 2008 at 9:52 PM, John W. Eaton <address@hidden> wrote:
> On 24-Mar-2008, Xavier Delacour wrote:
>
>
> | Other than being a lot more work, I don't see how this solution is
> | really any different from what is in octave-forge. The package as is
> | provides the full interface, and is given in about 250 lines (most of
> | which passes through to ftplib.
>
> The SWIG solution may be OK. I have not tried using it. Looking at
> the sources, I don't don't see any doc strings defined for these
> functions. Am I missing something? Is there a way to insert the
> Texinfo doc strings for the DEFUN macros in the interface definition
> file you use for generating the wrappers?
That is missing, yes. I am working on it, both automatic generation
and manual insertion of texinfo docs.
Manual insertion would look something like
%docstring func_name {
usual texinfo docs, as given to DEFUN
}
There is already similar support for various SWIG targets (eg Python).
> How thoroughly are
> arguments checked, and how are those checks performed?
By using "typemaps", which match a sequence of input arguments by
their type and optionally names, and insert the argument checking and
translation code. A simple example of a custom typemap:
%typemap(in,noblock=1) (const double* A,int m,int n) (Matrix tmp) {
if (!$input.is_matrix_type()) {
error("A must be a matrix");
SWIG_fail;
}
tmp=$input.matrix_value();
$1=tmp.data();
$2=tmp.rows();
$3=tmp.columns();
}
double sum_2d(const double* A,int m,int n) {
double s=0;
for (int j=0,k=m*n;j<k;++j)
s+=A[j];
return s;
}
This would generate a wrapper for sum_2d that looks like this:
static octave_value_list _wrap_sum_2d (const octave_value_list& args,
int nargout) {
double *arg1 = (double *) 0 ;
int arg2 ;
int arg3 ;
double result;
Matrix tmp1 ;
octave_value_list _out;
octave_value_list *_outp=&_out;
octave_value _outv;
if (!SWIG_check_num_args("sum_2d",args.length(),1,1,0)) {
SWIG_fail;
}
if (!args(0).is_matrix_type()) {
error("A must be a matrix");
SWIG_fail;
}
tmp1=args(0).matrix_value();
arg1=tmp1.data();
arg2=tmp1.rows();
arg3=tmp1.columns();
result = (double)sum_2d((double const *)arg1,arg2,arg3);
_outv = SWIG_From_double((double)(result));
if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
fail:
return _out;
}
SWIG_check_num_args, SWIG_From_double, and SWIG_Octave_AppendOutput
are helpers that do the obvious things (call error if bad num args,
return octave_value from double, call append on _out).
All primitive types and various STL types have typemaps predefined.
Usually there are only a small number of typemap defs required to wrap
an entire library, and it's no problem to have rigorous argument
checking (including for overload dispatching).
There is extensive documentation:
http://www.swig.org/Doc1.3/Contents.html#Contents
http://www.swig.org/Doc1.3/Typemaps.html#Typemaps
>
>
> | The package
> | also includes a few test cases.
>
> How about using a smaller file for your test? Also, why did you
> choose the gcc-objc sources?
Arbitrarily. I'll change it to something else, and something that's smaller.
Xavier