
Here it is. It took me some time, though. I had much
to do last week !

Anyway, here is the tarball with some files 4 you. 
I'm attaching the README file (is in the tarball anyway)
so u know what u get and what to do.

Cheer's
Zoran

-----------------------------------------------------------------------


This directory contains support files to enable AOLServer 3.4 to load 
and use the XOTcl 0.85 extension. 

Following files are distributed by this patch:

  o. the "src" directory; contains files to be copied into the same
     directory found in XOTcl distribution.

  o. the "modules" directory; contains files and directories to be put
     in the same place in AOLserver runtime directory.

  o. the "patchfile-3.4 file; contains commands for the patch utility.
     It should be copied to the root of AOLserver source directory.

Regular usage for XOTcl under AOLserver is to declare all your needed
classes, objects, etc at the startup time. The AOLserver will then
take care to replicate all of them in connection threads (or any other
thread). It will also take care to automatically destroy them at
thread-exit time.

You have to dig thru the AOLserver docs in order to find information
on how to make AOLserver-savvy Tcl and/or XOtcl library files, where
to put them, so they get recognized and loaded by the server, etc,
etc.  I'm not going to write about this here - I assume you know it
already.


Why need to patch AOLserver 3.4?
--------------------------------

The AOLserver is a multithreaded application and web server using Tcl
as it's primary extension language. Each server thread gets its own
Tcl interpreter where most of the processing takes place.  In order to
simplify task of creating and properly initializing Tcl interpreters
for each new thread, AOLserver does some additional processing at the
server-start time.

During startup, the startup-thread performs many tasks, one of which
is to load declared shared-libraries and source declared Tcl files.
What to load/source is declared in the server configuration file.
After that, server runs an introspective script which collects names
of all commands, namespaces, variables, etc, found in the interpreter
at that moment. The list of commands is represented internally as
linked-list of Tcl command structures. All other Tcl data (procedures,
namespaces, variables) are collected in a big synthetized Tcl script -
the init script.

When creating the new Tcl interp, AOLserver walks the command
linked-list and creates all commands found there. Afterwards, the init
script is sourced and this re-creates all namespaces, procedures and
variables. So the new Tcl interpreter for new thread is (ahem, should
be...) more or less the same as in the initial startup thread.

All of this can be learned from nsd/tclinit.c file...

This process works mostly fine. There are however couple of culprits
there.  One of the most vulnerable points is the linked list of Tcl
command structs.  A Tcl command structure stores, among others, the
command-deletion callback.  This callback is activated each time a
command is deleted from the interpreter.  Now, this delete-callback
accepts a (ClientData) pointer which gets passed to the callback. This
pointer is also stored in the Tcl command structure.  Now, what
happens if we share the Tcl command structure among threads, more
precisely, use the same command structure to create command in one or
many different threads ? You're right. Shit happens !  Again, more
precisely, many command deletion callbacks get *same* client data
pointer which may (and mostly does) result in memory trashing.

What we do to avoid it?

We simply avoid copying commands with declared deletion callbacks in
the first place (patch the nsd/tclstubs.cpp, the NsTclCreateCommand()
function)

Then, we make sure that our extension registers the AOLserver AtCreate
callback which gets activated each time a new Tcl interp is being
created.  The extension takes care to stuff all what's needed in the
callback so the interpreter gets properly configured.  A minor
inconvenience is that AOLserver calls these (AtCreate) callbacks
*after* running the init script, which is bad. We therefore changed
this behaviour, so handlers are invoked *before* the script gets
evaluated.  This way, the commands collected in the script, which may
(and usually do) reference extension commands, will run properly
(patch the nsd/tclinit.c, the CreateInterp() function).


How to make AOLserver 3.4 to load and use XOTcl 0.85?
-----------------------------------------------------
    
  1. Unpack the xotcl-aolserver patch somewhere on your filesystem:
    
     % cd 
     % tar xvzf ~/xotcl-aolpatch.tar.gz
     % P=~/xotcl-aolpatch
    
  2. Get a new AOLserver 3.4 distribution from 
     http://www.aolserver.com/archive/server/aolserver-3.4.tar.gz
    
     Unpack the original distribution. Copy the patch file from the
     patch directory above to the server source distribution
     directory:
  
     % tar xvzf aolserver-3.4.tar.gz
     % AOL=~/aolserver-3.4
     % cp $P/patchfile-3.4 $AOL/
     % cd $AOL/
     % patch -p0 < patchfile-3.4
    
     Patch should modify following files only:
       nsd/tclinit.c
       nsd/tclstubs.cpp

     NOTE: this description assumes that you have enough
     space in your home directory.
    
  3. Replace one original file:
    
     % mv $AOL/tcl/namespace.tcl $AOL/tcl/namespace.tcl-orig
     % cp $P/modules/tcl/namespace.tcl $AOL/tcl/
       

  4. Compile and install the AOLserver. 
         
     % gmake 
     % gmake install
    
     This should run cleanly on most systems.
     Now, add one additional file

     % mkdir /usr/local/aolserver/modules/tcl/xotcl
     % cp $P/modules/tcl/xotcl/classcopy.xotcl /usr/local/aolserver/modules/tcl/xotcl

This is all you have to do for the AOL-server. You should be able 
to start your server now. But, don't do this until you have 
prepared the XOTcl shared library. This is explained below.


How to make XOTcl 0.85 to load into the AOLserver 3.4?
------------------------------------------------------

  1. Fetch XOTcl 0.85 version from
     http://www.xotcl.org/download/xotcl-0.85-p3.tar.gz

     % cd 
     % tar zxvf xotcl-0.85-p3-tar.gz
     % cd xotcl-0.85-p3
    
  2. Copy aolserver.cpp file from the patch dir to your distribution:
    
     % cp $P/src/aolserver.cpp src/
  
  3. Edit src/Makefile.in and uncomment the line
     with AOL_DEFINES

     % ./configure
    
  4. Build the XOTcl shared library (the .so file). Note that you have
     to build only the shared library, no executables.
    
     % make libs
   
  5. Now, you should copy the library to the server binary directory.

     % cp src/libxotcl.so /usr/local/aolserver/bin

     You also have to tweak the server startup file to load the
     library. Consult the AOLserver documentation on how to do this.
  

 You can start the AOLserver now. If all's well, you should be able to
 see following line in your server log:
    
  [16/Jun/2001:18:08:08][17427.1][-main-] Notice: xotcl module version 0.85

 If you have any problems, try: mailto:zoran@archiware.com
 Have fun!
    
Zoran Vasiljevic
Archiware Inc.