Uploaded image for project: ' Swift for TensorFlow'
  1. Swift for TensorFlow
  2. TF-342

[Python] Adopt Python iterator C API

    XMLWordPrintable

    Details

      Description

      Reproducer:

      import Python
      let dict: PythonObject = ["foo": [0], "bar": [1, 2, 3]]
      for x in dict {
          print(x)
      }
      
      Fatal error: Could not access PythonObject element corresponding to the specified key values: [0]: file /usr/local/src/swift-build/swift/stdlib/public/Python/Python.swift, line 563
      Stack dump:
      0.	Program arguments: /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.2.xctoolchain/usr/bin/swift -frontend -interpret dict.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name dict
      [1]    42904 illegal hardware instruction  swift dict.swift
      

      The reason for the crash is that for-in iteration for PythonObject is enabled via a MutableCollection conformance and is based on index-iteration. Instead, iteration should use the Python iterator protocol C API:

        Attachments

          Activity

            People

            Assignee:
            sendilkumarn Sendil Kumar
            Reporter:
            danzheng Dan Zheng
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: