[M3devel] suspicious order of evaluation?

Jay K jay.krell at cornell.edu
Thu Oct 25 07:57:37 CEST 2012


correction:
  temp = RTHooks__AllocateTracedRef(...);    sources = temp    if sources == NULL      raise exception  

 - Jay


From: jay.krell at cornell.edu
To: m3devel at elegosoft.com
Date: Thu, 25 Oct 2012 05:42:16 +0000
Subject: [M3devel] suspicious order of evaluation?




  m3tohtml/src/Main.m3:  
  sources is global  
      PROCEDURE Add() =          BEGIN            sources := NEW (Source, next := sources,                            from := Pathname.Join(pkgpath, file, NIL),                            to   := Pathname.Join(pkg, FixDerived (file), NIL),                            kind := kind);      
  It APPEARS this compiles to like:      
  temp = RTHooks__AllocateTracedRef(...);    sources = temp    if temp == NULL      raise exception    sources->from = ...    sources->to = ...    
  To me this seems a bit suspicious.  
    First, the null check should be against the temp.    Sources should not be assigned and then checked.            Second, probably, the fields of sources should be filled in before    the global.            So, it should be more like:  
      temp = RTHooks__AllocateTracedRef();    if temp == NULL      raise exception    temp->from = ...    temp->to = ...    sources = temp    ...  

Just as efficient, but "safer".

Now, I realize, without a lock or barrier, the compiler is free to reorder like this.Maybe ideally temp would be gone but the original order used?

C++ would implement it more like how I showed.

Thoughts?

 - Jay

 		 	   		   		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20121025/e402fa19/attachment-0002.html>


More information about the M3devel mailing list