intl/hyphenation/src/hnjalloc.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/hyphenation/src/hnjalloc.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Simple replacement for hnjalloc.h from libhyphen-2.x, to use moz_x* memory
    1.11 + * allocation functions. Note that the hyphen.c code does *NOT* check for
    1.12 + * NULL from memory (re)allocation, so it is essential that we use the
    1.13 + * "infallible" moz_x* variants here.
    1.14 + */
    1.15 +
    1.16 +#include "mozilla/mozalloc.h"
    1.17 +
    1.18 +#define hnj_malloc(size)      moz_xmalloc(size)
    1.19 +#define hnj_realloc(p, size)  moz_xrealloc(p, size)
    1.20 +#define hnj_free(p)           moz_free(p)
    1.21 +
    1.22 +/*
    1.23 + * To enable us to load hyphenation dictionaries from arbitrary resource URIs,
    1.24 + * not just through file paths using stdio, we override the (few) stdio APIs
    1.25 + * that hyphen.c uses and provide our own reimplementation that calls Gecko
    1.26 + * i/o methods.
    1.27 + */
    1.28 +
    1.29 +#include <stdio.h> /* ensure stdio.h is loaded before our macros */
    1.30 +
    1.31 +#undef FILE
    1.32 +#define FILE hnjFile
    1.33 +
    1.34 +#define fopen(path,mode)      hnjFopen(path,mode)
    1.35 +#define fclose(file)          hnjFclose(file)
    1.36 +#define fgets(buf,count,file) hnjFgets(buf,count,file)
    1.37 +
    1.38 +typedef struct hnjFile_ hnjFile;
    1.39 +
    1.40 +#ifdef __cplusplus
    1.41 +extern "C" {
    1.42 +#endif
    1.43 +
    1.44 +hnjFile* hnjFopen(const char* aURISpec, const char* aMode);
    1.45 +
    1.46 +int hnjFclose(hnjFile* f);
    1.47 +
    1.48 +char* hnjFgets(char* s, int n, hnjFile* f);
    1.49 +
    1.50 +#ifdef __cplusplus
    1.51 +}
    1.52 +#endif
    1.53 +
    1.54 +

mercurial