Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scicos C function problem in Scilab

59 views
Skip to first unread message

Edsoncv

unread,
Oct 8, 2008, 1:54:15 PM10/8/08
to
Hello
I'm having a strange behavior with a compiled block in scicos, maybe
I'm doing something wrong, but it can also be a scilab bug, that's the
reason for my post.
Scilab 5.0.1 for windows
Compiler MSVC 9
After successfully compile a simple C function to evaluate the outputs
from inputs with MSVC9, I ran a simple diagram to evaluate the
results. After a sucessfull integration at the flag = 5, I got the
following error, related with memory allocation:

Warning !!!
Scilab has found a critical error (EXCEPTION_ACCESS_VIOLATION)
with "scicosim" function.
Save your data and restart Scilab.

The function I use is very simple, I build it with debug purposes:

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "scicos_block4.h"

struct emso_str {
char *u_name;
char *y_name;
int *nU;
int *nY;

} ;
void print_str(emso_str * PWork);
extern "C" _declspec(dllexport) void test(scicos_block *block,int
flag)
{ printf("flag: %d\n", flag);

if (flag == 4) { /* initialization */
emso_str *PWork;
printf("Started initialization\n");
if ((*block->work= (emso_str*) scicos_malloc(sizeof(emso_str)))==
NULL ) {
set_block_error(-16);
return;
}
PWork = (emso_str*) block->work;
PWork->u_name = new char [block->insz[0]];
PWork->u_name = "in";
PWork->y_name = new char [block->outsz[0]];
PWork->y_name = "ou";
int *uu = new int;
int *yy = new int;
uu[0] = block->insz[0];
yy[0] = block->outsz[0];
PWork->nU = uu;
PWork->nY = yy;

}
else if(flag == 1) { /* output computation*/
printf("Started output computation\n");
emso_str *PWork= (emso_str*) block->work;

SCSREAL_COP *ptr_in;
SCSREAL_COP *ptr_out;
ptr_in = (SCSREAL_COP *)block->inptr[0];
ptr_out = (SCSREAL_COP *)block->outptr[0];
ptr_out[0] = 2* get_scicos_time()*ptr_in[0];
ptr_out[1] = 2* get_scicos_time()*ptr_in[1];
print_str(PWork);
} else if (flag == 5) { /* ending */
emso_str *PWork= (emso_str*) block->work;
delete PWork->nU;
delete PWork->nY;
delete [] PWork->u_name;
delete [] PWork->y_name;
scicos_free(PWork);
}
}
void print_str(emso_str * PWork){
printf("inside print_str\n");
printf("NU: %d\n", PWork->nU[0]);
printf("NY: %d\n", PWork->nY[0]);
printf("%s\n", PWork->u_name);
printf("%s\n",PWork->y_name);
}
#ifdef __cplusplus
}; //extern "C"
#endif

My scicos diagram is like this:

Constant block ->|
| ->|Generic Block| ->Scope
Constant block-> |
(mux)

And my generic block parameters are like this:
Simulate function: test
Func. Type:4
In port sizes [-1,-2]
Out port sizes [-1,-2]
In port type 1
Out port type 1
all other parameters are default

I found it very strange since I suppose to have deleted all allocated
objects, maybe I'm missing something.
Thanks

Edsoncv

unread,
Oct 8, 2008, 3:48:38 PM10/8/08
to

Hello again
After take a deeper look at the output messages I found that my
structure created for passing extra arguments is being corrupted right
after the initialization flag. Anyone can tell me if it's a bug?
Thanks

Ramine.N...@inria.fr

unread,
Oct 8, 2008, 4:40:37 PM10/8/08
to


Hello,
Normally what Scicos does with work is keeping its address;
scicos_malloc
is just malloc. Since you do the allocations, I don't see how Scicos
can corrupt
the structure unless something has been changed in Scilab 5 version of
Scicos.
Have you tried your example in the latest version of Scicos, scicos
4.2.1 distributed
with scilabgtk. If it does not work there, just send me the diagram, I
take a look.

Cheers
Ramine

Edsoncv

unread,
Oct 8, 2008, 4:54:30 PM10/8/08
to
On 8 out, 17:40, Ramine.Nikouk...@inria.fr wrote:
> On 8 oct, 21:48,Edsoncv<edso...@gmail.com> wrote:

Hello Ramine

I tried the same C program in scilab 5.0.2 in linux. The pointers does
not became corrupt but there was a problem reported as "cross variable
size checking 1" and the simulation does not go on.
I downloaded the gtk version and since I'm linking outside scilab I
would like to know where are the scilab and scicos libs (or .so) in
linux, I couldn't find them.
Thanks

Edsoncv

unread,
Oct 8, 2008, 5:57:32 PM10/8/08
to
>          Thanks- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -

Hello Ramine
I tried with scil ab 4.2 gtk for windows and got the same problem, is
it ok to send you the diagram by e-mail?
Thanks again

ramine

unread,
Oct 9, 2008, 3:11:22 AM10/9/08
to
Edsoncv a écrit :

Sure no problem. Send me the .cos file and whatever else I need to make
it run (I suppose it is just a C code).

Ramine

Edsoncv

unread,
Oct 13, 2008, 9:22:13 AM10/13/08
to
On 9 out, 05:11, ramine <ramine.nikou...@scicos.inria.fr> wrote:
> Edsoncva écrit :

Ramine

I've already sent you the e-mails, did you received them? I've been
receiving delivery failure notification, are there another e-mail to
send you the files?
EdsonCV

ramine

unread,
Oct 13, 2008, 11:00:50 AM10/13/08
to
Edsoncv a écrit :

Non I have not received it. I don't have any particular filter simply
make sure the file you are sending is less than 2 megs.
Ramine

Edsoncv

unread,
Oct 13, 2008, 2:19:40 PM10/13/08
to

Ramine
Even a common e-mail sent to you 11-oct returned. I'll try to send
you from another address: edsoncv at vrtech dot com dot br
Regards

Edsoncv

unread,
Oct 17, 2008, 6:03:55 PM10/17/08
to
> you from another address:edsoncvat vrtech dot com dot br
> Regards

After some talk with the developers I found my problem, in fact 2
of them:

I was creating a struture

if ((*block->work= (e_str*) scicos_malloc(sizeof(e_str)))== NULL ) {
set_block_error(-16);
return;
}

and casting it this way:

PWork = (e_str*) block->work;

and the right is:

PWork = (e_str*) * block->work;

also, I was suggested to copy a char this way:

(void)strncpy(PWork->u_name, "in", sizeof(PWork->u_name));

instead of

PWork2->u_name = new char [2];
PWork2->u_name = "in";

where PWork->uname is a member of a structure allocated this way:

struct e_str {
char u_name[3];
} ;

and PWork2 was:

struct e_str {
char *u_name;
} ;
EdsonCV

0 new messages