www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - AAs

reply John Demme <me teqdruid.com> writes:
I don't understand how Associative Arrays work.  I'm getting a segfault
on a line that puts a new entry in an AA.  Here's the stacktrace:



com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getLinkedChildrenOf(com.neura
nexus.nnnode.INode, com.neuralnexus.nnnode.INode) ()

com.neuralnexus.client.ConnectorNode.getAttribute(com.neuralnexus.nnnode.INode)
()

com.neuralnexus.client.ConnectorNode.getFirstAttribute(com.neura
nexus.nnnode.INode) ()

com.neuralnexus.client.ConnectorNode.getFirstAttributeString(com.neura
nexus.nnnode.INode) ()



com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getNodeStruct(mango.xml.rpc.obj
cts.MethodResponse) ()



com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getNodeStruct(mango.xml.rpc.obj
cts.MethodResponse) ()

com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getRelationships(com.neura
nexus.nnnode.INode) ()

com.neuralnexus.client.ConnectorNode.getRelationships() ()



Obviously, it's my own code that's segfaulting, but I don't understand
why all these functions are being run.  The line that puts the new entry

toHash, opEquals, and opCmp.

Can someone explain this stack trace?

Thanks
John Demme
Apr 26 2005
next sibling parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"John Demme" <me teqdruid.com> wrote in message 
news:1114572104.9518.9.camel localhost.localdomain...
I don't understand how Associative Arrays work.  I'm getting a segfault
 on a line that puts a new entry in an AA.  Here's the stacktrace:



 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getLinkedChildrenOf(com.neura
nexus.nnnode.INode, 
 com.neuralnexus.nnnode.INode) ()

 com.neuralnexus.client.ConnectorNode.getAttribute(com.neura
nexus.nnnode.INode) 
 ()

 com.neuralnexus.client.ConnectorNode.getFirstAttribute(com.neura
nexus.nnnode.INode) 
 ()

 com.neuralnexus.client.ConnectorNode.getFirstAttributeString(com.neura
nexus.nnnode.INode) 
 ()



 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getNodeStruct(mango.xml.rpc.obj
cts.MethodResponse) 
 ()



 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getNodeStruct(mango.xml.rpc.obj
cts.MethodResponse) 
 ()

 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getRelationships(com.neura
nexus.nnnode.INode) 
 ()

 com.neuralnexus.client.ConnectorNode.getRelationships() ()



 Obviously, it's my own code that's segfaulting, but I don't understand
 why all these functions are being run.  The line that puts the new entry

 toHash, opEquals, and opCmp.

 Can someone explain this stack trace?

 Thanks
 John Demme
Is the key type an interface? I notice the inputs to getLinkedChildrenOf are INode which looks like interfaces. The ti_C.TypeInfo_C.compare is the comparison function for Object references. So it looks like the interface reference is being cast to void* and then to Object* and jumping to a random routine where Object.opCmp would be. That's just a guess. More information like a code example or dmd version info would help.
Apr 27 2005
parent reply John Demme <me teqdruid.com> writes:
Sorry.  Forgot the usual stuff.  This is DMD .120 on Linux.  Both the
key and the values are, in fact, interfaces.  Below is the code for the
INode interface:
public interface INode
{
	public INode createChild();
	public void makeChild(INode child);
	public UText getFirstAttributeString(INode attributeType);
	public void addAttribute(INode attributeType, UText string);
	public void setAttribute(INode attributeType, UText string);
	public INode getFirstAttribute(INode attributeType);
	public INode[] getAttribute(INode attributeType);
	public NNNodeID getID();
	public INode[] getImmediateChildren();
	public INode[] getImmediateParents();
	public INode[] getRelatedNodes();
	public void setData(NNNodeData data);
	public bool isChildOf(INode searchParent);
	public NNNodeData getData();
	public INode[INode] getRelationships();
	
	public int opEquals(Object o);
	public int opCmp(Object o);
	public uint toHash();
}

I have a Class called ConnectorNode which implements this INode.  Here's
the code that does the AA stuff (my debug version)
	protected INode[INode] getNodeStruct(MethodResponse mr) {
		Value[] params = mr.getParams();
		assert(params.length == 1);
		assert(params[0].getValueType() == ValueType.Struct);
		Struct s = params[0].getStruct();
		INode[INode] table;
		foreach (UText key, Value value; s.getValues()) {
			NNNodeID kid = new nnNodeID(key);
			writefln("a");
			ConnectorNode kn = new ConnectorNode(kid, this);
			writefln("b");
			ConnectorNode vn = new ConnectorNode(new NNNodeID(value.getString()),
this);
			writefln("c");
			INode kin = kn;
			writefln("d");
			INode vin = vn;
			writefln("e");
			table[kin] = vin;
			writefln("f");
		}
		return table;
	}

Any ideas?

Thanks
John Demme

On Wed, 2005-04-27 at 08:50 -0400, Ben Hinkle wrote:
 "John Demme" <me teqdruid.com> wrote in message 
 news:1114572104.9518.9.camel localhost.localdomain...
I don't understand how Associative Arrays work.  I'm getting a segfault
 on a line that puts a new entry in an AA.  Here's the stacktrace:



 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getLinkedChildrenOf(com.neura
nexus.nnnode.INode, 
 com.neuralnexus.nnnode.INode) ()

 com.neuralnexus.client.ConnectorNode.getAttribute(com.neura
nexus.nnnode.INode) 
 ()

 com.neuralnexus.client.ConnectorNode.getFirstAttribute(com.neura
nexus.nnnode.INode) 
 ()

 com.neuralnexus.client.ConnectorNode.getFirstAttributeString(com.neura
nexus.nnnode.INode) 
 ()



 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getNodeStruct(mango.xml.rpc.obj
cts.MethodResponse) 
 ()



 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getNodeStruct(mango.xml.rpc.obj
cts.MethodResponse) 
 ()

 com.neuralnexus.xmlrpc.connector.XmlRpcConnector.getRelationships(com.neura
nexus.nnnode.INode) 
 ()

 com.neuralnexus.client.ConnectorNode.getRelationships() ()



 Obviously, it's my own code that's segfaulting, but I don't understand
 why all these functions are being run.  The line that puts the new entry

 toHash, opEquals, and opCmp.

 Can someone explain this stack trace?

 Thanks
 John Demme
Is the key type an interface? I notice the inputs to getLinkedChildrenOf are INode which looks like interfaces. The ti_C.TypeInfo_C.compare is the comparison function for Object references. So it looks like the interface reference is being cast to void* and then to Object* and jumping to a random routine where Object.opCmp would be. That's just a guess. More information like a code example or dmd version info would help.
Apr 27 2005
parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"John Demme" <me teqdruid.com> wrote in message 
news:1114624472.31952.3.camel localhost.localdomain...
 Sorry.  Forgot the usual stuff.  This is DMD .120 on Linux.  Both the
 key and the values are, in fact, interfaces.  Below is the code for the
 INode interface:
[snip]
 Any ideas?
nothing jumps out. I tried using an interface key in an AA on Windows dmd121 and it worked ok.
Apr 27 2005
prev sibling parent Ant <Ant_member pathlink.com> writes:
In article <1114572104.9518.9.camel localhost.localdomain>, John Demme says...
I don't understand how Associative Arrays work.  I'm getting a segfault
on a line that puts a new entry in an AA.  Here's the stacktrace:
Is this windows? did you try running it on linux? Ant
Apr 27 2005