Remove duplicate defines of HAVE_LIBJPEG and HAVE_LIBPNG.
[hiphop-php.git] / hphp / runtime / ext / gd / libgd / php_compat.h
blobed5c1d12c414357cb11669bb582895444a809c13
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #ifndef incl_HPHP_LIBGD_COMPAT_H_
19 #define incl_HPHP_LIBGD_COMPAT_H_
21 // I died a little inside writing this, but we have to end the extern "C"
24 #include "hphp/runtime/base/directory.h"
25 #include "hphp/runtime/base/file.h"
26 #include "hphp/runtime/base/preg.h"
27 #include "hphp/runtime/base/runtime-error.h"
28 #include "hphp/runtime/base/stream-wrapper-registry.h"
29 #include "hphp/runtime/base/stream-wrapper.h"
30 #include "hphp/runtime/base/zend-printf.h"
31 #include "hphp/runtime/base/zend-php-config.h"
32 #include "hphp/util/string-vsnprintf.h"
34 // And start the blasted C stuff again
35 extern "C" {
37 #ifdef FACEBOOK
38 # define HAVE_LIBJPEG
39 # define HAVE_LIBPNG
40 #endif
41 #define emalloc HPHP::req::malloc
42 #define ecalloc HPHP::req::calloc
43 #define efree HPHP::req::free
44 #define erealloc HPHP::req::realloc
45 #define vspprintf HPHP::vspprintf
46 #define TSRMLS_CC
47 #define TSRMLS_FETCH()
48 #define MAXPATHLEN PATH_MAX
49 #define pemalloc(size, persistent) ((persistent)?malloc(size):emalloc(size))
50 #define pefree(ptr, persistent) ((persistent)?free(ptr):efree(ptr))
51 #define pestrdup(s, persistent) ((persistent)?strdup(s):estrdup(s))
52 #define VCWD_GETCWD(buff, size) getcwd(buff, size)
54 static inline size_t safe_address(size_t nmemb, size_t size, size_t offset) {
55 return nmemb * size + offset;
58 inline void *safe_emalloc(size_t nmemb, size_t size, size_t offset) {
59 return emalloc(safe_address(nmemb, size, offset));
62 inline char *estrndup(const char *s, unsigned int length) {
63 char* ret = (char*) emalloc(length + 1);
64 memcpy(ret, s, length);
65 ret[length] = '\0';
66 return ret;
69 inline char *estrdup(const char *s) {
70 return estrndup(s, strlen(s));
73 #define E_ERROR (1<<0L)
74 #define E_WARNING (1<<1L)
75 #define E_NOTICE (1<<3L)
76 inline void php_verror(const char *docref, const char *params, int type,
77 const char *format, va_list args) {
78 std::string msg;
79 HPHP::string_vsnprintf(msg, format, args);
81 if (type == E_ERROR) {
82 return HPHP::raise_error(msg);
83 } else if (type == E_WARNING) {
84 return HPHP::raise_warning(msg);
85 } else if (type == E_NOTICE) {
86 return HPHP::raise_notice(msg);
88 not_reached();
90 inline void php_error_docref(const char *docref, int type,
91 const char *format, ...) {
92 va_list args;
93 va_start(args, format);
94 php_verror(docref, "", type, format, args);
95 va_end(args);
98 // Force gdhelpers.h to run with thread safety.
99 #define ZTS
100 #define MUTEX_T pthread_mutex_t
102 // This abomination is required because of what happens in gdhelpers.h.
103 // They steal (x) away from us, so we just looked up the one place
104 // which used it and hard-coded it in here. Yep.
105 #define tsrm_mutex_alloc(x) gdFontCacheMutex; \
106 pthread_mutex_init(&gdFontCacheMutex, 0)
108 #define tsrm_mutex_free(x) pthread_mutex_destroy(&x)
109 #define tsrm_mutex_lock(x) pthread_mutex_lock(&x)
110 #define tsrm_mutex_unlock(x) pthread_mutex_unlock(&x)
112 // Double definition with libjpeg, which can affect PCH builds
113 #undef MAXJSAMPLE
115 // And double definition with libxml2
116 #undef ESC
118 #endif // incl_HPHP_LIBGD_COMPAT_H_