Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1796: Nativelib toCString() & fromCString() now return nulls. #1945

Conversation

LeeTibbert
Copy link
Contributor

In the sweat of thy face shalt thou eat bread, till thou return unto
the ground; for out of it wast thou taken: for null thou art, and
unto null shalt thou return. [1]

  • This PR was motivated by Issue fromCString(null) returns java.lang.RuntimeException not NullPointerException #1796. There is extensive discussion
    of design alternatives in that Issue. This PR implements the
    final decision; toCString() & fromCString are to
    return null when given a null.

  • Two test cases for exercising null handling were added to
    were added to CStringSuite.scala.

    To isolate the changes of this PR, I left CStringSuite.scala
    as the old-style Scala Native test Suite it was before I touched
    it this time. If/when the core changes of this PR are found
    acceptable, I can sweep through and convert that file to JUnit,
    under the guidance of: You touch it, you own it.

Documentation:

  • The standard changelog entry is requested.

  • I added a one sentence paragraph to docs/user/interop.rst
    to make the newly defined behavior accessible to users of Scala Native.

    interop.rst had a number (7 or 8) warnings before I touched it.
    I left it with the same warnings. That is, I did not introduce
    any warning, but, to keep this PR reviewable on-sight, I did
    not fix any. I think I have a PR in the queue which fixes some
    of those warnings and others; yielding, at that time, a clean build.

Testing:

Safety -

  • Built and tested ("test-all") in debug mode using sbt 1.3.13 on
    X86_64 only . All tests pass.

Efficacy -

  • The two newly cases in CStringSuite.scala to exercise the changes
    of this both passed.

Documentation -

  • I did a successful manual html build of the doc directory.

[1]: Adapted from original

Copy link
Collaborator

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. There are several asInstanceOfs that are not necessary, I believe.

@LeeTibbert
Copy link
Contributor Author

@david-bouyssie, @jokade Does this PR provide what you were describing & needing to ease your work?
Did I capture the idea?

    ```
    In the sweat of thy face shalt thou eat bread, till thou return unto
    the ground; for out of it wast thou taken: for null thou art, and
    unto null shalt thou return."
    ``` [^1]

  * This PR was motivated by Issue scala-native#1796.  There is extensive discussion
    of design alternatives in that Issue. This PR implements the
    final decision; toCString() & fromCString are to
    return null when given a null.

  * Two test cases for exercising null handling were added to
    were added to CStringSuite.scala.

    To isolate the changes of this PR, I left CStringSuite.scala
    as the old-style Scala Native test Suite it was before I touched
    it this time.  If/when the core changes of this PR are found
    acceptable, I can sweep through and convert that file to JUnit,
    under the guidance of: You touch it, you own it.

Documentation:

  * The standard changelog entry is requested.

  * I added a one sentence paragraph to `docs/user/interop.rst`
    to make the newly defined behavior accessible to users of Scala Native.

    `interop.rst` had a number (7 or 8) warnings before I touched it.
    I left it with the same warnings.  That is, I did not introduce
    any warning, but, to keep this PR reviewable on-sight, I did
    not fix any.  I think I have a PR in the queue which fixes some
    of those warnings and others; yielding, at that time, a clean build.

Testing:

  Safety -

    + Built and tested ("test-all") in debug mode using sbt 1.3.13 on
      X86_64 only . All tests pass.

  Efficacy -

    + The two newly cases in CStringSuite.scala to exercise the changes
      of this both passed.

  Documentation -
    + I did a successful manual html build of the `doc` directory.

[^1]: Modified from
    [original](https://www.phrases.org.uk/meanings/ashes-to-ashes.html)

Travis CI restarts:

  1) All but one runs completed green. The one which failed did so
     with a Coursier fetch error, apparently unrelated to this PR.
     Restarting.
@LeeTibbert LeeTibbert force-pushed the PR_nativelib_CStringNulls_I1796_2020-10-13T0942-0400 branch from 957151c to 1a11b7a Compare October 13, 2020 20:02
Copy link
Member

@ekrich ekrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now.

