summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/textdocument-frames/xmlwriter.cpp
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2010-03-29 06:01:09 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2010-03-29 06:03:47 (GMT)
commit51a444a789ff5f3ba72d3f817f4cdf427d2ff91d (patch)
tree075d06f1a5c6bd0159af201847f1353f63a455bd /doc/src/snippets/textdocument-frames/xmlwriter.cpp
parentd8265f2edd89cc5a9ff0a490177fa6ce3e0b7785 (diff)
downloadQt-51a444a789ff5f3ba72d3f817f4cdf427d2ff91d.zip
Qt-51a444a789ff5f3ba72d3f817f4cdf427d2ff91d.tar.gz
Qt-51a444a789ff5f3ba72d3f817f4cdf427d2ff91d.tar.bz2
Use QSKIP rather than commenting a failure.
Reviewed-by:TrustMe
Diffstat (limited to 'doc/src/snippets/textdocument-frames/xmlwriter.cpp')
0 files changed, 0 insertions, 0 deletions
160' href='#n160'>160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.haxx.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ***************************************************************************/

#include "curl_setup.h"

#ifdef CURLDEBUG

#include <curl/curl.h>

#include "urldata.h"

#define MEMDEBUG_NODEFINES /* don't redefine the standard functions */

/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"

/*
 * Until 2011-08-17 libcurl's Memory Tracking feature also performed
 * automatic malloc and free filling operations using 0xA5 and 0x13
 * values. Our own preinitialization of dynamically allocated memory
 * might be useful when not using third party memory debuggers, but
 * on the other hand this would fool memory debuggers into thinking
 * that all dynamically allocated memory is properly initialized.
 *
 * As a default setting, libcurl's Memory Tracking feature no longer
 * performs preinitialization of dynamically allocated memory on its
 * own. If you know what you are doing, and really want to retain old
 * behavior, you can achieve this compiling with preprocessor symbols
 * CURL_MT_MALLOC_FILL and CURL_MT_FREE_FILL defined with appropriate
 * values.
 */

#ifdef CURL_MT_MALLOC_FILL
# if (CURL_MT_MALLOC_FILL < 0) || (CURL_MT_MALLOC_FILL > 0xff)
#   error "invalid CURL_MT_MALLOC_FILL or out of range"
# endif
#endif

#ifdef CURL_MT_FREE_FILL
# if (CURL_MT_FREE_FILL < 0) || (CURL_MT_FREE_FILL > 0xff)
#   error "invalid CURL_MT_FREE_FILL or out of range"
# endif
#endif

#if defined(CURL_MT_MALLOC_FILL) && defined(CURL_MT_FREE_FILL)
# if (CURL_MT_MALLOC_FILL == CURL_MT_FREE_FILL)
#   error "CURL_MT_MALLOC_FILL same as CURL_MT_FREE_FILL"
# endif
#endif

#ifdef CURL_MT_MALLOC_FILL
#  define mt_malloc_fill(buf,len) memset((buf), CURL_MT_MALLOC_FILL, (len))
#else
#  define mt_malloc_fill(buf,len) Curl_nop_stmt
#endif

#ifdef CURL_MT_FREE_FILL
#  define mt_free_fill(buf,len) memset((buf), CURL_MT_FREE_FILL, (len))
#else
#  define mt_free_fill(buf,len) Curl_nop_stmt
#endif

struct memdebug {
  size_t size;
  union {
    curl_off_t o;
    double d;
    void *p;
  } mem[1];
  /* I'm hoping this is the thing with the strictest alignment
   * requirements.  That also means we waste some space :-( */
};

/*
 * Note that these debug functions are very simple and they are meant to
 * remain so. For advanced analysis, record a log file and write perl scripts
 * to analyze them!
 *
 * Don't use these with multithreaded test programs!
 */

FILE *curl_dbg_logfile = NULL;
static bool memlimit = FALSE; /* enable memory limit */
static long memsize = 0;  /* set number of mallocs allowed */

