OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2009 Red Hat, Inc. | 2 * Copyright © 2009 Red Hat, Inc. |
3 * | 3 * |
4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
5 * | 5 * |
6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 10 * all copies of this software. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 _hb_blob_destroy_user_data (hb_blob_t *blob) | 71 _hb_blob_destroy_user_data (hb_blob_t *blob) |
72 { | 72 { |
73 if (blob->destroy) { | 73 if (blob->destroy) { |
74 blob->destroy (blob->user_data); | 74 blob->destroy (blob->user_data); |
75 blob->user_data = NULL; | 75 blob->user_data = NULL; |
76 blob->destroy = NULL; | 76 blob->destroy = NULL; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 /** | 80 /** |
81 * hb_blob_create: (Xconstructor) | 81 * hb_blob_create: (skip) |
82 * @data: (array length=length) (closure user_data) (destroy destroy) (scope not
ified) (transfer none): Pointer to blob data. | 82 * @data: Pointer to blob data. |
83 * @length: Length of @data in bytes. | 83 * @length: Length of @data in bytes. |
84 * @mode: Memory mode for @data. | 84 * @mode: Memory mode for @data. |
85 * @user_data: Data parameter to pass to @destroy. | 85 * @user_data: Data parameter to pass to @destroy. |
86 * @destroy: Callback to call when @data is not needed anymore. | 86 * @destroy: Callback to call when @data is not needed anymore. |
87 * | 87 * |
88 * Creates a new "blob" object wrapping @data. The @mode parameter is used | 88 * Creates a new "blob" object wrapping @data. The @mode parameter is used |
89 * to negotiate ownership and lifecycle of @data. | 89 * to negotiate ownership and lifecycle of @data. |
90 * | 90 * |
91 * Return value: New blob, or the empty blob if something failed or if @length i
s | 91 * Return value: New blob, or the empty blob if something failed or if @length i
s |
92 * zero. Destroy with hb_blob_destroy(). | 92 * zero. Destroy with hb_blob_destroy(). |
93 * | 93 * |
94 * Since: 1.0 | 94 * Since: 1.0 |
95 **/ | 95 **/ |
96 hb_blob_t * | 96 hb_blob_t * |
97 hb_blob_create (const char *data, | 97 hb_blob_create (const char *data, |
98 unsigned int length, | 98 unsigned int length, |
99 hb_memory_mode_t mode, | 99 hb_memory_mode_t mode, |
100 void *user_data, | 100 void *user_data, |
101 hb_destroy_func_t destroy) | 101 hb_destroy_func_t destroy) |
102 { | 102 { |
103 hb_blob_t *blob; | 103 hb_blob_t *blob; |
104 | 104 |
105 if (!length || !(blob = hb_object_create<hb_blob_t> ())) { | 105 if (!length || |
| 106 length >= 1u << 31 || |
| 107 data + length < data /* overflows */ || |
| 108 !(blob = hb_object_create<hb_blob_t> ())) { |
106 if (destroy) | 109 if (destroy) |
107 destroy (user_data); | 110 destroy (user_data); |
108 return hb_blob_get_empty (); | 111 return hb_blob_get_empty (); |
109 } | 112 } |
110 | 113 |
111 blob->data = data; | 114 blob->data = data; |
112 blob->length = length; | 115 blob->length = length; |
113 blob->mode = mode; | 116 blob->mode = mode; |
114 | 117 |
115 blob->user_data = user_data; | 118 blob->user_data = user_data; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 470 |
468 memcpy (new_data, blob->data, blob->length); | 471 memcpy (new_data, blob->data, blob->length); |
469 _hb_blob_destroy_user_data (blob); | 472 _hb_blob_destroy_user_data (blob); |
470 blob->mode = HB_MEMORY_MODE_WRITABLE; | 473 blob->mode = HB_MEMORY_MODE_WRITABLE; |
471 blob->data = new_data; | 474 blob->data = new_data; |
472 blob->user_data = new_data; | 475 blob->user_data = new_data; |
473 blob->destroy = free; | 476 blob->destroy = free; |
474 | 477 |
475 return true; | 478 return true; |
476 } | 479 } |
OLD | NEW |