[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

WebObjects adaptor bug... help.



Hi.  I'm trying to compile the WebObjects adaptor (mod_Webobjects.so) for
apache on OpenBSD, and getting the following error.

../Adaptor/shmem.c: In function `WOShmem_lock':
../Adaptor/shmem.c:385: syntax error before `info'
../Adaptor/shmem.c: In function `WOShmem_unlock':
../Adaptor/shmem.c:417: syntax error before `info'

The lines containing the above listed 'syntax error' both say:

info->cache = WOShmem_lockInfoCache;

It's not a definition, or a type-casting problem that I can tell.  Is it the
fact that info is defined:

   LockInfo *info = NULL;

and the compiler is having problems de-referencing info?

Below is a code fragment of both of those functions, with the lines
containing the above two errors marked.  I'm somewhat confused.  It may be
obvious, but I'm not clear here, not being a C programmer very often or
recently.  Any help would be appreciated.

In the short term, I'm disabling shared-memory, but that's a bad hack.

=============================================================

[snip]

typedef union _LockInfo {
   struct flock flockInfo;
   union _LockInfo *cache;
} LockInfo;

[snip]

/*
 * Obtain a lock on a chunk of shared memory. The range of memory
 * begins add address addr, and is size bytes in length. If exclusive
 * is zero the lock is a shared lock for read only access to the region.
 * If exclusive is nonzero the lock is an exclusive lock for write
 * access to the region.
 * The return value is a handle which must be supplied to the WOShmem_unlock
 * function when the lock is released. If some error occurrs and
 * a lock could not be obtained, NULL is returned.
 */
void *WOShmem_lock(const void *addr, unsigned int size, int exclusive)
{
   struct flock *lockInfo;
   int offset;
   LockInfo *info = NULL;

   if (addr && WOShmem_fd != -1)
   {
      offset = addr_to_offset(addr);
      if (offset >= 0 && offset + size < WOShmem_size)
      {
         /* This gets called a lot, so as an optimization to avoid the
malloc() overhead */
         /* we keep a cache of LockInfo's. */
         WA_lock(WOShmem_mutex);
         info = WOShmem_lockInfoCache;
         if (info)
            WOShmem_lockInfoCache = info->cache;
         WA_unlock(WOShmem_mutex);

         /* if there wasn't one in the cache, malloc a new one */
         if (!info)
            info = WOMALLOC(sizeof(LockInfo));

         if (info)
         {
            lockInfo = &info->flockInfo;
            if (lock_file_section(WOShmem_fd, offset, size, lockInfo,
exclusive))
            {
               /* failed; put the info struct back on the cache */
               WA_lock(WOShmem_mutex)
               info->cache = WOShmem_lockInfoCache;                    //
<----- error on line 385
               WOShmem_lockInfoCache = info;
               WA_unlock(WOShmem_mutex);
               info = NULL;
            }
         }
      }
   }
   return info;
}


/*
 * Release a lock obtained by WOShmem_lock. handle is the value returned
 * by WOShmem_lock.
 */
void WOShmem_unlock(void *handle)
{
   if (handle)
   {
      LockInfo *info = (LockInfo *)handle;
      struct flock *lockInfo = &info->flockInfo;
      lockInfo->l_type = F_UNLCK;
      if (fcntl(WOShmem_fd, F_SETLK, lockInfo) == -1)
      {
         char *errMsg = WA_errorDescription(WA_error());
         WOLog(WO_ERR,"WOShmem_unlock(): failed to unlock %d bytes at 0x%x:
%s", lockInfo->l_len, lockInfo->l_start, errMsg);
         WA_freeErrorDescription(errMsg);
         /* how should we recover? */
      }
      /* put the info struct back on the cache */
      WA_lock(WOShmem_mutex)
      info->cache = WOShmem_lockInfoCache;                     // <-----
error on line 417
      WOShmem_lockInfoCache = info;
      WA_unlock(WOShmem_mutex);
   }
}