]> git.ipfire.org Git - thirdparty/squid.git/blame - compat/compat.dox
SquidNew: don't redefine new and delete on clang
[thirdparty/squid.git] / compat / compat.dox
CommitLineData
823b0590
AJ
1/**
2\defgroup compat Portability Library
3
4\title Squid Portability
5
6
7\section 1 Aim
8
9\par
10Squid aims to build and run on many modern systems. To do this we have traditionally
11added small hacks and wrappers all over the code whenever one was needed.
12The final result of that is a vast amount of code duplication, dodgy licensing on
13some older hacks, and some cases of obsolete algorithms sitting side by side with their
14current equivalent.
15
16\par
17The Portability library libcompat-squid.la has been created to correct the three issues of
18stable build portability, code cleanliness, and clearer licensing.
19
20
21\section 2 Requirements
22
23\par
24The system calls used by Squid are not required to be standard. Often we depend on
25some non-standard call which can give great performance benefits.
26But they are required to meet several other criteria:
27 \li They must be of actual benefit to Squid during its operation.
28 \li A better alternative must not exist.
29 \li If not available on all OS an open-source GPLv2+ implementation must be available
30 to be included with the Squid sources and used when required.
31
32\par
33To be built into the libcompat-squid.la as a layer below all Squid-bundled binaries. The code
34must also qualify by being provided natively by some OS where Squid builds. \br
35Code and Algorithms which do not meet this final criteria are relegated to the slightly
36higher level of basic component, rather than portability.
37
38
39\section 3 Component Types
40
41\par Macro re-definition
42Where the only difference between systems is their naming scheme. One of the schemes is
43chosen by the developers for use and mappings are created in the form of Macros.
44
45\par Inline Functions
46
47\par Algorithm Templates and Inline functions
48Being C++ we are able to use templates in place of inline functions where that is more
49convenient. Care is taken to provide no additional requirements upon the callers when
50using the template as to when using the native constructs.
51
52\par Emulators
53As mentioned above if a useful library function calls or global is not available on all
54operating systems a GPLv2+ alternative may be added to the compat layer. As an emulator
55it retains the exact naming and definition of the source systems. Thus being able to be
56used seamlessly across all platforms by the main code.
57
58\par Wrappers
59Sometimes common and useful library functions are not always as safe as they could be.
60An alternative which wraps the original in extra safety checks is provided under the
61same name with an 'x' pre-pended. Currently these extra protections are added on string
62handling and memory allocation.
63
64
65\section 4 Layout
66The internal code structure of libcompat-squid.la files has a hierarchy. The API has a flat
67global scope separate from the file layout. The API is pulled in by including compat/compat.h.
68The strict dependency requirements which exist within the compat API make including
69individual part separately a risky operation.
70
71\par
582c2af2 72Squid coding guidelines require each .c and .cc file to include squid.h first
f7f3304a 73in their included files. squid.h begin with an order-specific sequence of defines and
823b0590 74includes compat/compat.h to incorporate the compat layer appropriately in every soure file.
823b0590
AJ
75
76\par
77Internally the compat/ directory contains the public API file compat/compat.h which structures
78order-specific includes as documented inside that file. Included by that is compat/osdetect.h
79which determines which operating system and in some cases compiler is being used.
80
81\par
82The compat/os/ directory contains separate files for each supported system which requires
83special compat layer handling. Hacks for specific systems should be restricted to these files
84as much as possible.
85
86\par
87compat/compat_shared.h file contains the shared portability definitions which are shared
88across a great many systems. These should be written with protective macros to prevent any
89symbols or code being defined which is not necessary. Protections here must not be system-specific.
90
91\par
92Also in compat/ directory are the .h and .c files for emulators detected by autoconf. These
93are added by autoconf to the build objects as required.
94
95*/