Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 30-May-2012 13:44:30

Nodrev
Scol Language & OS3D developer
From: Nantes, France
Registered: 29-Dec-2009
Posts: 197

fread as a vm function, what's the point?

I'm digging in the vm, and i found something quite strange in "scolCbMachine.h":

struct CBmachine
{
...
int (*fread)(char* buf, size_t i, size_t j, FILE *f);
...
};

This function ptr is is latterly initialized as

int SCinitCBm(cbmachine w)
{
...
w->fread=fread;
...
}

The assignated "fread" being the standard c function declared in "stdio.h"... What's the point about that? Why declaring a standard C function as part of the VM, when it's always possible to call it directly?
At first I suspected a multithreading hack (to be sure that this function is called in scol thread), but it's non-sense too!
And as the std fread signature is not exactly the same as the one declared in size_t (originally, it's "size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );"), it do not work for every buffers types, and can makes problems on systems where size_t is too big for int...

So, is there any reason to keep this horror? I will not remove it, just rename the (*fread) function ptr as it makes some conflicts in some cases with stdio definition...
But if anyone knows why this was done, i would like to know the reason smile

Last edited by Nodrev (30-May-2012 13:45:21)

Offline

#2 30-May-2012 15:09:55

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: fread as a vm function, what's the point?

Oh, Welcome to the club !

I searched several times on this ... thing. I know the source of 3.5 already contains this redefinition, so this dates from 1999/2000. I thinked too to skirt a specific problem in the VM. Or, anyone has thinked that the read data were chars, so he changed the prototype .... Unless it was an hideous hack to avoid a compilation warning or other thing.
In my mind, such a redefinition is not justified, fread is a C-standard function. If a speific prototype was imperative, a new function (like scolFread) was the best choice rather than a bullshit. I could be wrong smile Today, nobody knows why !... smile
Unless error on my part, this doesn't exist in the GNU/Linux version, the C-standard function is used.

Offline

#3 30-May-2012 15:58:03

Nodrev
Scol Language & OS3D developer
From: Nantes, France
Registered: 29-Dec-2009
Posts: 197

Re: fread as a vm function, what's the point?

Ok, thanks for the infos smile

Offline

#4 30-May-2012 17:33:18

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: fread as a vm function, what's the point?

Either that is really a bullshit, or that is an hack (as you say) for a well-hidden bit of code. If the second case, it's boring !!

Offline

#5 30-May-2012 18:48:57

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: fread as a vm function, what's the point?

Bob agrees too. He tries some tests for his part

Offline

#6 30-May-2012 19:12:49

Bob Le Gob
Scol language & Scol applications developer
Registered: 9-Apr-2009
Posts: 26

Re: fread as a vm function, what's the point?

Moreover, fread is the only classic file handling function which is re-defined in this way. So I do not think, at first glance, that handling fread in such a way is useful. I'll make a few tests to check this.

Offline

#7 31-May-2012 10:19:01

Nodrev
Scol Language & OS3D developer
From: Nantes, France
Registered: 29-Dec-2009
Posts: 197

Re: fread as a vm function, what's the point?

Thanks Bob, I already renamed it anyway smile.

Offline

#8 31-May-2012 10:25:45

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: fread as a vm function, what's the point?

Yes, seen in the last commit smile

Offline

Board footer

Powered by FluxBB