[Oorexx-devel] Another observation (Re: Problem with SysStemSort, but ...

2009-05-25 Thread Rony G. Flatscher
Rick,

when invoking that program via Java, then it works without a problem!

If invoked via Java then in the native layer an AttachThread() is
invoked, a Routine object is created and invoked with CallRoutine(),
followed by a matching DetachThread().

---rony



Rony G. Flatscher wrote:
 Rick McGuire wrote:
 I just thought of one more thing that could cause the error you're
 seeing.  If you do an AttachThread() at some point and neglect to do a
 corresponding DetachThread() before returning to your caller, you'll
 end up with a corrupted activaation stack that will result in problems
 with legacy callback APIs like RexxVariablePool or RexxStemSort.
 What;s showing up in this traceback very much appears to match what
 might happen in that sort of situation.
   

 In this particular program an external function BSF(), defined as

 RexxRoutine1(RexxObjectPtr, BSF, ARGLIST, argArray) {...}
   

 gets invoked to communicate to the Java side. There are no calls from
 Java into BSF4Rexx occurring, hence there AttachThread() and
 DetachThread() are not invoked in this case (at least not from BSF4Rexx).

 Also, BSF4Rexx in this case does not excercise any variable gets or
 sets. It just interacts with Java and returns a (string) value back,
 which gets stored in the stem.

 ---rony

 P.S.: Just for completeness, here is the Rexx program in question:

 /* classic Rexx version, ---rgf, 2003-02, 2003-05-10, 2003-09-04, 
 2005-12-28 */

 /* this version works on Java 1.1 too (because using wrapEnumeration()) 
 */

   /* load the BSF4Rexx functions and start a JVM, if necessary */
 if rxFuncQuery(BSF) = 1 then   /* BSF() support not loaded yet ? */
 do
call rxFuncAdd BsfLoadFuncs, BSF4Rexx, BsfLoadFuncs
call BsfLoadFuncs  /* load all BSF*() functions  */
call BsfLoadJava   /* load Java  */
 end

/* 'Class.class' is pre-registered for Rexx, cf. docs */
 system=bsf('invoke', 'Class.class', 'forName', 'java.lang.System')

 properties=bsf('invoke', system, getProperties)  /* get the System 
 properties  */

 enum=bsf('invoke', properties, 'propertyNames')/* get an enumeration 
 of the property names */

/* wrap the Enumeration object, so Java 1.1 can handle this too 
 (overcome Java inner class access restriction) */
/* the following statement is *not* necessary for Java = 1.2 */
 enum=bsf('wrapEnumeration', enum)

 say copies(=, 70)

 stem. = 0
 deli  = 010203x
 do i=1 to 5000 while bsf('invoke', enum, 'hasMoreElements') /* loop over 
 enumeration   */
key=bsf('invoke', enum, 'nextElement')
stem.i= key || deli || bsf('invoke', properties, 'getProperty', key)
stem.0=i   /* remember total of elements */
 end

 say stem.0 elements, now sorting...
 call sysStemSort stem.

 l=length(stem.0)
 do i=1 to stem.0
parse var stem.i key (deli) val
say i~right(l): pp(key)~left(31)=pp(val)
 end

 exit

 pp: procedure
return [ || arg(1) || ]
 


--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA,  Big Spaceship. http://www.creativitycat.com ___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel


Re: [Oorexx-devel] Another observation (Re: Problem with SysStemSort, but ...

2009-05-25 Thread Rony G. Flatscher

Rick McGuire wrote:
 The other possibility is you've called RexxCreateInterpreter() on a
 thread that was already owned by Rexx.  In that case, the
 RexxThreadContext returned with the instance pushes down the active
 one and can create the same symptoms if you return without destroying
 the instance.  In that situation, you should either create the
 instance on a separate thread or just inherit the instance of the
 program that called you in the first place.
   
In the scenario that rexx.exe is used to run the program (which then
fails), no RexxCreateInterpreter() is carried out by BSF4Rexx.

---rony

 On Mon, May 25, 2009 at 5:08 AM, Rony G. Flatscher
 rony.flatsc...@wu-wien.ac.at wrote:
   
 Rick,

 when invoking that program via Java, then it works without a problem!

 If invoked via Java then in the native layer an AttachThread() is invoked, a
 Routine object is created and invoked with CallRoutine(), followed by a
 matching DetachThread().

 ---rony



 Rony G. Flatscher wrote:

 Rick McGuire wrote:

 I just thought of one more thing that could cause the error you're
 seeing.  If you do an AttachThread() at some point and neglect to do a
 corresponding DetachThread() before returning to your caller, you'll
 end up with a corrupted activaation stack that will result in problems
 with legacy callback APIs like RexxVariablePool or RexxStemSort.
 What;s showing up in this traceback very much appears to match what
 might happen in that sort of situation.


 In this particular program an external function BSF(), defined as

 RexxRoutine1(RexxObjectPtr, BSF, ARGLIST, argArray) {...}


 gets invoked to communicate to the Java side. There are no calls from Java
 into BSF4Rexx occurring, hence there AttachThread() and DetachThread() are
 not invoked in this case (at least not from BSF4Rexx).

 Also, BSF4Rexx in this case does not excercise any variable gets or sets. It
 just interacts with Java and returns a (string) value back, which gets
 stored in the stem.

 ---rony

 P.S.: Just for completeness, here is the Rexx program in question:

 /* classic Rexx version, ---rgf, 2003-02, 2003-05-10, 2003-09-04, 2005-12-28
 */

 /* this version works on Java 1.1 too (because using wrapEnumeration()) */

   /* load the BSF4Rexx functions and start a JVM, if necessary */
 if rxFuncQuery(BSF) = 1 then   /* BSF() support not loaded yet ? */
 do
call rxFuncAdd BsfLoadFuncs, BSF4Rexx, BsfLoadFuncs
call BsfLoadFuncs  /* load all BSF*() functions  */
call BsfLoadJava   /* load Java  */
 end

/* 'Class.class' is pre-registered for Rexx, cf. docs */
 system=bsf('invoke', 'Class.class', 'forName', 'java.lang.System')

 properties=bsf('invoke', system, getProperties)  /* get the System
 properties  */

 enum=bsf('invoke', properties, 'propertyNames')/* get an enumeration of
 the property names */

/* wrap the Enumeration object, so Java 1.1 can handle this too (overcome
 Java inner class access restriction) */
/* the following statement is *not* necessary for Java = 1.2 */
 enum=bsf('wrapEnumeration', enum)

 say copies(=, 70)

 stem. = 0
 deli  = 010203x
 do i=1 to 5000 while bsf('invoke', enum, 'hasMoreElements') /* loop over
 enumeration   */
key=bsf('invoke', enum, 'nextElement')
stem.i= key || deli || bsf('invoke', properties, 'getProperty', key)
stem.0=i   /* remember total of elements */
 end

 say stem.0 elements, now sorting...
 call sysStemSort stem.

 l=length(stem.0)
 do i=1 to stem.0
parse var stem.i key (deli) val
say i~right(l): pp(key)~left(31)=pp(val)
 end

 exit

 pp: procedure
return [ || arg(1) || ]


 


--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA,  Big Spaceship. http://www.creativitycat.com 
___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel