I keep on trying to understand what goes on with the move semantics.

I am trying the following:
    
    
    import vs
    
    proc main =
      let c1 = source("2sec.mkv")    # OK
      discard c1.saveY4M("demo.y4m") # OK
      echo c1                        # OK
      `=destroy`(c1) # shows 'destroying VSMapObj'
      echo c1.handle.isNil # shows 'false'
      # shows 'destroying VSMapObj' again
    
    main()
    
    
    Run

It saves the video file and echos `c1`.

Then I try to manually destroy `c1`.

Bearing in mind that:
    
    
    type
      VSMapObj* = object
        handle*:ptr VSMap
    
    proc `=destroy`*(self: VSMapObj) =
      if not self.handle.isNil:
        echo "destroying VSMapObj"
        api.handle.freeMap(self.handle)
    
    
    Run

The output is:
    
    
    destroying VSMapObj
    VSMap: 1 item(s)
      (key: "clip", typ: ptvideonode, n: 1, idx: 0)
    
    destroying VSMapObj
    false
    destroying VSMapObj
    Traceback (most recent call last)
    /home/jose/src/nimlang/vs.nim/tests/ex08_mm1.nim(11) ex08_mm1
    /home/jose/src/nimlang/vs.nim/src/lib/libvsmap.nim(31) main
    /home/jose/src/nimlang/vs.nim/src/lib/libvsmap.nim(34) =destroy
    SIGSEGV: Illegal storage access. (Attempt to read from nil?)
    Error: execution of an external program failed: 
'/home/jose/src/nimlang/vs.nim/tests/ex08_mm1'
    
    
    Run

I would expect `c1.handle.isNil` being `nil`, wouldn't it?

The generated code is:
    
    
    var
      c1
      :tmpD
      :tmpD_1
      :tmpD_2
      :tmpD_3
      :tmpD_4
    try:
      c1 = source("2sec.mkv", none(int), none(int),
        :tmpD = none_1(string)
        :tmpD, none(int), none(int), none(int),
        :tmpD_1 = none_1(string)
        :tmpD_1, none(int), none(int), none(int),
        :tmpD_2 = none_1(string)
        :tmpD_2, none(int), none(int))
      discard saveY4M(c1, "demo.y4m")
      echo [
        :tmpD_3 = `$`(c1)
        :tmpD_3]
      `=destroy`(c1)
      echo [
        :tmpD_4 = `$`(isNil(c1.handle))
        :tmpD_4]
    finally:
      `=destroy`(:tmpD_4)
      `=destroy`(:tmpD_3)
      `=destroy_2`(:tmpD_2)
      `=destroy_2`(:tmpD_1)
      `=destroy_2`(:tmpD)
      `=destroy`(c1)
    
    
    Run

Reply via email to