Rename smart->small in MM apis
[hiphop-php.git] / hphp / runtime / ext / gd / libgd / gdhelpers.h
blob8f7ec3834451a8a7cb487320b869e935b94a6157
1 #ifndef GDHELPERS_H
2 #define GDHELPERS_H 1
4 #include <sys/types.h>
5 #include "php.h"
7 #include "hphp/runtime/base/memory-manager.h"
9 /* TBB: strtok_r is not universal; provide an implementation of it. */
11 extern char *gd_strtok_r(char *s, char *sep, char **state);
13 /* Check for request OOM. Call before allocating a lot of memory. */
14 inline bool precheckOOM(size_t allocsz) {
15 return allocsz > HPHP::kMaxSmallSize && HPHP::MM().preAllocOOM(allocsz);
18 /* These functions wrap memory management. gdFree is
19 in gd.h, where callers can utilize it to correctly
20 free memory allocated by these functions with the
21 right version of free(). */
22 #define gdCalloc(nmemb, size) ecalloc(nmemb, size)
23 #define gdMalloc(size) emalloc(size)
24 #define gdRealloc(ptr, size) erealloc(ptr, size)
25 #define gdEstrdup(ptr) estrdup(ptr)
26 #define gdFree(ptr) efree(ptr)
27 #define gdPMalloc(ptr) pemalloc(ptr, 1)
28 #define gdPFree(ptr) pefree(ptr, 1)
29 #define gdPEstrdup(ptr) pestrdup(ptr, 1)
31 /* Returns nonzero if multiplying the two quantities will
32 result in integer overflow. Also returns nonzero if
33 either quantity is negative. By Phil Knirsch based on
34 netpbm fixes by Alan Cox. */
36 int overflow2(int a, int b);
38 #ifdef ZTS
39 #define gdMutexDeclare(x) MUTEX_T x
40 #define gdMutexSetup(x) x = tsrm_mutex_alloc()
41 #define gdMutexShutdown(x) tsrm_mutex_free(x)
42 #define gdMutexLock(x) tsrm_mutex_lock(x)
43 #define gdMutexUnlock(x) tsrm_mutex_unlock(x)
44 #else
45 #define gdMutexDeclare(x)
46 #define gdMutexSetup(x)
47 #define gdMutexShutdown(x)
48 #define gdMutexLock(x)
49 #define gdMutexUnlock(x)
50 #endif
52 #endif /* GDHELPERS_H */