diff options
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/src/image.c b/src/image.c index e236b389210..643b3d0a1f4 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -803,17 +803,23 @@ valid_image_p (Lisp_Object object) | |||
| 803 | { | 803 | { |
| 804 | Lisp_Object tail = XCDR (object); | 804 | Lisp_Object tail = XCDR (object); |
| 805 | FOR_EACH_TAIL_SAFE (tail) | 805 | FOR_EACH_TAIL_SAFE (tail) |
| 806 | if (EQ (XCAR (tail), QCtype)) | 806 | { |
| 807 | { | 807 | if (EQ (XCAR (tail), QCtype)) |
| 808 | tail = XCDR (tail); | 808 | { |
| 809 | if (CONSP (tail)) | 809 | tail = XCDR (tail); |
| 810 | { | 810 | if (CONSP (tail)) |
| 811 | struct image_type const *type = lookup_image_type (XCAR (tail)); | 811 | { |
| 812 | if (type) | 812 | struct image_type const *type = |
| 813 | return type->valid_p (object); | 813 | lookup_image_type (XCAR (tail)); |
| 814 | } | 814 | if (type) |
| 815 | break; | 815 | return type->valid_p (object); |
| 816 | } | 816 | } |
| 817 | break; | ||
| 818 | } | ||
| 819 | tail = XCDR (tail); | ||
| 820 | if (! CONSP (tail)) | ||
| 821 | return false; | ||
| 822 | } | ||
| 817 | } | 823 | } |
| 818 | 824 | ||
| 819 | return false; | 825 | return false; |
| @@ -899,7 +905,7 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords, | |||
| 899 | return false; | 905 | return false; |
| 900 | 906 | ||
| 901 | plist = XCDR (spec); | 907 | plist = XCDR (spec); |
| 902 | while (CONSP (plist)) | 908 | FOR_EACH_TAIL_SAFE (plist) |
| 903 | { | 909 | { |
| 904 | Lisp_Object key, value; | 910 | Lisp_Object key, value; |
| 905 | 911 | ||
| @@ -913,7 +919,6 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords, | |||
| 913 | if (!CONSP (plist)) | 919 | if (!CONSP (plist)) |
| 914 | return false; | 920 | return false; |
| 915 | value = XCAR (plist); | 921 | value = XCAR (plist); |
| 916 | plist = XCDR (plist); | ||
| 917 | 922 | ||
| 918 | /* Find key in KEYWORDS. Error if not found. */ | 923 | /* Find key in KEYWORDS. Error if not found. */ |
| 919 | for (i = 0; i < nkeywords; ++i) | 924 | for (i = 0; i < nkeywords; ++i) |
| @@ -921,7 +926,7 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords, | |||
| 921 | break; | 926 | break; |
| 922 | 927 | ||
| 923 | if (i == nkeywords) | 928 | if (i == nkeywords) |
| 924 | continue; | 929 | goto maybe_done; |
| 925 | 930 | ||
| 926 | /* Record that we recognized the keyword. If a keyword | 931 | /* Record that we recognized the keyword. If a keyword |
| 927 | was found more than once, it's an error. */ | 932 | was found more than once, it's an error. */ |
| @@ -1009,14 +1014,20 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords, | |||
| 1009 | if (EQ (key, QCtype) | 1014 | if (EQ (key, QCtype) |
| 1010 | && !(EQ (type, value) || EQ (type, Qnative_image))) | 1015 | && !(EQ (type, value) || EQ (type, Qnative_image))) |
| 1011 | return false; | 1016 | return false; |
| 1012 | } | ||
| 1013 | 1017 | ||
| 1014 | /* Check that all mandatory fields are present. */ | 1018 | maybe_done: |
| 1015 | for (i = 0; i < nkeywords; ++i) | 1019 | if (EQ (XCDR (plist), Qnil)) |
| 1016 | if (keywords[i].count < keywords[i].mandatory_p) | 1020 | { |
| 1017 | return false; | 1021 | /* Check that all mandatory fields are present. */ |
| 1022 | for (i = 0; i < nkeywords; ++i) | ||
| 1023 | if (keywords[i].mandatory_p && keywords[i].count == 0) | ||
| 1024 | return false; | ||
| 1025 | |||
| 1026 | return true; | ||
| 1027 | } | ||
| 1028 | } | ||
| 1018 | 1029 | ||
| 1019 | return NILP (plist); | 1030 | return false; |
| 1020 | } | 1031 | } |
| 1021 | 1032 | ||
| 1022 | 1033 | ||
| @@ -1031,9 +1042,8 @@ image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found) | |||
| 1031 | 1042 | ||
| 1032 | eassert (valid_image_p (spec)); | 1043 | eassert (valid_image_p (spec)); |
| 1033 | 1044 | ||
| 1034 | for (tail = XCDR (spec); | 1045 | tail = XCDR (spec); |
| 1035 | CONSP (tail) && CONSP (XCDR (tail)); | 1046 | FOR_EACH_TAIL_SAFE (tail) |
| 1036 | tail = XCDR (XCDR (tail))) | ||
| 1037 | { | 1047 | { |
| 1038 | if (EQ (XCAR (tail), key)) | 1048 | if (EQ (XCAR (tail), key)) |
| 1039 | { | 1049 | { |
| @@ -1041,6 +1051,9 @@ image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found) | |||
| 1041 | *found = 1; | 1051 | *found = 1; |
| 1042 | return XCAR (XCDR (tail)); | 1052 | return XCAR (XCDR (tail)); |
| 1043 | } | 1053 | } |
| 1054 | tail = XCDR (tail); | ||
| 1055 | if (! CONSP (tail)) | ||
| 1056 | break; | ||
| 1044 | } | 1057 | } |
| 1045 | 1058 | ||
| 1046 | if (found) | 1059 | if (found) |
| @@ -1584,6 +1597,16 @@ make_image_cache (void) | |||
| 1584 | return c; | 1597 | return c; |
| 1585 | } | 1598 | } |
| 1586 | 1599 | ||
| 1600 | /* Compare two lists (one of which must be proper), comparing each | ||
| 1601 | element with `eq'. */ | ||
| 1602 | static bool | ||
| 1603 | equal_lists (Lisp_Object a, Lisp_Object b) | ||
| 1604 | { | ||
| 1605 | while (CONSP (a) && CONSP (b) && EQ (XCAR (a), XCAR (b))) | ||
| 1606 | a = XCDR (a), b = XCDR (b); | ||
| 1607 | |||
| 1608 | return EQ (a, b); | ||
| 1609 | } | ||
| 1587 | 1610 | ||
| 1588 | /* Find an image matching SPEC in the cache, and return it. If no | 1611 | /* Find an image matching SPEC in the cache, and return it. If no |
| 1589 | image is found, return NULL. */ | 1612 | image is found, return NULL. */ |
| @@ -1610,7 +1633,7 @@ search_image_cache (struct frame *f, Lisp_Object spec, EMACS_UINT hash) | |||
| 1610 | 1633 | ||
| 1611 | for (img = c->buckets[i]; img; img = img->next) | 1634 | for (img = c->buckets[i]; img; img = img->next) |
| 1612 | if (img->hash == hash | 1635 | if (img->hash == hash |
| 1613 | && !NILP (Fequal (img->spec, spec)) | 1636 | && !equal_lists (img->spec, spec) |
| 1614 | && img->frame_foreground == FRAME_FOREGROUND_PIXEL (f) | 1637 | && img->frame_foreground == FRAME_FOREGROUND_PIXEL (f) |
| 1615 | && img->frame_background == FRAME_BACKGROUND_PIXEL (f)) | 1638 | && img->frame_background == FRAME_BACKGROUND_PIXEL (f)) |
| 1616 | break; | 1639 | break; |