Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
3 replies Latest Post - ‏2014-03-19T17:51:01Z by llandale
CWicker
CWicker
3 Posts
ACCEPTED ANSWER

Pinned topic Access Violation when retrieving link in object

‏2014-03-17T19:24:25Z |

I have a script that loops through the links in an object. Readers of this forum may remember me from last week. Now I am getting a EXCEPTION_ACCESS_VIOLATION error. The full DXL is below. The error states that line 95 is the culprit (for l in o ->). The script works well for the first module but then fails on some objects in the second module. After the failure I can rerun the script, it will pick up where it left off, but it will get this error again.

The script is designed to skip over links whose target module has already been through the script (stored in the completedList). I reviewed the output file and noticed that when I rerun after each failure the first line in the log shows a skipped object. Then no other skipped objects in the log. From what I understand I must be doing something 'right' the first time the script encounters a skip-able object, but I have left something in an untidy state the second time this condition is met.

The team here was a great help last time, any ideas for my latest fumbling?

 

/************************************
    TITLE:    Link Flip Out Only
    DATE:     17 MAR 14    
************************************/

Skip completeList = create  //List of Modules already reversed
Stream out        = write "C:\\temp\\LinkFlipOut_" name(current Project) ".csv"
/************************************
  reverse links in linkList
************************************/
void linkFlip(Link l){
  Object   oSource, oTarget
  Module   mTarget, mLink
  ModName_ mnTarget
  string   sLinkMod
  
  sLinkMod = fullName(module(l))
  mnTarget = module(fullName(target(l))) 
  mTarget = edit(fullName(mnTarget),false, true, true)
  oTarget = target(l)
  if (null oTarget) {
    mTarget = edit(target(l),false, true, true)
 oTarget = target(l)
  }
  oSource = source(l)
  if (null oTarget) {
    out << ",NULL\n"
    return
  }
  if (isDeleted(oTarget)) {
    out << ",DEL\n"
    return
  }
  if(!canModify(oTarget)){
    out <<",!ACCESS\n"
 return
  }
  if (find(completeList, fullName(mnTarget))) {
     out << "," fullName(mTarget) "," oTarget."Absolute Number" ",SKIPPED\n"
     return
  }  
  if (null mnTarget) {
    out << ",NULL mnTarget\n"
    return
  }
  if (null mTarget) {
    out << ",NULL mTarget\n"
    return
  }
  out << "," fullName(mnTarget) "," targetAbsNo(l) ""
  filtering off
  showDeletedObjects on 
  mLink = edit(fullName(module(l)), false) 
 
  oTarget -> sLinkMod -> oSource
  if(canDelete(l))
  {
 delete l
    out <<",DELETED\n"
  } else {
 out << ",FAILED\n"
  }
  flushDeletions
  flush(out)
}
/************************************
   Link Search
************************************/
void linkSearch(){
  Item iRef
  Module m
  Link l
  Object o
  idx = 0
  int linkCountOut = 0
  int linkCountIn  = 0
  out <<"Source Mod,Source Object,Target Mod, Target Object,Status\n"
  for iRef in current Project do {
    if (type(iRef)=="Formal") {
      m = edit(fullName(iRef), false, true, true)
      if (null m) {
        out << "NULL\n"
        continue
      }
      filtering off
      showDeletedObjects on
      current = m 
      linkCountOut = 0
      linkCountIn  = 0
      for o in m do {
        if (null o) {
          out << fullName(m) ",NULL\n"
          continue
        }
        for l in o -> "*" do {
          if (null source(l)) {
            out << fullName(m) ",NULL\n"
            continue
          }
          if (isDeleted(source(l))) {
            out << fullName(m) ",DEL\n"
            continue
          }
          if(!canModify(source(l))){
            out << fullName(m) ",!ACCESS\n"
            continue
          }
          out << fullName(m) "," o."Absolute Number" ""
          linkFlip(l)
    linkCountOut++
        }    
      }
      if (!find(completeList, fullName(m))) put(completeList,fullName(m),fullName(m)) //add completed modules to the skip list      
      save(m)
   close(m)
 }  
  }
  out << "\n"
  flush(out)  
}