/* this sets the log file name */
void curl_dbg_memdebug(const char *logname)
{
  if(!curl_dbg_logfile) {
    if(logname && *logname)
      curl_dbg_logfile = fopen(logname, FOPEN_WRITETEXT);
    else
      curl_dbg_logfile = stderr;
#ifdef MEMDEBUG_LOG_SYNC
    /* Flush the log file after every line so the log isn't lost in a crash */
    if(curl_dbg_logfile)
      setbuf(curl_dbg_logfile, (char *)NULL);
#endif
  }
}

/* This function sets the number of malloc() calls that should return
   successfully! */
void curl_dbg_memlimit(long limit)
{
  if(!memlimit) {
    memlimit = TRUE;
    memsize = limit;
  }
}

/* returns TRUE if this isn't allowed! */
static bool countcheck(const char *func, int line, const char *source)
{
  /* if source is NULL, then the call is made internally and this check
     should not be made */
  if(memlimit && source) {
    if(!memsize) {
      if(source) {
        /* log to file */
        curl_dbg_log("LIMIT %s:%d %s reached memlimit\n",
                     source, line, func);
        /* log to stderr also */
        fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
                source, line, func);
        fflush(curl_dbg_logfile); /* because it might crash now */
      }
      errno = ENOMEM;
      return TRUE; /* RETURN ERROR! */
    }
    else
      memsize--; /* countdown */


  }

  return FALSE; /* allow this */
}

void *curl_dbg_malloc(size_t wantedsize, int line, const char *source)
{
  struct memdebug *mem;
  size_t size;

  DEBUGASSERT(wantedsize != 0);

  if(countcheck("malloc", line, source))
    return NULL;

  /* alloc at least 64 bytes */
  size = sizeof(struct memdebug) + wantedsize;

  mem = (Curl_cmalloc)(size);
  if(mem) {
    /* fill memory with junk */
    mt_malloc_fill(mem->mem, wantedsize);
    mem->size = wantedsize;
  }

  if(source)
    curl_dbg_log("MEM %s:%d malloc(%zu) = %p\n",
                 source, line, wantedsize,
                 mem ? (void *)mem->mem : (void *)0);

  return (mem ? mem->mem : NULL);
}

void *curl_dbg_calloc(size_t wanted_elements, size_t wanted_size,
                      int line, const char *source)
{
  struct memdebug *mem;
  size_t size, user_size;

  DEBUGASSERT(wanted_elements != 0);
  DEBUGASSERT(wanted_size != 0);

  if(countcheck("calloc", line, source))
    return NULL;

  /* alloc at least 64 bytes */
  user_size = wanted_size * wanted_elements;
  size = sizeof(struct memdebug) + user_size;

  mem = (Curl_ccalloc)(1, size);
  if(mem)
    mem->size = user_size;

  if(source)
    curl_dbg_log("MEM %s:%d calloc(%zu,%zu) = %p\n",
                 source, line, wanted_elements, wanted_size,
                 mem ? (void *)mem->mem : (void *)0);

  return (mem ? mem->mem : NULL);
}

char *curl_dbg_strdup(const char *str, int line, const char *source)
{
  char *mem;
  size_t len;

  DEBUGASSERT(str != NULL);

  if(countcheck("strdup", line, source))
    return NULL;

  len = strlen(str) + 1;

  mem = curl_dbg_malloc(len, 0, NULL); /* NULL prevents logging */
  if(mem)
    memcpy(mem, str, len);

  if(source)
    curl_dbg_log("MEM %s:%d strdup(%p) (%zu) = %p\n",
                 source, line, (const void *)str, len, (const void *)mem);

  return mem;
}

#if defined(WIN32) && defined(UNICODE)
wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source)
{
  wchar_t *mem;
  size_t wsiz, bsiz;

  DEBUGASSERT(str != NULL);

  if(countcheck("wcsdup", line, source))
    return NULL;

  wsiz = wcslen(str) + 1;
  bsiz = wsiz * sizeof(wchar_t);