~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to lib/curl_memory.h

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-05-07 12:16:37 UTC
  • mfrom: (3.4.37 sid)
  • Revision ID: package-import@ubuntu.com-20130507121637-9t3i98qgsyr9dw5d
Tags: 7.30.0-1ubuntu1
* Resynchronize on Debian. Remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from binary package Depends.
  - Add new libcurl3-udeb package.
  - Add new curl-udeb package.
* Add warning to debian/patches/series.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 *                            | (__| |_| |  _ <| |___
8
8
 *                             \___|\___/|_| \_\_____|
9
9
 *
10
 
 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
 
10
 * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
11
11
 *
12
12
 * This software is licensed as described in the file COPYING, which
13
13
 * you should have received as part of this distribution. The terms
22
22
 *
23
23
 ***************************************************************************/
24
24
 
25
 
#include <curl/curl.h> /* for the typedefs */
 
25
/*
 
26
 * Nasty internal details ahead...
 
27
 *
 
28
 * File curl_memory.h must be included by _all_ *.c source files
 
29
 * that use memory related functions strdup, malloc, calloc, realloc
 
30
 * or free, and given source file is used to build libcurl library.
 
31
 *
 
32
 * There is nearly no exception to above rule. All libcurl source
 
33
 * files in 'lib' subdirectory as well as those living deep inside
 
34
 * 'packages' subdirectories and linked together in order to build
 
35
 * libcurl library shall follow it.
 
36
 *
 
37
 * File lib/strdup.c is an exception, given that it provides a strdup
 
38
 * clone implementation while using malloc. Extra care needed inside
 
39
 * this one. TODO: revisit this paragraph and related code.
 
40
 *
 
41
 * The need for curl_memory.h inclusion is due to libcurl's feature
 
42
 * of allowing library user to provide memory replacement functions,
 
43
 * memory callbacks, at runtime with curl_global_init_mem()
 
44
 *
 
45
 * Any *.c source file used to build libcurl library that does not
 
46
 * include curl_memory.h and uses any memory function of the five
 
47
 * mentioned above will compile without any indication, but it will
 
48
 * trigger weird memory related issues at runtime.
 
49
 *
 
50
 * OTOH some source files from 'lib' subdirectory may additionally be
 
51
 * used directly as source code when using some curlx_ functions by
 
52
 * third party programs that don't even use libcurl at all. When using
 
53
 * these source files in this way it is necessary these are compiled
 
54
 * with CURLX_NO_MEMORY_CALLBACKS defined, in order to ensure that no
 
55
 * attempt of calling libcurl's memory callbacks is done from code
 
56
 * which can not use this machinery.
 
57
 *
 
58
 * Notice that libcurl's 'memory tracking' system works chaining into
 
59
 * the memory callback machinery. This implies that when compiling
 
60
 * 'lib' source files with CURLX_NO_MEMORY_CALLBACKS defined this file
 
61
 * disengages usage of libcurl's 'memory tracking' system, defining
 
62
 * MEMDEBUG_NODEFINES and overriding CURLDEBUG purpose.
 
63
 *
 
64
 * CURLX_NO_MEMORY_CALLBACKS takes precedence over CURLDEBUG. This is
 
65
 * done in order to allow building a 'memory tracking' enabled libcurl
 
66
 * and at the same time allow building programs which do not use it.
 
67
 *
 
68
 * Programs and libraries in 'tests' subdirectories have specific
 
69
 * purposes and needs, and as such each one will use whatever fits
 
70
 * best, depending additionally wether it links with libcurl or not.
 
71
 *
 
72
 * Caveat emptor. Proper curlx_* separation is a work in progress
 
73
 * the same as CURLX_NO_MEMORY_CALLBACKS usage, some adjustments may
 
74
 * still be required. IOW don't use them yet, there are sharp edges.
 
75
 */
 
76
 
 
77
#ifdef HEADER_CURL_MEMDEBUG_H
 
78
#error "Header memdebug.h shall not be included before curl_memory.h"
 
79
#endif
 
80
 
 
81
#ifndef CURLX_NO_MEMORY_CALLBACKS
 
82
 
 
83
#include <curl/curl.h> /* for the callback typedefs */
26
84
 
27
85
extern curl_malloc_callback Curl_cmalloc;
28
86
extern curl_free_callback Curl_cfree;
29
87
extern curl_realloc_callback Curl_crealloc;
30
88
extern curl_strdup_callback Curl_cstrdup;
31
89
extern curl_calloc_callback Curl_ccalloc;
 
90
#ifdef WIN32
 
91
extern curl_wcsdup_callback Curl_cwcsdup;
 
92
#endif
32
93
 
33
94
#ifndef CURLDEBUG
34
 
/* Only do this define-mania if we're not using the memdebug system, as that
35
 
   has preference on this magic. */
 
95
 
 
96
/*
 
97
 * libcurl's 'memory tracking' system defines strdup, malloc, calloc,
 
98
 * realloc and free, along with others, in memdebug.h in a different
 
99
 * way although still using memory callbacks forward declared above.
 
100
 * When using the 'memory tracking' system (CURLDEBUG defined) we do
 
101
 * not define here the five memory functions given that definitions
 
102
 * from memdebug.h are the ones that shall be used.
 
103
 */
 
104
 
36
105
#undef strdup
37
106
#define strdup(ptr) Curl_cstrdup(ptr)
38
107
#undef malloc
44
113
#undef free
45
114
#define free(ptr) Curl_cfree(ptr)
46
115
 
47
 
#endif
 
116
#ifdef WIN32
 
117
#  undef wcsdup
 
118
#  define wcsdup(ptr) Curl_cwcsdup(ptr)
 
119
#  undef _wcsdup
 
120
#  define _wcsdup(ptr) Curl_cwcsdup(ptr)
 
121
#  undef _tcsdup
 
122
#  ifdef UNICODE
 
123
#    define _tcsdup(ptr) Curl_cwcsdup(ptr)
 
124
#  else
 
125
#    define _tcsdup(ptr) Curl_cstrdup(ptr)
 
126
#  endif
 
127
#endif
 
128
 
 
129
#endif /* CURLDEBUG */
 
130
 
 
131
#else /* CURLX_NO_MEMORY_CALLBACKS */
 
132
 
 
133
#ifndef MEMDEBUG_NODEFINES
 
134
#define MEMDEBUG_NODEFINES
 
135
#endif
 
136
 
 
137
#endif /* CURLX_NO_MEMORY_CALLBACKS */
48
138
 
49
139
#endif /* HEADER_CURL_MEMORY_H */