/************************************
  Clean up memory
************************************/
void cleanUp(){
  Item iRef
  for iRef in current Project do {
    if (type(iRef)!="Folder") {
      if(open(module(fullName(iRef)))) {
     save(module(iRef))
  close(module(iRef))
      }
    }
    delete(completeList)
    out << "Ending," stringOf(dateAndTime(today)) "\n"
    close(out)
    flush(out)
  }
}

/************************************
  MAIN
************************************/
out << "Start," stringOf(dateAndTime(today)) "\n"
out << "Project," name(current Project) "\n"
linkSearch()
cleanUp()
print "Script Complete"

 

Updated on 2014-03-17T19:31:46Z at 2014-03-17T19:31:46Z by CWicker
  • CWicker
    CWicker
    3 Posts
    ACCEPTED ANSWER

    Re: Access Violation when retrieving link in object

    ‏2014-03-17T21:25:20Z  in response to CWicker

    Assuming the error had something to do with the way I was exiting the voids I reworked to code as follows and I have avoided the issue, but I am still not sure what I was doing wrong in the first example. I would appreciate someone helping me to understand what was going on.

    Now am I encountering null module parameters because I removed several of the null checks I was use before, but they employed the 'return' command which needed to be removed to relieve the access error from above.

    /************************************
        TITLE:    Link Flip Out Only
        DATE:     17 MAR 14    
    ************************************/
    
    Skip completeList = create  //List of Modules already reversed
    Stream out        = write "C:\\temp\\LinkFlipOut_" name(current Project) ".csv"
    string sOptions[] = {"Yes","No"}
    
    /************************************
      Executes link flip
    ************************************/
    void linkFlip(Object oSource, string sLinkMod, Object oTarget, Link l){
      out << "," fullName(module(oTarget)) "," oTarget."Absolute Number" ""
      mLink = edit(sLinkMod, false) 
      if (!find(completeList, fullName(module(oTarget)))) {
        oTarget -> sLinkMod -> oSource 
        if(canDelete(l))
        {
       delete l
          out <<",DELETED\n"
        } else {
       out << ",FAILED\n"
        }
      }
    }
    /************************************
      prepares links to be flipped
    ************************************/
    void linkPrep(Link l){
      Object   oSource, oTarget
      Module   mTarget, mLink
      ModName_ mnTarget
      string   sLinkMod = null
      
      sLinkMod = fullName(module(l))
      mnTarget = module(fullName(target(l)))
      oTarget = target(l)
      if (null oTarget) {
        mTarget = edit(target(l),false, true, true)
     print "Null Target Opened: " name(mTarget) "\n"
        filtering    off
        graphics     off
        outlining    off
        showPictures on
        showTables   on
        sorting      off
        showDeletedObjects(true)
        level(0)
     oTarget = target(l)
      } 
      mTarget = edit(fullName(mnTarget),false, true, true) 
      oSource = source(l)
      if (null oTarget) {
        out << ",NULL\n"
      }
      if (isDeleted(oTarget)) {
        out << ",DEL\n"
      }
      if(!canModify(oTarget)){
        out <<",!ACCESS\n"
      }
      if (!null oTarget && !null oSource && !null sLinkMod) {
        linkFlip(oSource, sLinkMod, oTarget, l)
      }
    }
    /************************************
       Link Search
    ************************************/
    void linkSearch(){
      Item iRef
      Module m
      Link l
      Object o
      idx = 0
      int linkCountOut = 0
      int linkCountIn  = 0
      out <<"Source Mod,Source Object,Target Mod, Target Object,Status\n"
      for iRef in current Project do {
        if (type(iRef)=="Formal") {
          m = edit(fullName(iRef), false, true, true)
          if (null m) {
            out << "NULL\n"
            continue
          }
          filtering    off
          graphics     off
          outlining    off
          showPictures on
          showTables   on
          sorting      off
          showDeletedObjects(true)
          level(0)
          current = m 
          linkCountOut = 0
          linkCountIn  = 0
          for o in m do {
            if (null o) {
              out << fullName(m) ",NULL\n"
              continue
            }
            for l in o -> "*" do {
              if (null source(l)) {
                out << fullName(m) ",NULL\n"
                continue
              }
              if (isDeleted(source(l))) {
                out << fullName(m) ",DEL\n"
                continue
              }
              if(!canModify(source(l))){
                out << fullName(m) ",!ACCESS\n"
                continue
              }
              out << fullName(m) "," o."Absolute Number" ""
              linkPrep(l)
        linkCountOut++
            }    
          }
          if (!find(completeList, fullName(m))) put(completeList,fullName(m),fullName(m)) //add completed modules to the skip list      
       flushDeletions
       int ans = query(name(m) " \n\nContinue?",sOptions)
       if (sOptions[ans] == "No") return
     }  
      }
      out << "\n"
      flush(out)  
    }
    
    /************************************
      Clean up memory
    ************************************/
    void cleanUp(){
      Item iRef
      for iRef in current Project do {
        if (type(iRef)!="Folder") {
          if(open(module(fullName(iRef)))) {
         save(module(iRef))
      close(module(iRef))
          }
        }
        delete(completeList)
        out << "Ending," stringOf(dateAndTime(today)) "\n"
        close(out)
        flush(out)
      }
    }
    
    /************************************
      MAIN
    ************************************/
    out << "Start," stringOf(dateAndTime(today)) "\n"
    out << "Project," name(current Project) "\n"
    linkSearch()
    cleanUp()
    print "Script Complete"
    

     

    Updated on 2014-03-17T21:27:05Z at 2014-03-17T21:27:05Z by CWicker
    • llandale
      llandale
      2943 Posts
      ACCEPTED ANSWER

      Re: Access Violation when retrieving link in object

      ‏2014-03-19T17:51:01Z  in response to CWicker

      You must not delete a Handle inside the Handle loop.  In this case you are deleting a link (line 20)  inside the for l in o ->"*" loop (line 102).  I'm supposing the delayed "flushDeletions" isn't saving you.

      A standard method for deleting links is:

      • Skip skpToDelete = create()   // KEY and DATA both 'Link" to delete
      • for lnk in o ->"*" do
      • {  if (I want to delete this lnk) then put(skpToDelete, lnk, lnk)
      • }
      • for lnk in skpToDelete do
      • {  delete(lnk)
      • }
      • flushDeletions
      • delete(skpToDelete)

      In your case perhaps move the actual deleting to the end of the module rather than the end of the object loop.

      On other news:

      • Yes, completeList MUST be created with createString.
      • You should not presume the "edit" (or "read") commands will both open the module AND make it the "current" module.  If the module is already open, it doesn't become current.  Thus, since you are subsequently changing the "current" module display ("filtering off" et tal), you should explicitely set the current module after opening it.  You should do that routinely before such commands in any case; better safe then sorry.
      • Line 135 can be "for mod in project do" directly giving the Module handles of open modules.  You should check "isEdit" or "isShare", or perhaps "needsSaved" before saving it.
      • Line 145; flush before closing but I doubt it matters.
      • Your "completeList" algorithm doesn't feel right (preventing re-flipping a just flipped link); but maybe its just me.  In any case promote the check in linkFlip() to before you open the target module in the first place.
      • I think you need to be explicitely creating flipped linksets and keeping track of ones you want to delete (and do so at the end of the script).  You could use the existance of such LinkSets to determine if you want to avoid re-flipping.

      -Louie

  • AleKo_
    AleKo_
    4 Posts
    ACCEPTED ANSWER

    Re: Access Violation when retrieving link in object

    ‏2014-03-19T08:14:20Z  in response to CWicker

    you are trying to put string in the skip (line 120) and for this you have to create the skip list using "createString()". maybe this is an issue?

    can you iterate using "print" to understand at which statement exception occurres?

     

    Alex.