What Bill is saying is that starting in 807, cd makes an copy of any
argument to cd that might be shared by another noun. So, the value of
'res' is put into a temporary block and passed to the DLL. The
temporary block is put into the boxed result of cd. You need to look in
that boxed result, not in the name res, which has not been modified.
This change was made in 807 because that release has a much more
aggressive policy of sharing nouns and parts of nouns without making
separate copies; for example
({. name)
actually gives you a pointer to the first item of name, without
recopying it, and
(i. 3)
is liable to give you a pointer to unchangeable internal data. With all
these pointers flying around we can no longer trust the user to know
when it is safe to pass a pointer into a DLL that might modify the data.
Henry Rich
On 11/18/2018 7:55 AM, bill lam wrote:
j807 must get from result of cd, like this
0 3{ (sqrdll, 'sqr i i *i *i') cd (#y);y;res
On Sun, Nov 18, 2018, 2:22 PM Ben Gorte <[email protected] wrote:
Dear All,
Long ago I made quite a lot of c-functions that I am calling from J using
the cd mechanism (load 'dll') in linux.
They stopped working in j64-807. I see in the release notes that indeed
something has changed, but I cannot quite relate that to my case (but maybe
I should - I'm not sure I entirely understand the story).
In the simplest form it looks like this:
First the c-code, sqr.c :
int sqr (int n, int a[], int b[])
{
int i, sumsqr=0;
for (i=0; i<n; i++)
sumsqr += b[i] = a[i] * a[i];
return sumsqr;
}
which I compile with
gcc -O3 -shared -fPIC -o sql.so -Wl,--no-as-needed sqr.c
(omitting -O3 does not make a difference).
In J I go like:
load 'dll'
sqrdll =: jpath '~user/ext/sqr.so '
sqr =: 3 : 0
res =. (#y)#4 NB. make sure it's integer
ret =. (sqrdll, 'sqr > i i *i *i') cd (#y);y;res
ret, res
)
Up until j806 I would get:
sqr i.10
285 0 1 4 9 16 25 36 49 64 81
But in j807:
sqr i.10
285 4 4 4 4 4 4 4 4 4 4
So my DLL 'reads' an array alright, but seems to be not 'writing' it.
For completeness:
JVERSION
Engine: j807/j64/linux
Release: commercial/2018-10-04T15:00:41
Library: 8.07.20
Qt IDE: 1.7.7/5.5.1
Platform: Linux 64
Installer: J807 install
InstallPath: /home/ben/j64-807
Contact: www.jsoftware.com
Perhaps I'm overlooking something trivial; any help is highly appreciated!
Ben
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
---
This email has been checked for viruses by AVG.
https://www.avg.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm