Re: [tcljava-user] (no subject)
Brought to you by:
mdejong
From: Martin L. <mar...@gm...> - 2008-09-25 09:08:39
|
Hi Dan, the reason is, that you return an element from the just built list by pushing it into the interpreter. If the method is ending the list object is released and all its elements will be released, too. So the result list element won't be present anymore. In my eyes even a "list.preserve" call wouldn't solve the problem because it raises the question, when the list would be release again? I would say ... never! So I would duplicate the object I want to return! In C(++) I would do: *Tcl_Obj** pList = *Tcl_NewObj*(); // building the list *Tcl_Obj** pElement = NULL; *Tcl_ListObjIndex*(pInterp, pList, nIndex, &pElement); *Tcl_SetObjResult*(pInterp, *Tcl_DuplicateObj*(pElement)); By the way ... why do you build a tcl list to extract one element and to forget it? Why not using Java container objects, if container objects are really needed? Ok - I hope my suggestion helps. Best regards, Martin Lemburg Dan Diolosa wrote: > > Hi, > > > I am wondering why I need to "preserve" a TclList that I don't return > to TCL, nor need/use after the function returns. > > I am trying to return just one sub-list from a list of sub-lists. If > I have just a list of normal TclObjects I can return one item without > a problem. What is wrong with this: > > > > public void cmdProc(Interp interp, TclObject argv[]) throws TclException > > { > > TclObject list = TclList.newInstance(); > > > > //Create the first sublist > > TclObject list1 = TclList.newInstance(); > > TclList.append(interp, list1, TclString.newInstance("1.1")); > > TclList.append(interp, list1, TclString.newInstance("1.2")); > > > > //Create the second sublist > > TclObject list2 = TclList.newInstance(); > > TclList.append(interp, list2, TclString.newInstance("2.1")); > > TclList.append(interp, list2, TclString.newInstance("2.2")); > > > > //Add to main list > > TclList.append(interp, list, list1); > > TclList.append(interp, list1, list2); > > > > //list.preserve(); > > > > //return just the second sublist list > > interp.setResult(TclList.index(interp, list, 0)); > > } > > > > When I run it (without the preserve()), I get this: > > % ls_test > > alloc: invalid block: 009B3DF0: f8 0 0 > > > > This application has requested the Runtime to terminate it in an > unusual way. > > Please contact the application's support team for more information. > > D:\ > > > > > > When I run a similar situation in my production code I get the error > from JRE side, SIGSEGV on Linux and ACCESS_VIOLATION on Windows: > > > > # > > # An unexpected error has been detected by HotSpot Virtual Machine: > > # > > # SIGSEGV (0xb) at pc=0x4008eb78, pid=4098, tid=1074768448 > > # > > # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing) > > # Problematic frame: > > # C [libtcl8.4.so+0x77b78] > > # > > # An error report file with more information is saved as > hs_err_pid4098.log > > # > > # If you would like to submit a bug report, please visit: > > # http://java.sun.com/webapps/bugreport/crash.jsp > > # > > Aborted (core dumped) > > > Thanks, > > Dan > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > ------------------------------------------------------------------------ > > _______________________________________________ > tcljava-user mailing list > tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tcljava-user > -- ------------------------------------------------------------------------ Martin Lemburg Emdener Strasse 19A D-10551 Berlin Private: Phone: +49 30 39 03 72 05 Mobile: +49 179 395 40 95 Fax: +49 1805 40 02-26 86 05 Email: mar...@gm... <mailto:mar...@gm...> Office: Phone: +49 30 46 77 75-22 Fax: +49 30 46 77 75-11 Email: mar...@si... <mailto:mar...@si...> ------------------------------------------------------------------------ "We are all individualists!" "No, Im the only non-individualist!" (Monty Pythons "Life of Brian") ------------------------------------------------------------------------ |