Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1331

Globals intended for use in a single file should be static

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.5.0, 2.6.0
    • 2.7.0
    • None
    • None
    • Win32, Visual Studio .NET 2003, static library

    Description

      util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp declares and uses several global variables. These variables do not appear to be intended to be visible outside the module. If this is the case, they should be declared static.

      I bumped into this when trying to build the Apache XML Security code with a) Xerces namespace support disabled and b) a statically linked Xerces library. XML Security has a modified version of the BinHTTPURLInputStream class, including copies of the offending globals. This results in warnings from the linker when it detects that the globals are multiply defined. They should fix their end, too (I'll file a report there, too), but the Xerces code should correctly declare its intent as well.

      Changing util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp is simple. The following lines need "static " inserted at the beginning:

      HMODULE gWinsockLib = NULL;
      LPFN_GETHOSTBYNAME gWSgethostbyname = NULL;
      LPFN_INET_ADDR gWSinet_addr = NULL;
      LPFN_GETHOSTBYADDR gWSgethostbyaddr = NULL;
      LPFN_HTONS gWShtons = NULL;
      LPFN_SOCKET gWSsocket = NULL;
      LPFN_CONNECT gWSconnect = NULL;
      LPFN_SEND gWSsend = NULL;
      LPFN_RECV gWSrecv = NULL;
      LPFN_SHUTDOWN gWSshutdown = NULL;
      LPFN_CLOSESOCKET gWSclosesocket = NULL;
      LPFN_WSACLEANUP gWSACleanup = NULL;

      The result:

      static HMODULE gWinsockLib = NULL;
      static LPFN_GETHOSTBYNAME gWSgethostbyname = NULL;
      static LPFN_INET_ADDR gWSinet_addr = NULL;
      static LPFN_GETHOSTBYADDR gWSgethostbyaddr = NULL;
      static LPFN_HTONS gWShtons = NULL;
      static LPFN_SOCKET gWSsocket = NULL;
      static LPFN_CONNECT gWSconnect = NULL;
      static LPFN_SEND gWSsend = NULL;
      static LPFN_RECV gWSrecv = NULL;
      static LPFN_SHUTDOWN gWSshutdown = NULL;
      static LPFN_CLOSESOCKET gWSclosesocket = NULL;
      static LPFN_WSACLEANUP gWSACleanup = NULL;

      Attachments

        Activity

          People

            Unassigned Unassigned
            jessepelton Jesse Pelton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: