summaryrefslogtreecommitdiff
path: root/zend/compileroptions.h
blob: c56bf789bcdba038e823802433082145710310bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 *  CompilerOptions.h
 *
 *  Helper class to temporarily set compiler options
 *
 *  When an object is destructed, it automatically restored the previous compiler settings
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2014 Copernica BV
 */

/**
 *  Open PHP namespace
 */
namespace Php {

/**
 *  Class definition
 */
class CompilerOptions
{
private:
    /**
     *  The original compiler options
     *  @var uint32_t
     */
    uint32_t _original;

#ifdef ZTS
    /**
     *  When in thread safety mode, we also keep track of the TSRM_LS var
     *  @var void***
     */
    void ***tsrm_ls;
#endif

public:
    /**
     *  Constructor
     *  @param  options
     */
    CompilerOptions(uint32_t options TSRMLS_DC)
    {
        // remember the old compiler options before we set temporary compile options
        _original = CG(compiler_options);

        // we're going to evaluate only once
        CG(compiler_options) = options;

#ifdef ZTS
        // copy tsrm_ls param
        this->tsrm_ls = tsrm_ls;
#endif
    }

    /**
     *  Destructor
     */
    virtual ~CompilerOptions()
    {
        // restore original options
        CG(compiler_options) = _original;
    }
};

/**
 *  End of namespace
 */
}