Uploaded image for project: 'Swift'
  1. Swift
  2. SR-2773

function abnormally releasing instance.

    XMLWordPrintable

    Details

      Description

      See: https://gist.github.com/erica/1bb492d616370c5e8ae3383b140c41b4

      import Foundation
      public func with<T: AnyObject>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
          var this = item
          try update(&this)
          var ptr: Unmanaged<T>? = Unmanaged<T>.passRetained(this).autorelease(); defer { ptr = nil }
          return this
      }
      
      let p = Process()
      let task3 = with(p) {
          $0.launchPath = "/usr/bin/mdfind"
          $0.arguments = ["kMDItemDisplayName == *.playground"]
          $0.standardOutput = pipe
      }
      
      let task4 = with(Process()) {
          $0.launchPath = "/usr/bin/mdfind"
          $0.arguments = ["kMDItemDisplayName == *.playground"]
          $0.standardOutput = pipe
      }
      print(task3)
      print(task4)
      

      If the silly `ptr` workaround is commented out, the second test (task4) fails. I've tested in Xcode and at the command line.

      % swiftc test.swift
      % ./test
      <NSConcreteTask: 0x7fb531c0b200>
      Segmentation fault
      % swift test.swift
      <NSConcreteTask: 0x7fad8b6cfbe0>
      0  swift                    0x000000010d0a7b6d PrintStackTraceSignalHandler(void*) + 45
      1  swift                    0x000000010d0a75b6 SignalHandler(int) + 470
      2  libsystem_platform.dylib 0x00007fffce81fbba _sigtramp + 26
      3  libsystem_platform.dylib 000000000000000000 _sigtramp + 830342240
      4  swift                    0x000000010a9821b8 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 456
      5  swift                    0x000000010a98774b llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 763
      6  swift                    0x000000010a4d3662 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 3234
      7  swift                    0x000000010a4be07e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23358
      8  swift                    0x000000010a4b6265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
      9  swift                    0x000000010a47382d main + 8685
      10 libdyld.dylib            0x00007fffce613255 start + 1
      11 libdyld.dylib            0x000000000000000c start + 832490936
      Stack dump:
      0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret test.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name test 
      Segmentation fault
      % 
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              erica erica sadun
              Votes:
              4 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: