This is not a good fix for the CSTRING conversion. The error messages will
always report that this is a problem with argument 1 if there is any sort
of error.

Rick
---------- Forwarded message ---------
From: erich_st--- via Oorexx-svn <oorexx-...@lists.sourceforge.net>
Date: Fri, Oct 4, 2019 at 2:00 PM
Subject: [Oorexx-svn] SF.net SVN: oorexx-code-0:[11923]
To: <oorexx-...@lists.sourceforge.net>
Cc: <erich...@users.sf.net>


Revision: 11923
          http://sourceforge.net/p/oorexx/code-0/11923
Author:   erich_st
Date:     2019-10-04 18:00:35 +0000 (Fri, 04 Oct 2019)
Log Message:
-----------
fix string conversion of CSTRING API argument type; also add more
RexxString and CSTRING API tests

Modified Paths:
--------------
    main/trunk/interpreter/execution/NativeActivation.cpp
    main/trunk/testbinaries/orxfunction.cpp
    test/trunk/ooRexx/API/oo/FUNCTION.testGroup
    test/trunk/ooRexx/API/oo/FUNCTIONPackage.cls
    test/trunk/ooRexx/API/oo/METHOD.testGroup

Modified: main/trunk/interpreter/execution/NativeActivation.cpp
===================================================================
--- main/trunk/interpreter/execution/NativeActivation.cpp       2019-10-03
16:26:20 UTC (rev 11922)
+++ main/trunk/interpreter/execution/NativeActivation.cpp       2019-10-04
18:00:35 UTC (rev 11923)
@@ -2015,7 +2015,7 @@
 {
     // force to a string value, making sure to protect the string
     // if a different object is returned.
-    RexxString *string = (RexxString *)object->stringValue();
+    RexxString *string = stringArgument(object, 1);
     if (string != object)
     {
         createLocalReference(string);

Modified: main/trunk/testbinaries/orxfunction.cpp
===================================================================
--- main/trunk/testbinaries/orxfunction.cpp     2019-10-03 16:26:20 UTC
(rev 11922)
+++ main/trunk/testbinaries/orxfunction.cpp     2019-10-04 18:00:35 UTC
(rev 11923)
@@ -307,6 +307,32 @@
     return arg1;
 }

+RexxRoutine1(CSTRING, TestOptionalCstringArg,
+             OPTIONAL_CSTRING, arg1)
+{
+    if (argumentOmitted(1))
+    {
+        return "OMITTED";
+    }
+    return arg1;
+}
+
+RexxRoutine1(RexxStringObject, TestStringArg,
+            RexxStringObject, arg1)
+{
+    return arg1;
+}
+
+RexxRoutine1(RexxStringObject, TestOptionalStringArg,
+             OPTIONAL_RexxStringObject, arg1)
+{
+    if (argumentOmitted(1))
+    {
+        return context->String("OMITTED");
+    }
+    return arg1;
+}
+
 RexxRoutine0(POINTER,                   // Return type
            TestPointerValue)            // Function routine name
 {
@@ -779,6 +805,9 @@
     REXX_TYPED_ROUTINE(TestFloatArg,          TestFloatArg),
     REXX_TYPED_ROUTINE(TestDoubleArg,         TestDoubleArg),
     REXX_TYPED_ROUTINE(TestCstringArg,        TestCstringArg),
+    REXX_TYPED_ROUTINE(TestOptionalCstringArg, TestOptionalCstringArg),
+    REXX_TYPED_ROUTINE(TestStringArg,         TestStringArg),
+    REXX_TYPED_ROUTINE(TestOptionalStringArg, TestOptionalStringArg),
     REXX_TYPED_ROUTINE(TestPointerValue,      TestPointerValue),
     REXX_TYPED_ROUTINE(TestPointerArg,        TestPointerArg),
     REXX_TYPED_ROUTINE(TestNullPointerValue,  TestNullPointerValue),

Modified: test/trunk/ooRexx/API/oo/FUNCTION.testGroup
===================================================================
--- test/trunk/ooRexx/API/oo/FUNCTION.testGroup 2019-10-03 16:26:20 UTC
(rev 11922)
+++ test/trunk/ooRexx/API/oo/FUNCTION.testGroup 2019-10-04 18:00:35 UTC
(rev 11923)
@@ -738,6 +738,78 @@
   val = copies('AbCdEfGhIjKlMnOpQrStUvWxYz0123456789', 1000)
   self~assertSame(val, TestCstringArg(val))

+::method test_OptionalCSTRING
+  self~assertSame("OMITTED", TestOptionalCStringArg())
+
+-- .nil doesn't honour request("string")
+::method test_CSTRING_nil
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  call TestCstringArg .nil
+
+-- an object with neither a string nor a makeString method
+::method test_CSTRING_no_string_no_makestring
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  call TestOptionalCstringArg .NoString_NoMakestring~new
+
+-- an object with a string but no makeString method
+::method test_CSTRING_string_no_makestring
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  call TestCstringArg .String_NoMakestring~new
+
+-- all classes with a makeString method should work
+::method test_CSTRING_makeString
+  self~assertSame("makeString", TestCstringArg(.NoString_Makestring~new))
+  self~assertSame("makeString",
TestOptionalCstringArg(.String_Makestring~new))
+  self~assertSame("123", TestCstringArg(.Array~of(123)))
+  self~assertSame("123", TestCstringArg(.CircularQueue~of(123)))
+  self~assertSame("123", TestOptionalCstringArg(.MutableBuffer~new(123)))
+
+-- any '00'x in a CSTRING will terminate the CSTRING
+::method test_CSTRING_no_hex00
+  self~assertSame("", TestCstringArg('00'x))
+  self~assertSame("", TestOptionalCstringArg(xrange('00'x, 'ff'x)))
+  self~assertSame(xrange('80'x, 'ff'x), TestCstringArg(xrange('80'x,
'7f'x)))
+
+
+-- test StringObject
+
+::method test_RexxString
+  self~assertSame("", TestOptionalCStringArg(""))
+  self~assertSame(123, TestOptionalCStringArg(123))
+
+::method test_OptionalRexxString
+  self~assertSame("OMITTED", TestOptionalCStringArg())
+
+-- .nil doesn't honour request("string")
+::method test_RexxString_nil
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  call TestStringArg .nil
+
+-- an object with neither a string nor a makeString method
+::method test_RexxString_no_string_no_makestring
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  call TestOptionalStringArg .NoString_NoMakestring~new
+
+-- an object with a string but no makeString method
+::method test_RexxString_string_no_makestring
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  call TestStringArg .String_NoMakestring~new
+
+-- all classes with a makeString method should work
+::method test_RexxString_makeString
+  self~assertSame("makeString", TestStringArg(.NoString_Makestring~new))
+  self~assertSame("makeString",
TestOptionalStringArg(.String_Makestring~new))
+  self~assertSame("123", TestStringArg(.Array~of(123)))
+  self~assertSame("123", TestStringArg(.CircularQueue~of(123)))
+  self~assertSame("123", TestOptionalStringArg(.MutableBuffer~new(123)))
+
+-- RexxString must be able to handle embedded '00'x characters
+::method test_RexxString_hex00
+  self~assertSame('00'x, TestStringArg('00'x))
+  self~assertSame(xrange('00'x, 'ff'x),
TestOptionalStringArg(xrange('00'x, 'ff'x)))
+  self~assertSame(xrange('80'x, '7f'x), TestStringArg(xrange('80'x,
'7f'x)))
+
+
 -- test POINTER
 ::method 'test046'
   val = TestPointerValue()
@@ -1771,5 +1843,21 @@

   return lines

+::class NoString_NoMakeString

+::class String_NoMakeString
+::method string
+  return "string"
+
+::class NoString_MakeString
+::method makeString
+  return "makeString"
+
+::class String_MakeString
+::method string
+  return "string"
+::method makeString
+  return "makeString"
+
+
 ::options novalue error

Modified: test/trunk/ooRexx/API/oo/FUNCTIONPackage.cls
===================================================================
--- test/trunk/ooRexx/API/oo/FUNCTIONPackage.cls        2019-10-03 16:26:20
UTC (rev 11922)
+++ test/trunk/ooRexx/API/oo/FUNCTIONPackage.cls        2019-10-04 18:00:35
UTC (rev 11923)
@@ -1,6 +1,6 @@
 
/*----------------------------------------------------------------------------*/
 /*
    */
-/* Copyright (c) 2008-2018 Rexx Language Association. All rights
reserved.    */
+/* Copyright (c) 2008-2019 Rexx Language Association. All rights
reserved.    */
 /*
    */
 /* This program and the accompanying materials are made available under
   */
 /* the terms of the Common Public License v1.0 which accompanies this
   */
@@ -69,6 +69,9 @@
 ::routine TestFloatArg PUBLIC EXTERNAL "LIBRARY orxfunction TestFloatArg"
 ::routine TestDoubleArg PUBLIC EXTERNAL "LIBRARY orxfunction TestDoubleArg"
 ::routine TestCstringArg PUBLIC EXTERNAL "LIBRARY orxfunction
TestCstringArg"
+::routine TestOptionalCstringArg PUBLIC EXTERNAL "LIBRARY orxfunction"
+::routine TestStringArg          PUBLIC EXTERNAL "LIBRARY orxfunction"
+::routine TestOptionalStringArg  PUBLIC EXTERNAL "LIBRARY orxfunction"
 ::routine TestPointerValue PUBLIC EXTERNAL "LIBRARY orxfunction
TestPointerValue"
 ::routine TestPointerArg PUBLIC EXTERNAL "LIBRARY orxfunction
TestPointerArg"
 ::routine TestNullPointerValue PUBLIC EXTERNAL "LIBRARY orxfunction
TestNullPointerValue"

Modified: test/trunk/ooRexx/API/oo/METHOD.testGroup
===================================================================
--- test/trunk/ooRexx/API/oo/METHOD.testGroup   2019-10-03 16:26:20 UTC
(rev 11922)
+++ test/trunk/ooRexx/API/oo/METHOD.testGroup   2019-10-04 18:00:35 UTC
(rev 11923)
@@ -883,6 +883,41 @@
   self~expectSyntax('91.999')
   x = tester~TestOptionalCStringArg()

+-- .nil doesn't honour request("string")
+::method test_CSTRING_nil
+  tester = .METHODtester~new
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  tester~TestCstringArg(.nil)
+
+-- an object with neither a string nor a makeString method
+::method test_CSTRING_no_string_no_makestring
+  tester = .METHODtester~new
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  tester~TestOptionalCstringArg(.NoString_NoMakestring~new)
+
+-- an object with a string but no makeString method
+::method test_CSTRING_string_no_makestring
+  tester = .METHODtester~new
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  tester~TestCstringArg(.String_NoMakestring~new)
+
+-- all classes with a makeString method should work
+::method test_CSTRING_makeString
+  tester = .METHODtester~new
+  self~assertSame("makeString",
tester~TestCstringArg(.NoString_Makestring~new))
+  self~assertSame("makeString",
tester~TestOptionalCstringArg(.String_Makestring~new))
+  self~assertSame("123", tester~TestCstringArg(.Array~of(123)))
+  self~assertSame("123", tester~TestCstringArg(.CircularQueue~of(123)))
+  self~assertSame("123",
tester~TestOptionalCstringArg(.MutableBuffer~new(123)))
+
+-- any '00'x in a CSTRING will terminate the CSTRING
+::method test_CSTRING_no_hex00
+  tester = .METHODtester~new
+  self~assertSame("", tester~TestCstringArg('00'x))
+  self~assertSame("", tester~TestOptionalCstringArg(xrange('00'x, 'ff'x)))
+  self~assertSame(xrange('80'x, 'ff'x),
tester~TestCstringArg(xrange('80'x, '7f'x)))
+
+
 -- test POINTER
 ::method 'test046'
   tester = .METHODtester~new
@@ -975,6 +1010,36 @@
   self~expectSyntax('93.938')
   x = tester~TestOptionalStringArg(.nil)

+
+-- an object with neither a string nor a makeString method
+::method test_RexxString_no_string_no_makestring
+  tester = .METHODtester~new
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  tester~TestOptionalStringArg(.NoString_NoMakestring~new)
+
+-- an object with a string but no makeString method
+::method test_RexxString_string_no_makestring
+  tester = .METHODtester~new
+  self~expectSyntax('93.938') -- Method argument 1 must have a string value
+  tester~TestStringArg(.String_NoMakestring~new)
+
+-- all classes with a makeString method should work
+::method test_RexxString_makeString
+  tester = .METHODtester~new
+  self~assertSame("makeString",
tester~TestStringArg(.NoString_Makestring~new))
+  self~assertSame("makeString",
tester~TestOptionalStringArg(.String_Makestring~new))
+  self~assertSame("123", tester~TestStringArg(.Array~of(123)))
+  self~assertSame("123", tester~TestStringArg(.CircularQueue~of(123)))
+  self~assertSame("123",
tester~TestOptionalStringArg(.MutableBuffer~new(123)))
+
+-- RexxString must be able to handle embedded '00'x characters
+::method test_RexxString_hex00
+  tester = .METHODtester~new
+  self~assertSame('00'x, tester~TestStringArg('00'x))
+  self~assertSame(xrange('00'x, 'ff'x),
tester~TestOptionalStringArg(xrange('00'x, 'ff'x)))
+  self~assertSame(xrange('80'x, '7f'x), tester~TestStringArg(xrange('80'x,
'7f'x)))
+
+
 -- test RexxArrayObject
 ::method 'testArray01'
   tester = .METHODtester~new
@@ -3040,5 +3105,21 @@
   use strict arg one, two, three
   return "S3" one two three

+::class NoString_NoMakeString

+::class String_NoMakeString
+::method string
+  return "string"
+
+::class NoString_MakeString
+::method makeString
+  return "makeString"
+
+::class String_MakeString
+::method string
+  return "string"
+::method makeString
+  return "makeString"
+
+
 ::options novalue error



_______________________________________________
Oorexx-svn mailing list
oorexx-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-svn
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to