< prev index next >

src/java.desktop/share/native/libfontmanager/harfbuzz/hb-blob.cc

Print this page

        

*** 23,40 **** * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * Red Hat Author(s): Behdad Esfahbod */ ! /* http://www.oracle.com/technetwork/articles/servers-storage-dev/standardheaderfiles-453865.html */ #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L #endif ! #include "hb-private.hh" ! #include "hb-debug.hh" ! #include "hb-blob-private.hh" #ifdef HAVE_SYS_MMAN_H #ifdef HAVE_UNISTD_H #include <unistd.h> #endif /* HAVE_UNISTD_H */ --- 23,46 ---- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * Red Hat Author(s): Behdad Esfahbod */ ! ! /* https://github.com/harfbuzz/harfbuzz/issues/1308 ! * http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html ! * https://www.oracle.com/technetwork/articles/servers-storage-dev/standardheaderfiles-453865.html ! */ #ifndef _POSIX_C_SOURCE + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-macros" #define _POSIX_C_SOURCE 200809L + #pragma GCC diagnostic pop #endif ! #include "hb.hh" ! #include "hb-blob.hh" #ifdef HAVE_SYS_MMAN_H #ifdef HAVE_UNISTD_H #include <unistd.h> #endif /* HAVE_UNISTD_H */
*** 45,54 **** --- 51,73 ---- #include <errno.h> #include <stdlib.h> /** + * SECTION: hb-blob + * @title: hb-blob + * @short_description: Binary data containers + * @include: hb.h + * + * Blobs wrap a chunk of binary data to handle lifecycle management of data + * while it is passed between client and HarfBuzz. Blobs are primarily used + * to create font faces, but also to access font face tables, as well as + * pass around other binary data. + **/ + + + /** * hb_blob_create: (skip) * @data: Pointer to blob data. * @length: Length of @data in bytes. * @mode: Memory mode for @data. * @user_data: Data parameter to pass to @destroy.
*** 128,138 **** unsigned int offset, unsigned int length) { hb_blob_t *blob; ! if (!length || offset >= parent->length) return hb_blob_get_empty (); hb_blob_make_immutable (parent); blob = hb_blob_create (parent->data + offset, --- 147,157 ---- unsigned int offset, unsigned int length) { hb_blob_t *blob; ! if (!length || !parent || offset >= parent->length) return hb_blob_get_empty (); hb_blob_make_immutable (parent); blob = hb_blob_create (parent->data + offset,
*** 179,204 **** * Return value: (transfer full): the empty blob. * * Since: 0.9.2 **/ hb_blob_t * ! hb_blob_get_empty (void) { ! static const hb_blob_t _hb_blob_nil = { ! HB_OBJECT_HEADER_STATIC, ! ! true, /* immutable */ ! ! nullptr, /* data */ ! 0, /* length */ ! HB_MEMORY_MODE_READONLY, /* mode */ ! ! nullptr, /* user_data */ ! nullptr /* destroy */ ! }; ! ! return const_cast<hb_blob_t *> (&_hb_blob_nil); } /** * hb_blob_reference: (skip) * @blob: a blob. --- 198,210 ---- * Return value: (transfer full): the empty blob. * * Since: 0.9.2 **/ hb_blob_t * ! hb_blob_get_empty () { ! return const_cast<hb_blob_t *> (&Null(hb_blob_t)); } /** * hb_blob_reference: (skip) * @blob: a blob.
*** 289,302 **** * Since: 0.9.2 **/ void hb_blob_make_immutable (hb_blob_t *blob) { ! if (hb_object_is_inert (blob)) return; ! blob->immutable = true; } /** * hb_blob_is_immutable: * @blob: a blob. --- 295,308 ---- * Since: 0.9.2 **/ void hb_blob_make_immutable (hb_blob_t *blob) { ! if (hb_object_is_immutable (blob)) return; ! hb_object_make_immutable (blob); } /** * hb_blob_is_immutable: * @blob: a blob.
*** 308,318 **** * Since: 0.9.2 **/ hb_bool_t hb_blob_is_immutable (hb_blob_t *blob) { ! return blob->immutable; } /** * hb_blob_get_length: --- 314,324 ---- * Since: 0.9.2 **/ hb_bool_t hb_blob_is_immutable (hb_blob_t *blob) { ! return hb_object_is_immutable (blob); } /** * hb_blob_get_length:
*** 382,392 **** return const_cast<char *> (blob->data); } bool ! hb_blob_t::try_make_writable_inplace_unix (void) { #if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) uintptr_t pagesize = -1, mask, length; const char *addr; --- 388,398 ---- return const_cast<char *> (blob->data); } bool ! hb_blob_t::try_make_writable_inplace_unix () { #if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) uintptr_t pagesize = -1, mask, length; const char *addr;
*** 425,435 **** return false; #endif } bool ! hb_blob_t::try_make_writable_inplace (void) { DEBUG_MSG_FUNC (BLOB, this, "making writable inplace\n"); if (this->try_make_writable_inplace_unix ()) return true; --- 431,441 ---- return false; #endif } bool ! hb_blob_t::try_make_writable_inplace () { DEBUG_MSG_FUNC (BLOB, this, "making writable inplace\n"); if (this->try_make_writable_inplace_unix ()) return true;
*** 440,452 **** this->mode = HB_MEMORY_MODE_READONLY; return false; } bool ! hb_blob_t::try_make_writable (void) { ! if (this->immutable) return false; if (this->mode == HB_MEMORY_MODE_WRITABLE) return true; --- 446,458 ---- this->mode = HB_MEMORY_MODE_READONLY; return false; } bool ! hb_blob_t::try_make_writable () { ! if (hb_object_is_immutable (this)) return false; if (this->mode == HB_MEMORY_MODE_WRITABLE) return true;
*** 485,499 **** # include <sys/types.h> # include <sys/stat.h> # include <fcntl.h> #endif ! #if defined(_WIN32) || defined(__CYGWIN__) # include <windows.h> #else ! # ifndef _O_BINARY ! # define _O_BINARY 0 # endif #endif #ifndef MAP_NORESERVE # define MAP_NORESERVE 0 --- 491,505 ---- # include <sys/types.h> # include <sys/stat.h> # include <fcntl.h> #endif ! #ifdef _WIN32 # include <windows.h> #else ! # ifndef O_BINARY ! # define O_BINARY 0 # endif #endif #ifndef MAP_NORESERVE # define MAP_NORESERVE 0
*** 501,529 **** struct hb_mapped_file_t { char *contents; unsigned long length; ! #if defined(_WIN32) || defined(__CYGWIN__) HANDLE mapping; #endif }; static void ! _hb_mapped_file_destroy (hb_mapped_file_t *file) { #ifdef HAVE_MMAP munmap (file->contents, file->length); ! #elif defined(_WIN32) || defined(__CYGWIN__) UnmapViewOfFile (file->contents); CloseHandle (file->mapping); #else assert (0); // If we don't have mmap we shouldn't reach here #endif free (file); } /** * hb_blob_create_from_file: * @file_name: font filename. * --- 507,538 ---- struct hb_mapped_file_t { char *contents; unsigned long length; ! #ifdef _WIN32 HANDLE mapping; #endif }; + #if (defined(HAVE_MMAP) || defined(_WIN32)) && !defined(HB_NO_MMAP) static void ! _hb_mapped_file_destroy (void *file_) { + hb_mapped_file_t *file = (hb_mapped_file_t *) file_; #ifdef HAVE_MMAP munmap (file->contents, file->length); ! #elif defined(_WIN32) UnmapViewOfFile (file->contents); CloseHandle (file->mapping); #else assert (0); // If we don't have mmap we shouldn't reach here #endif free (file); } + #endif /** * hb_blob_create_from_file: * @file_name: font filename. *
*** 538,548 **** Allison Lortie permission but changed a lot to suit our need. */ #if defined(HAVE_MMAP) && !defined(HB_NO_MMAP) hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); ! int fd = open (file_name, O_RDONLY | _O_BINARY, 0); if (unlikely (fd == -1)) goto fail_without_close; struct stat st; if (unlikely (fstat (fd, &st) == -1)) goto fail; --- 547,557 ---- Allison Lortie permission but changed a lot to suit our need. */ #if defined(HAVE_MMAP) && !defined(HB_NO_MMAP) hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); ! int fd = open (file_name, O_RDONLY | O_BINARY, 0); if (unlikely (fd == -1)) goto fail_without_close; struct stat st; if (unlikely (fstat (fd, &st) == -1)) goto fail;
*** 561,585 **** fail: close (fd); fail_without_close: free (file); ! #elif (defined(_WIN32) || defined(__CYGWIN__)) && !defined(HB_NO_MMAP) hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); ! HANDLE fd = CreateFile (file_name, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, nullptr); if (unlikely (fd == INVALID_HANDLE_VALUE)) goto fail_without_close; file->length = (unsigned long) GetFileSize (fd, nullptr); file->mapping = CreateFileMapping (fd, nullptr, PAGE_READONLY, 0, 0, nullptr); if (unlikely (file->mapping == nullptr)) goto fail; file->contents = (char *) MapViewOfFile (file->mapping, FILE_MAP_READ, 0, 0, 0); if (unlikely (file->contents == nullptr)) goto fail; CloseHandle (fd); return hb_blob_create (file->contents, file->length, HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, (void *) file, --- 570,627 ---- fail: close (fd); fail_without_close: free (file); ! #elif defined(_WIN32) && !defined(HB_NO_MMAP) hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); ! HANDLE fd; ! unsigned int size = strlen (file_name) + 1; ! wchar_t * wchar_file_name = (wchar_t *) malloc (sizeof (wchar_t) * size); ! if (unlikely (wchar_file_name == nullptr)) goto fail_without_close; ! mbstowcs (wchar_file_name, file_name, size); ! #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) ! { ! CREATEFILE2_EXTENDED_PARAMETERS ceparams = { 0 }; ! ceparams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS); ! ceparams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED & 0xFFFF; ! ceparams.dwFileFlags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED & 0xFFF00000; ! ceparams.dwSecurityQosFlags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED & 0x000F0000; ! ceparams.lpSecurityAttributes = nullptr; ! ceparams.hTemplateFile = nullptr; ! fd = CreateFile2 (wchar_file_name, GENERIC_READ, FILE_SHARE_READ, ! OPEN_EXISTING, &ceparams); ! } ! #else ! fd = CreateFileW (wchar_file_name, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, nullptr); + #endif + free (wchar_file_name); if (unlikely (fd == INVALID_HANDLE_VALUE)) goto fail_without_close; + #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) + { + LARGE_INTEGER length; + GetFileSizeEx (fd, &length); + file->length = length.LowPart; + file->mapping = CreateFileMappingFromApp (fd, nullptr, PAGE_READONLY, length.QuadPart, nullptr); + } + #else file->length = (unsigned long) GetFileSize (fd, nullptr); file->mapping = CreateFileMapping (fd, nullptr, PAGE_READONLY, 0, 0, nullptr); + #endif if (unlikely (file->mapping == nullptr)) goto fail; + #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP) + file->contents = (char *) MapViewOfFileFromApp (file->mapping, FILE_MAP_READ, 0, 0); + #else file->contents = (char *) MapViewOfFile (file->mapping, FILE_MAP_READ, 0, 0, 0); + #endif if (unlikely (file->contents == nullptr)) goto fail; CloseHandle (fd); return hb_blob_create (file->contents, file->length, HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, (void *) file,
< prev index next >