summaryrefslogtreecommitdiff
path: root/firmware/common/unicode.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/unicode.c')
-rw-r--r--firmware/common/unicode.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/firmware/common/unicode.c b/firmware/common/unicode.c
index f0f663f712..e53ad6bcb0 100644
--- a/firmware/common/unicode.c
+++ b/firmware/common/unicode.c
@@ -168,6 +168,10 @@ static unsigned short default_cp_table_buf[MAX_CP_TABLE_SIZE+1];
168 do {} while (0) 168 do {} while (0)
169#define cp_table_alloc(filename, size, opsp) \ 169#define cp_table_alloc(filename, size, opsp) \
170 ({ (void)(opsp); 1; }) 170 ({ (void)(opsp); 1; })
171#define cp_table_pin(handle) \
172 do { (void)handle; } while(0)
173#define cp_table_unpin(handle) \
174 do { (void)handle; } while(0)
171#else 175#else
172#define cp_table_alloc(filename, size, opsp) \ 176#define cp_table_alloc(filename, size, opsp) \
173 core_alloc_ex((filename), (size), (opsp)) 177 core_alloc_ex((filename), (size), (opsp))
@@ -175,6 +179,10 @@ static unsigned short default_cp_table_buf[MAX_CP_TABLE_SIZE+1];
175 core_free(handle) 179 core_free(handle)
176#define cp_table_get_data(handle) \ 180#define cp_table_get_data(handle) \
177 core_get_data(handle) 181 core_get_data(handle)
182#define cp_table_pin(handle) \
183 core_pin(handle)
184#define cp_table_unpin(handle) \
185 core_unpin(handle)
178#endif 186#endif
179 187
180static const unsigned char utf8comp[6] = 188static const unsigned char utf8comp[6] =
@@ -191,21 +199,8 @@ static inline void cptable_tohw16(uint16_t *buf, unsigned int count)
191 (void)buf; (void)count; 199 (void)buf; (void)count;
192} 200}
193 201
194static int move_callback(int handle, void *current, void *new)
195{
196 /* we don't keep a pointer but we have to stop it if this applies to a
197 buffer not yet swapped-in since it will likely be in use in an I/O
198 call */
199 return (handle != default_cp_handle || default_cp_table_ref != 0) ?
200 BUFLIB_CB_CANNOT_MOVE : BUFLIB_CB_OK;
201 (void)current; (void)new;
202}
203
204static int alloc_and_load_cp_table(int cp, void *buf) 202static int alloc_and_load_cp_table(int cp, void *buf)
205{ 203{
206 static struct buflib_callbacks ops =
207 { .move_callback = move_callback };
208
209 /* alloc and read only if there is an associated file */ 204 /* alloc and read only if there is an associated file */
210 const char *filename = cp_info[cp].filename; 205 const char *filename = cp_info[cp].filename;
211 if (!filename) 206 if (!filename)
@@ -228,13 +223,17 @@ static int alloc_and_load_cp_table(int cp, void *buf)
228 !(size % (off_t)sizeof (uint16_t))) { 223 !(size % (off_t)sizeof (uint16_t))) {
229 224
230 /* if the buffer is provided, use that but don't alloc */ 225 /* if the buffer is provided, use that but don't alloc */
231 int handle = buf ? 0 : cp_table_alloc(filename, size, &ops); 226 int handle = buf ? 0 : cp_table_alloc(filename, size, NULL);
232 if (handle > 0) 227 if (handle > 0) {
228 cp_table_pin(handle);
233 buf = cp_table_get_data(handle); 229 buf = cp_table_get_data(handle);
230 }
234 231
235 if (buf && read(fd, buf, size) == size) { 232 if (buf && read(fd, buf, size) == size) {
236 close(fd); 233 close(fd);
237 cptable_tohw16(buf, size / sizeof (uint16_t)); 234 cptable_tohw16(buf, size / sizeof (uint16_t));
235 if (handle > 0)
236 cp_table_unpin(handle);
238 return handle; 237 return handle;
239 } 238 }
240 239