[M3devel] m3tests, pickles
Tony Hosking
hosking at cs.purdue.edu
Wed Jan 16 15:17:16 CET 2008
Perhaps we just need some builtin specials for types like MUTEX that
need different handling.
Of course, what does it mean to transfer a MUTEX or a thread anyway?!
On Jan 16, 2008, at 7:59 AM, Randy Coleburn wrote:
> Mika:
>
> I've used pickles between various platforms in the past. I use the
> Pickle2 variant.
>
> In my code, I've registered special picklers to deal with mutexes.
> Since it doesn't make sense to transfer the state of a mutex
> between computers, I simply recreate/reinitialize the mutex on the
> receiving computer. Here is an example of an interface and a
> module that defines a type ServerConfig.T that I transfer between
> computers using Pickle2 and network objects. I've omitted some of
> the detail just to show the important stuff about the special
> pickling definitions and procedures:
>
>
> INTERFACE ServerConfig;
>
> CONST
> Brand = "ServerConfig"; (* prefix for all branded references *)
> TYPE
> T <: Public;
>
> Public = ConfigSettings.T OBJECT
> METHODS
> init (): T;
> (* initialize to default settings *)
> ...
> END; (* Public *)
> END ServerConfig.
>
>
>
> MODULE ServerConfig EXPORTS ServerConfig;
>
> IMPORT
> Pickle2 AS Pickle;
> TYPE
> PrivateMutex = MUTEX BRANDED Brand & ".PrivateMutex" OBJECT END;
> REVEAL
> T = Public BRANDED Brand & ".T" OBJECT
> mutex: PrivateMutex := NIL;
> ...
> METHODS
> OVERRIDES
> init := Init;
> ...
> END; (* T *)
>
> (*-------------------*)
> (* Pickle Procedures *)
> (*-------------------*)
>
> TYPE
> Special = Pickle.Special OBJECT
> OVERRIDES
> write := WriteSpecial;
> read := ReadSpecial;
> END; (* Special *)
>
> PROCEDURE WriteSpecial (self: Special;
> <*UNUSED*>ref: REFANY;
> <*UNUSED*>writer: Pickle.Writer
> )
> RAISES {Pickle.Error,
> <*NOWARN*>Wr.Failure, Thread.Alerted} =
> (* Special pickle writer for ServerConfig.PrivateMutex objects. *)
> BEGIN (* WriteSpecial *)
> IF self.sc = TYPECODE(PrivateMutex)
> THEN
> (* omit writing the mutex field *)
> ELSE
> RAISE Pickle.Error("ServerConfig.WriteSpecial asked to
> process unrecognized typecode."); (* should never happen *)
> END; (* if *)
> END WriteSpecial;
>
>
>
> PROCEDURE ReadSpecial (self: Special;
> reader: Pickle.Reader;
> id: Pickle.RefID
> ): REFANY
> RAISES {Pickle.Error,
> <*NOWARN*>Rd.EndOfFile, Rd.Failure, Thread.Alerted} =
> (* Special pickle reader for ServerConfig.PrivateMutex objects. *)
> BEGIN (* ReadSpecial *)
> IF self.sc = TYPECODE(PrivateMutex)
> THEN
> WITH m = NEW(PrivateMutex)
> DO
> reader.noteRef(m, id);
> RETURN m;
> END; (* with *)
> ELSE
> RAISE Pickle.Error("ServerConfig.ReadSpecial asked to process
> unrecognized typecode."); (* should never happen *)
> END; (* if *)
> END ReadSpecial;
>
>
>
> BEGIN (* ServerConfig module initialization *)
> Pickle.RegisterSpecial(NEW(Special, sc := TYPECODE(PrivateMutex)));
> END ServerConfig.
>
> Regards,
> Randy
>
> >>> Mika Nystrom <mika at async.caltech.edu> 1/16/2008 3:45 AM >>>
>
> Can I add something tricky to a wish list on regression testing?
> Tricky because I don't know the best way to go about it.
>
> I have spent quite some time with various versions of Modula-3
> tracking down issues with Pickles. Usually the problem is that
> Pickles aren't transferrable between systems, and it turns out that
> I have included some type, somewhere, that doesn't translate.
> MUTEX is a good example. First of all it would be very nice if
> such system dependencies were kept out (for instance, don't know
> if it's possible, but something like this...)
>
> TYPE RealMutex = OBJECT END;
>
> TYPE WinMutex = RealMutex OBJECT (* windows fields *) END;
> TYPE PosixMutex = RealMutex OBJECT (* POSIX fields *) END;
>
> TYPE MUTEX = RealMutex;
>
> and of course all that a client sees is MUTEX which is the same
> across systems.
>
> However I realize that what I say above may not be possible or
> practical in all cases.
>
> This brings me to the fact that Pickles are sensitive to certain
> types of bugs (I think), and it would be very nice to check that
> all OS/processor builds of M3 make compatible Pickles, with the
> possible exception of things like MUTEX. Of course this can't be
> done within a single build...
>
> Mika
>
More information about the M3devel
mailing list