Accessing the symbol table is deprecated. Don't do it.  It should never have been allowed.

The J symbol table is a contiguous array of structures that connect names and values.  When the table fills, a larger one is allocated and the symbols are all relocated.  The table may become full any time a new symbol is created.

Thus, your very first line

s=. symget <y

is not robust.  symget will return a pointer (as an integer), but the assignment to s may relocate the symbol table, which means that your pointer may be invalid before you even store it into s.

There is no way around this, and the problem applies to all releases of JE.

If that's not bad enough, a routine you call, or a J task running in a thread, may delete any global name and leave you with an invalid pointer.

WHAT YOU NEED TO DO is use 15!:14 if you want the address of the first atom, or 15!:12 (new in J9.04) to get the address of the header.  The header and data will not be relocated.

Henry Rich

On 3/31/2022 11:35 AM, [email protected] wrote:
I am working on a binding for a dll which requires a bit of mema / memr / memw, 
and this brought me to looking at symget / symset / symdat

With minor tweeking, I updated to 64bits the viewnoun verb from the "Guides/Named 
Noun Internals" page (running J903):



NB. 64 bit version

viewnoun=: 3 : 0

s=. symget <y NB. pointer to symbol table entry

sys=. memr s,0 2 4 NB. pointers to name, header

h=. 1{sys NB. header pointer

fheader=. memr h,0 7 4 NB. fixed header

NB. 'offset flag size type refcount len rank'=. fheader

'offset flag size type refcount len rank'=. fheader

      rank =. 2 NB. hard coded patch !!!

shape=. memr h,56,rank,4 NB. shape

data=. memr (h+offset),0,len,type

sys;fheader;shape;data

)



   abc=:10+ i. 2 3

viewnoun 'abc'

┌─────────────────────────────┬─────────────────────┬───┬─────────────────┐

│94112853474752 94112853484736│72 0 1 4 1 6 37355522│2 3│10 11 12 13 14 15│

└─────────────────────────────┴─────────────────────┴───┴─────────────────┘


Something has clearly changed in the data organization.

* where has the rank info gone to? why do I get 37355522 instead?

* does "reserved size for data" still exist? does the 1 actually mean anything 
or is it just a placeholder?





----------------------------------------------------------------------
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

Reply via email to