@LeeTibbert LeeTibbert force-pushed the PR_nativelib_CStringNulls_I1796_2020-10-13T0942-0400 branch from 370c749 to bb7e5fa Compare October 13, 2020 23:46
Travis CI restart #2. Failed Travis job (scalafmt, but not in scalafmt)
unrelated to the PR, just after "store build cache".

Travis CI restart scala-native#3. Two failed jobs unrelated to this PR.
One was a failed CLA check. Second was a failed Coursier fetch.
@LeeTibbert LeeTibbert force-pushed the PR_nativelib_CStringNulls_I1796_2020-10-13T0942-0400 branch from bb7e5fa to 6a8b3b7 Compare October 14, 2020 04:38
@sjrd sjrd changed the title Fix 1796: Nativelib toCString() & fromCString() now return nulls. Fix #1796: Nativelib toCString() & fromCString() now return nulls. Oct 14, 2020
@sjrd sjrd merged commit 064d434 into scala-native:master Oct 14, 2020
1 check passed
LeeTibbert added a commit to LeeTibbert/scala-native-fork that referenced this pull request Oct 14, 2020
  * PR scala-native#1945 added two cases to unsafe.CStringSuite.scala. To aid
    review of scala-native#1945, I did not convert CStringSuite from the
    classical Scala Native test format to JUnit. Rather, I left
    an IOU in the commit message for scala-native#1945.  This PR pays off
    that IOU.

  * There should be no functional changes. A trial testOnly of
    CSuiteTest.scala reveals no changes beyond changed test names
    and JUnit style output.

  * It looks as though the CStringSuite tests had been written at
    different times, with slightly different assert styles. I am
    supposing that the later authors did not want to alter existing,
    working tests, again to minimize and isolate changes.

    I changed some of the asserts to use a consistent "expected, result"
    format. This is the convention documented by JUnit and some/most of the
    existing tests.  Future readers will expect that a JUnit test
    follow the JUnit convention.

Documentation:

  * As a number of tests are changing to JUnit the Release Notes will
    need a blanket statement saying "Many tests changed to JUnit.".
    This test would be covered by that statement.

Testing:

  Safety -

  + Built and tested ("test-all") in debug mode using sbt 1.3.13 on
    X86_64 only . All tests pass.

  Efficacy -

  + JUnit style output is evident upon execution.
LeeTibbert added a commit to LeeTibbert/scala-native-fork that referenced this pull request Oct 14, 2020
  * PR scala-native#1945 added two cases to unsafe.CStringSuite.scala. To aid
    review of scala-native#1945, I did not convert CStringSuite from the
    classical Scala Native test format to JUnit. Rather, I left
    an IOU in the commit message for scala-native#1945.  This PR pays off
    that IOU.

  * There should be no functional changes. A trial testOnly of
    CSuiteTest.scala reveals no changes beyond changed test names
    and JUnit style output.

  * It looks as though the CStringSuite tests had been written at
    different times, with slightly different assert styles. I am
    supposing that the later authors did not want to alter existing,
    working tests, again to minimize and isolate changes.

    I changed some of the asserts to use a consistent "expected, result"
    format. This is the convention documented by JUnit and some/most of the
    existing tests.  Future readers will expect that a JUnit test
    follow the JUnit convention.

Documentation:

  * As a number of tests are changing to JUnit the Release Notes will
    need a blanket statement saying "Many tests changed to JUnit.".
    This test would be covered by that statement.

Testing:

  Safety -

  + Built and tested ("test-all") in debug mode using sbt 1.3.13 on
    X86_64 only . All tests pass.

  Efficacy -

  + JUnit style output is evident upon execution.

Travis CI restarts:

1) Failures unrelated the changes of this PR: One CLA failure,
   two Coursier. Looks like Travis's network is having a bad hair day.
   All the other cases are successful/green.
vicopem pushed a commit to vicopem/scala-native that referenced this pull request Nov 19, 2020
vicopem added a commit to vicopem/scala-native that referenced this pull request Nov 19, 2020
vicopem added a commit to vicopem/scala-native that referenced this pull request Nov 19, 2020
ekrich pushed a commit to ekrich/scala-native that referenced this pull request May 21, 2021
WojciechMazur pushed a commit to WojciechMazur/scala-native that referenced this pull request Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants