|
From: | Riccardo Corradini |
Subject: | Re: How could octave use pvm library pvm_spawn ? |
Date: | Thu, 8 Mar 2007 11:26:31 +0100 (CET) |
On 28-Feb-2007, Riccardo Corradini wrote:
| DEFUN_DLD(pvm_pkcharMAT,args,, "This function emulates the C function pvm_pkbyte of pvm3 library, but packs any char matrixes with any dimensions \n")
| {
|
|
|
| octave_value_list retval;
| double nargin = args.length ();
|
| if (nargin != 2)
| {
| error ("expecting 2 input arguments");
| return retval;
| }
|
| const charNDArray tarray = args(0).char_array_value();
| int nitem = tarray.capacity();
| char *p = const_cast( tarray.data() );
I dont' think you should be using const_cast here. Octave is not
designed for you to be modifying arguments passed to functions. If
you need to do that, you need to make a copy, and return the copy to
the caller. To do that, write
charNDArray tarray = args(0).char_array_value ();
char *p = tarray.fortran_vec ();
Or, if it is just that
| int info2 = pvm_pkbyte (p, nitem, stride);
has the wrong declaration for the first arg (char* instead of const
char*), and it really doesn't ever modify the contents of the vector,
then maybe you should fix the declaration of pvm_pkbyte?
| // Could I use an octave_local_buffer macro if so .. how?
| charNDArray oar (dv);
| if( (n != oar.capacity()) )
| {
| error ("errors with dims");
| return retval;
| }
|
| char *preal = const_cast( oar.data() );
Again, I dont' think you want a const_cast here. Use
char *preal = oar.fortran_vec ();
| int info1 = pvm_upkbyte (preal, n, stride);
| retval(0) = static_cast(info1);
It looks like the type of info1 is already an int, so why do you use a
cast here?
| return octave_value_list(retval);
The variable retval is already an octave_value_list, so you can just
write
return retval;
jwe
[Prev in Thread] | Current Thread | [Next in Thread] |