This assertion was removed in
1c349c62305d432abf0fa2b6e3f5d754fe4cab79
because the assumption was invalid during set_intervals_multibyte_1.
So we change set_intervals_multibyte_1 to solve the problem in the same
way as in the rest of Fset_buffer_multibyte, which actually simplifies
the code.
* src/buffer.c (advance_to_char_boundary): Not static any more.
* src/buffer.h (advance_to_char_boundary): Add prototype.
* src/intervals.c (set_intervals_multibyte_1): Use it.
/* Advance BYTE_POS up to a character boundary
and return the adjusted position. */
-static ptrdiff_t
+ptrdiff_t
advance_to_char_boundary (ptrdiff_t byte_pos)
{
int c;
/* Do this last, so it can calculate the new correspondences
between chars and bytes. */
+ /* FIXME: Is it worth the trouble, really? Couldn't we just throw
+ away all the text-properties instead of trying to guess how
+ to adjust them? AFAICT the result is not reliable anyway. */
set_intervals_multibyte (1);
}
#define BYTE_TO_CHAR(bytepos) \
(buf_bytepos_to_charpos (current_buffer, bytepos))
+/* For those very rare cases where you may have a "random" pointer into
+ the middle of a multibyte char, this moves to the next boundary. */
+extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos);
+
/* Convert PTR, the address of a byte in the buffer, into a byte position. */
#define PTR_BYTE_POS(ptr) \
if (multi_flag)
{
ptrdiff_t temp;
- left_end_byte = start_byte + LEFT_TOTAL_LENGTH (i);
+ left_end_byte
+ = advance_to_char_boundary (start_byte + LEFT_TOTAL_LENGTH (i));
left_end = BYTE_TO_CHAR (left_end_byte);
-
- temp = CHAR_TO_BYTE (left_end);
-
- /* If LEFT_END_BYTE is in the middle of a character,
- adjust it and LEFT_END to a char boundary. */
- if (left_end_byte > temp)
- {
- left_end_byte = temp;
- }
- if (left_end_byte < temp)
- {
- left_end--;
- left_end_byte = CHAR_TO_BYTE (left_end);
- }
+ eassert (CHAR_TO_BYTE (left_end) == left_end_byte);
}
else
{
{
ptrdiff_t temp;
- right_start_byte = end_byte - RIGHT_TOTAL_LENGTH (i);
+ right_start_byte
+ = advance_to_char_boundary (end_byte - RIGHT_TOTAL_LENGTH (i));
right_start = BYTE_TO_CHAR (right_start_byte);
-
- /* If RIGHT_START_BYTE is in the middle of a character,
- adjust it and RIGHT_START to a char boundary. */
- temp = CHAR_TO_BYTE (right_start);
-
- if (right_start_byte < temp)
- {
- right_start_byte = temp;
- }
- if (right_start_byte > temp)
- {
- right_start++;
- right_start_byte = CHAR_TO_BYTE (right_start);
- }
+ eassert (CHAR_TO_BYTE (right_start) == right_start_byte);
}
else
{
if (best_above == best_above_byte)
return bytepos;
+ /* Check bytepos is not in the middle of a character. */
+ eassert (bytepos >= BUF_Z_BYTE (b)
+ || CHAR_HEAD_P (BUF_FETCH_BYTE (b, bytepos)));
+
best_below = BEG;
best_below_byte = BEG_BYTE;