comparison src/text.c @ 1318:b531bf8658e9

[xemacs-hg @ 2003-02-21 06:56:46 by ben] redisplay fixes et al. PROBLEMS: Add comment about Cygwin, unexec and sysmalloc. Move some non-general stuff out of general. Make a section for x86. configure.in: Add check for broken alloca in funcalls. mule/mule-cmds.el: Alias file-name to native not vice-versa. Do set EOL of native but not of process output to fix various problems and be consistent with code-init.el. code-cmds.el: Return a name not a coding system. code-init.el: Reindent. Remove `file-name' since it should always be the same as native. unicode.el: Rename to load-unicode-mapping-table as suggested by the anonymous (but rather Turnbullian) comment in unicode.c. xemacs.dsp: Add /k to default build. alloc.c: Make gc_currently_forbidden static. config.h.in, lisp.h: Move some stuff to lisp.h. console-gtk.h, console-impl.h, console-msw.h, console-x.h, event-Xt.c, event-msw.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, gtk-xemacs.c: Remove duplicated code to redraw exposed area. Add deadbox method needed by the generalized redraw code. Defer redrawing if already in redisplay. frame-msw.c, event-stream.c, frame.c: Add comments about calling Lisp. debug.c, general-slots.h: Move generalish symbols to general-slots.h. doprnt.c: reindent. lisp.h, dynarr.c: Add debug code for locking a dynarr to catch invalid mods. Use in redisplay.c. eval.c: file-coding.c: Define file-name as alias for native not vice-versa. frame-gtk.c, frame-x.c: Move Qwindow_id to general-slots. dialog-msw.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, gui.c, gui.h, menubar-msw.c, menubar.c: Ensure that various glyph functions that eval within redisplay protect the evals. Same for calls to internal_equal(). Modify various functions, e.g. gui_item_*(), to protect evals within redisplay, taking an in_redisplay parameter if it's possible for them to be called both inside and outside of redisplay. gutter.c: Defer specifier-changed updating till after redisplay, if necessary, since we need to enter redisplay to do it. gutter.c: Do nothing if in redisplay. lisp.h: Add version of alloca() for use in function calls. lisp.h: Add XCAD[D+]R up to 6 D's, and aliases X1ST, X2ND, etc. frame.c, frame.h, redisplay.c, redisplay.h, signal.c, toolbar.c: Redo critical-section code and move from frame.c to redisplay.c. Require that every place inside of redisplay catch errors itself, not at the edge of the critical section (thereby bypassing the rest of redisplay and leaving things in an inconsistent state). Introduce separate means of holding frame-size changes without entering a complete critical section. Introduce "post-redisplay" methods for deferring things till after redisplay. Abort if we enter redisplay reentrantly. Disable all quit checking in redisplay since it's too dangerous. Ensure that all calls to QUIT trigger an abort if unprotected. redisplay.c, scrollbar-gtk.c, scrollbar-x.c, scrollbar.c: Create enter/exit_redisplay_critical_section_maybe() for code that needs to ensure it's in a critical section but doesn't interfere with an existing critical section. sysdep.c: Use _wexecve() when under Windows NT for Unicode correctness. text.c, text.h: Add new_dfc() functions, which return an alloca()ed value rather than requiring an lvalue. (Not really used yet; used in another workspace, to come.) Add some macros for SIZED_EXTERNAL. Update the encoding aliases after involved scrutinization of the X manual. unicode.c: Answer the anonymous but suspiciously Turnbullian questions. Rename parse-unicode-translation-table to load-unicode-mapping-table, as suggested.
author ben
date Fri, 21 Feb 2003 06:57:21 +0000
parents 70921960b980
children 969b7290edca
comparison
equal deleted inserted replaced
1317:d9d08dc5e617 1318:b531bf8658e9
3217 } 3217 }
3218 3218
3219 PROFILE_RECORD_EXITING_SECTION (QSin_internal_external_conversion); 3219 PROFILE_RECORD_EXITING_SECTION (QSin_internal_external_conversion);
3220 } 3220 }
3221 3221
3222 /* ----------------------------------------------------------------------- */
3223 /* New-style DFC converters (data is returned rather than stored into var) */
3224 /* ----------------------------------------------------------------------- */
3225
3226 /* We handle here the cases where SRC is a Lisp_Object, internal data
3227 (sized or unsized), or external data (sized or unsized), and return type
3228 is unsized alloca() or malloc() data. If the return type is a
3229 Lisp_Object, use build_ext_string() for unsized external data,
3230 make_ext_string() for sized external data. If the return type needs to
3231 be sized data, use the *_TO_SIZED_*() macros, and for other more
3232 complicated cases, use the original TO_*_FORMAT() macros. */
3233
3234 static void
3235 new_dfc_convert_now_damn_it (const void *src, Bytecount src_size,
3236 enum new_dfc_src_type type,
3237 void **dst, Bytecount *dst_size,
3238 Lisp_Object codesys)
3239 {
3240 /* #### In the case of alloca(), it would be a bit more efficient, for
3241 small strings, to use static Dynarr's like are used internally in
3242 TO_*_FORMAT(), or some other way of avoiding malloc() followed by
3243 free(). I doubt it really matters, though. */
3244
3245 switch (type)
3246 {
3247 case DFC_EXTERNAL:
3248 TO_INTERNAL_FORMAT (C_STRING, src,
3249 MALLOC, (*dst, *dst_size), codesys);
3250 break;
3251
3252 case DFC_SIZED_EXTERNAL:
3253 TO_INTERNAL_FORMAT (DATA, (src, src_size),
3254 MALLOC, (*dst, *dst_size), codesys);
3255 break;
3256
3257 case DFC_INTERNAL:
3258 TO_EXTERNAL_FORMAT (C_STRING, src,
3259 MALLOC, (*dst, *dst_size), codesys);
3260 break;
3261
3262 case DFC_SIZED_INTERNAL:
3263 TO_EXTERNAL_FORMAT (DATA, (src, src_size),
3264 MALLOC, (*dst, *dst_size), codesys);
3265 break;
3266
3267 case DFC_LISP_STRING:
3268 TO_EXTERNAL_FORMAT (LISP_STRING, VOID_TO_LISP (src),
3269 MALLOC, (*dst, *dst_size), codesys);
3270 break;
3271
3272 default:
3273 abort ();
3274 }
3275 }
3276
3277 void *
3278 new_dfc_convert_malloc (const void *src, Bytecount src_size,
3279 enum new_dfc_src_type type, Lisp_Object codesys)
3280 {
3281 void *dst;
3282 Bytecount dst_size;
3283
3284 new_dfc_convert_now_damn_it (src, src_size, type, &dst, &dst_size, codesys);
3285 return dst;
3286 }
3287
3288 /* For alloca(), things are trickier because the calling function needs to
3289 allocate. This means that the caller needs to do the following:
3290
3291 (a) invoke us to do the conversion, remember the data and return the size.
3292 (b) alloca() the proper size.
3293 (c) invoke us again to copy the data.
3294
3295 We need to handle the possibility of two or more invocations of the
3296 converter in the same expression. In such cases it's conceivable that
3297 the evaluation of the sub-expressions will be overlapping (e.g. one size
3298 function called, then the other one called, then the copy functions
3299 called). To handle this, we keep a list of active data, indexed by the
3300 src expression. (We use the stringize operator to avoid evaluating the
3301 expression multiple times.) If the caller uses the exact same src
3302 expression twice in two converter calls in the same subexpression, we
3303 will lose, but at least we can check for this and abort(). We could
3304 conceivably try to index on other parameters as well, but there is not
3305 really any point. */
3306
3307 typedef struct
3308 {
3309 const char *srctext;
3310 void *dst;
3311 Bytecount dst_size;
3312 } dfc_e2c_vals;
3313
3314 typedef struct
3315 {
3316 Dynarr_declare (dfc_e2c_vals);
3317 } dfc_e2c_vals_dynarr;
3318
3319 static dfc_e2c_vals_dynarr *active_dfc_e2c;
3320
3321 static int
3322 find_pos_of_existing_active_dfc_e2c (const char *srctext)
3323 {
3324 dfc_e2c_vals *vals = NULL;
3325 int i;
3326
3327 for (i = 0; i < Dynarr_length (active_dfc_e2c); i++)
3328 {
3329 vals = Dynarr_atp (active_dfc_e2c, i);
3330 if (vals->srctext == srctext)
3331 return i;
3332 }
3333
3334 return -1;
3335 }
3336
3337 void *
3338 new_dfc_convert_alloca (const char *srctext, void *alloca_data)
3339 {
3340 dfc_e2c_vals *vals;
3341 int i = find_pos_of_existing_active_dfc_e2c (srctext);
3342
3343 assert (i >= 0);
3344 vals = Dynarr_atp (active_dfc_e2c, i);
3345 assert (alloca_data);
3346 memcpy (alloca_data, vals->dst, vals->dst_size + 2);
3347 xfree (vals->dst);
3348 Dynarr_delete (active_dfc_e2c, i);
3349 return alloca_data;
3350 }
3351
3352 Bytecount
3353 new_dfc_convert_size (const char *srctext, const void *src,
3354 Bytecount src_size, enum new_dfc_src_type type,
3355 Lisp_Object codesys)
3356 {
3357 dfc_e2c_vals vals;
3358
3359 assert (find_pos_of_existing_active_dfc_e2c (srctext) < 0);
3360
3361 vals.srctext = srctext;
3362
3363 new_dfc_convert_now_damn_it (src, src_size, type, &vals.dst, &vals.dst_size,
3364 codesys);
3365
3366 Dynarr_add (active_dfc_e2c, vals);
3367 /* The size is always + 2 because we have double zero-termination at the
3368 end of all data (for Unicode-correctness). */
3369 return vals.dst_size + 2;
3370 }
3371
3222 3372
3223 /************************************************************************/ 3373 /************************************************************************/
3224 /* Basic Ichar functions */ 3374 /* Basic Ichar functions */
3225 /************************************************************************/ 3375 /************************************************************************/
3226 3376
3738 3888
3739 conversion_in_dynarr_list = Dynarr_new2 (Ibyte_dynarr_dynarr, 3889 conversion_in_dynarr_list = Dynarr_new2 (Ibyte_dynarr_dynarr,
3740 Ibyte_dynarr *); 3890 Ibyte_dynarr *);
3741 conversion_out_dynarr_list = Dynarr_new2 (Extbyte_dynarr_dynarr, 3891 conversion_out_dynarr_list = Dynarr_new2 (Extbyte_dynarr_dynarr,
3742 Extbyte_dynarr *); 3892 Extbyte_dynarr *);
3893 active_dfc_e2c = Dynarr_new (dfc_e2c_vals);
3743 3894
3744 for (i = 0; i <= MAX_BYTEBPOS_GAP_SIZE_3; i++) 3895 for (i = 0; i <= MAX_BYTEBPOS_GAP_SIZE_3; i++)
3745 three_to_one_table[i] = i / 3; 3896 three_to_one_table[i] = i / 3;
3746 } 3897 }
3747 3898