about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorarg@mig29 <unknown>2006-12-05 10:30:31 +0100
committerarg@mig29 <unknown>2006-12-05 10:30:31 +0100
commit9bd9ea423e5b4c4bfee65a8495c5d611b242f7b7 (patch)
treefa9d9c74f8f70f704f21e015b902b39c4abf031a
parent99964398e7e7e8b23952f7f1997bf78d1afa8e7b (diff)
downloaddwm-9bd9ea423e5b4c4bfee65a8495c5d611b242f7b7.tar.gz
enforcing using fontsets even if they are incomplete for some encodings
-rw-r--r--config.mk2
-rw-r--r--draw.c4
2 files changed, 1 insertions, 5 deletions
diff --git a/config.mk b/config.mk
index b325d05..6961464 100644
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,5 @@
 # dwm version
-VERSION = 2.5.1
+VERSION = 2.6
 
 # Customize below to fit your system
 
diff --git a/draw.c b/draw.c
index a67ac58..c0b233f 100644
--- a/draw.c
+++ b/draw.c
@@ -179,10 +179,6 @@ setfont(const char *fontstr) {
 		while(n--)
 			fprintf(stderr, "missing fontset: %s\n", missing[n]);
 		XFreeStringList(missing);
-		if(dc.font.set) {
-			XFreeFontSet(dpy, dc.font.set);
-			dc.font.set = NULL;
-		}
 	}
 	if(dc.font.set) {
 		XFontSetExtents *font_extents;
f11c364bf78'>6c96a437 ^
795f5244 ^
16386f76 ^
a0fc38c9 ^
e236973b ^
a0fc38c9 ^
ba1fb981 ^
2b250717 ^
a0fc38c9 ^

3c31b721 ^
bb7142db ^
e0659ab3 ^
a0fc38c9 ^




e236973b ^
a0fc38c9 ^
e236973b ^

a0fc38c9 ^






5f98a10c ^
1ead3562 ^
3c31b721 ^
a0fc38c9 ^
3c31b721 ^
a0fc38c9 ^

5f98a10c ^
1ead3562 ^
192d59d3 ^
a0fc38c9 ^
192d59d3 ^
a0fc38c9 ^

5f98a10c ^
1ead3562 ^
192d59d3 ^
a0fc38c9 ^
192d59d3 ^
a0fc38c9 ^

5f98a10c ^
1ead3562 ^
192d59d3 ^
a0fc38c9 ^
192d59d3 ^
a0fc38c9 ^
bb7142db ^
1ead3562 ^
192d59d3 ^

bb7142db ^



9e32e473 ^







1193171f ^






3bfd75fc ^
1ead3562 ^
d52406cc ^

3bfd75fc ^



9e32e473 ^

1ead3562 ^
192d59d3 ^
d52406cc ^
b436291f ^
9e32e473 ^
b436291f ^
a0fc38c9 ^
691b529e ^
3bfd75fc ^

9e32e473 ^

1193171f ^
93d4cc93 ^
016599f1 ^


4d238fd7 ^
dfdbcbab ^

4d238fd7 ^



dfdbcbab ^
4d238fd7 ^

af023b32 ^

4d238fd7 ^
016599f1 ^
4d238fd7 ^
7f193a0e ^

49620728 ^
3473c63a ^

b5f2a629 ^
4d238fd7 ^
7136ddd5 ^

4d238fd7 ^
dfdbcbab ^
4d238fd7 ^


c6034af3 ^

3473c63a ^
af023b32 ^
93d4cc93 ^
af023b32 ^
93d4cc93 ^
af023b32 ^
af023b32 ^


f8b0b04d ^





a0fc38c9 ^

d785efe5 ^











f8b0b04d ^







86c715d7 ^

f8b0b04d ^

58a9f7c3 ^

7136ddd5 ^



3473c63a ^

af023b32 ^

af023b32 ^



4ecab182 ^



af023b32 ^
a0fc38c9 ^

3473c63a ^

af023b32 ^

af023b32 ^



4ecab182 ^



af023b32 ^
a0fc38c9 ^
a0d7a155 ^
3473c63a ^

3bfd75fc ^

af023b32 ^
3bfd75fc ^


3473c63a ^
9e32e473 ^




3473c63a ^
c6034af3 ^
af023b32 ^
67f969b9 ^
c4e143d6 ^
65c905fe ^
67f969b9 ^
795f5244 ^
4e49b29e ^

db69ad7a ^

af023b32 ^






db69ad7a ^

3473c63a ^
af023b32 ^

af023b32 ^






a0d7a155 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277


                                                                              





                                                                            
 
                      
                                                      

       
                                                
                                                                                               
                                              
                                                          
                                                   
                                
                             
                                
                  
                                                           
                                                                                                                        

                
                                                         
                                                                              
                                                                                                                                                                                                    




                                             
                                    
                

                                    






                                     
                     
          
                         
 
                                                            

                                            
                     
          
                        
 
                                                                 

                                              
                     
          
                                   
 
                                                                 

                                              
                     
          
                          
 
                                                                   
 
                                           
          

                                 



                              







                                                                       






                                             
                                           
          

                       



                             

                                              
          
                  
                      
 
                                                               
 
       
                                 

                                                              

                                                                
                                                                  
                                      


               
                                                          

                                                                                



                                         
                                     

                                                   

                                                                        
                                                            
   
                                        

 
                                   

                                                                     
                                              
                                                                                     

                                                                                
                                   
                                


                                                  

 
                                                                       
                              
                        
                                               
                                           
                   


                                                         





                                                                                                 

 











                                                      







                                                                            

                                        

 

           



                                   

                                          

                             



                                         



                                                                 
                                                         

 

                                            

                               



                                           



                                                                 
                                                           
 
 

                                            

                                  
                                  


                                                       
                                      




                                                                                        
                                           
                            
                                  
                      
                                                      
                                     
   
                                                      

 

                                              






                                                       

 
                                      

                              






                                          
 
//: Introduce a new transform to perform various checks in instructions before
//: we start running them. It'll be extensible, so that we can add checks for
//: new recipes as we extend 'run' to support them.
//:
//: Doing checking in a separate part complicates things, because the values
//: of variables in memory and the processor (current_recipe_name,
//: current_instruction) aren't available at checking time. If I had a more
//: sophisticated layer system I'd introduce the simpler version first and
//: transform it in a separate layer or set of layers.

:(before "End Checks")
Transform.push_back(check_instruction);  // idempotent

:(code)
void check_instruction(const recipe_ordinal r) {
  trace(9991, "transform") << "--- perform checks for recipe " << get(Recipe, r).name << end();
  map<string, vector<type_ordinal> > metadata;
  for (int i = 0;  i < SIZE(get(Recipe, r).steps);  ++i) {
    instruction& inst = get(Recipe, r).steps.at(i);
    if (inst.is_label) continue;
    switch (inst.operation) {
      // Primitive Recipe Checks
      case COPY: {
        if (SIZE(inst.products) > SIZE(inst.ingredients)) {
          raise << maybe(get(Recipe, r).name) << "too many products in '" << to_original_string(inst) << "'\n" << end();
          break;
        }
        for (int i = 0;  i < SIZE(inst.products);  ++i) {
          if (!types_coercible(inst.products.at(i), inst.ingredients.at(i))) {
            raise << maybe(get(Recipe, r).name) << "can't copy '" << inst.ingredients.at(i).original_string << "' to '" << inst.products.at(i).original_string << "'; types don't match\n" << end();
            goto finish_checking_instruction;
          }
        }
        break;
      }
      // End Primitive Recipe Checks
      default: {
        // Defined Recipe Checks
        // End Defined Recipe Checks
      }
    }
    finish_checking_instruction:;
  }
}

:(scenario copy_checks_reagent_count)
% Hide_errors = true;
def main [
  1:num, 2:num <- copy 34
]
+error: main: too many products in '1:num, 2:num <- copy 34'

:(scenario write_scalar_to_array_disallowed)
% Hide_errors = true;
def main [
  1:array:num <- copy 34
]
+error: main: can't copy '34' to '1:array:num'; types don't match

:(scenario write_scalar_to_array_disallowed_2)
% Hide_errors = true;
def main [
  1:num, 2:array:num <- copy 34, 35
]
+error: main: can't copy '35' to '2:array:num'; types don't match

:(scenario write_scalar_to_address_disallowed)
% Hide_errors = true;
def main [
  1:address:num <- copy 34
]
+error: main: can't copy '34' to '1:address:num'; types don't match

:(scenario write_address_to_number_allowed)
def main [
  1:address:num <- copy 12/unsafe
  2:num <- copy 1:address:num
]
+mem: storing 12 in location 2
$error: 0

:(scenario write_address_to_character_disallowed)
% Hide_errors = true;
def main [
  1:address:num <- copy 12/unsafe
  2:char <- copy 1:address:num
]
+error: main: can't copy '1:address:num' to '2:char'; types don't match

:(scenario write_number_to_character_allowed)
def main [
  1:num <- copy 97
  2:char <- copy 1:num
]
$error: 0

:(scenario write_boolean_to_number_allowed)
def main [
  1:bool <- copy 1/true
  2:num <- copy 1:bool
]
+mem: storing 1 in location 2
$error: 0

:(scenario write_number_to_boolean_disallowed)
% Hide_errors = true;
def main [
  1:num <- copy 34
  2:bool <- copy 1:num
]
+error: main: can't copy '1:num' to '2:bool'; types don't match

:(code)
// types_match with some leniency
bool types_coercible(const reagent& to, const reagent& from) {
  if (types_match(to, from)) return true;
  if (is_mu_address(from) && is_real_mu_number(to)) return true;
  if (is_mu_boolean(from) && is_real_mu_number(to)) return true;
  if (is_real_mu_number(from) && is_mu_character(to)) return true;
  // End types_coercible Special-cases
  return false;
}

bool types_match(const reagent& to, const reagent& from) {
  // to sidestep type-checking, use /unsafe in the source.
  // this will be highlighted in red inside vim. just for setting up some tests.
  if (is_unsafe(from)) return true;
  if (is_literal(from)) {
    if (is_mu_array(to)) return false;
    // End Matching Types For Literal(to)
    // allow writing 0 to any address
    if (is_mu_address(to)) return from.name == "0";
    if (!to.type) return false;
    if (to.type->atom && to.type->value == get(Type_ordinal, "boolean"))
      return from.name == "0" || from.name == "1";
    return size_of(to) == 1;  // literals are always scalars
  }
  return types_strictly_match(to, from);
}

//: copy arguments for later layers
bool types_strictly_match(reagent/*copy*/ to, reagent/*copy*/ from) {
  // End Preprocess types_strictly_match(reagent to, reagent from)
  if (to.type == NULL) return false;  // error
  if (is_literal(from) && to.type->value == get(Type_ordinal, "number")) return true;
  // to sidestep type-checking, use /unsafe in the source.
  // this will be highlighted in red inside vim. just for setting up some tests.
  if (is_unsafe(from)) return true;
  // '_' never raises type error
  if (is_dummy(to)) return true;
  if (!to.type) return !from.type;
  return types_strictly_match(to.type, from.type);
}

bool types_strictly_match(const type_tree* to, const type_tree* from) {
  if (from == to) return true;
  if (!to) return false;
  if (!from) return to->atom && to->value == 0;
  if (from->atom != to->atom) return false;
  if (from->atom) {
    if (from->value == -1) return from->name == to->name;
    return from->value == to->value;
  }
  if (types_strictly_match(to->left, from->left) && types_strictly_match(to->right, from->right))
    return true;
  // fallback: (x) == x
  if (to->right == NULL && types_strictly_match(to->left, from)) return true;
  if (from->right == NULL && types_strictly_match(to, from->left)) return true;
  return false;
}

void test_unknown_type_does_not_match_unknown_type() {
  reagent a("a:foo");
  reagent b("b:bar");
  CHECK(!types_strictly_match(a, b));
}

void test_unknown_type_matches_itself() {
  reagent a("a:foo");
  reagent b("b:foo");
  CHECK(types_strictly_match(a, b));
}

void test_type_abbreviations_match_raw_types() {
  put(Type_abbreviations, "text", new_type_tree("address:array:character"));
  // a has type (address buffer (address array character))
  reagent a("a:address:buffer:text");
  expand_type_abbreviations(a.type);
  // b has type (address buffer address array character)
  reagent b("b:address:buffer:address:array:character");
  CHECK(types_strictly_match(a, b));
  delete Type_abbreviations["text"];
  put(Type_abbreviations, "text", NULL);
}

//: helpers

bool is_unsafe(const reagent& r) {
  return has_property(r, "unsafe");
}

bool is_mu_array(reagent/*copy*/ r) {
  // End Preprocess is_mu_array(reagent r)
  return is_mu_array(r.type);
}
bool is_mu_array(const type_tree* type) {
  if (!type) return false;
  if (is_literal(type)) return false;
  if (type->atom) return false;
  if (!type->left->atom) {
    raise << "invalid type " << to_string(type) << '\n' << end();
    return false;
  }
  return type->left->value == get(Type_ordinal, "array");
}

bool is_mu_address(reagent/*copy*/ r) {
  // End Preprocess is_mu_address(reagent r)
  return is_mu_address(r.type);
}
bool is_mu_address(const type_tree* type) {
  if (!type) return false;
  if (is_literal(type)) return false;
  if (type->atom) return false;
  if (!type->left->atom) {
    raise << "invalid type " << to_string(type) << '\n' << end();
    return false;
  }
  return type->left->value == get(Type_ordinal, "address");
}

bool is_mu_boolean(reagent/*copy*/ r) {
  // End Preprocess is_mu_boolean(reagent r)
  if (!r.type) return false;
  if (is_literal(r)) return false;
  if (!r.type->atom) return false;
  return r.type->value == get(Type_ordinal, "boolean");
}

bool is_mu_number(reagent/*copy*/ r) {
  if (is_mu_character(r.type)) return true;  // permit arithmetic on unicode code points
  return is_real_mu_number(r);
}

bool is_real_mu_number(reagent/*copy*/ r) {
  // End Preprocess is_mu_number(reagent r)
  if (!r.type) return false;
  if (!r.type->atom) return false;
  if (is_literal(r)) {
    return r.type->name == "literal-fractional-number"
        || r.type->name == "literal";
  }
  return r.type->value == get(Type_ordinal, "number");
}

bool is_mu_character(reagent/*copy*/ r) {
  // End Preprocess is_mu_character(reagent r)
  return is_mu_character(r.type);
}
bool is_mu_character(const type_tree* type) {
  if (!type) return false;
  if (!type->atom) return false;
  if (is_literal(type)) return false;
  return type->value == get(Type_ordinal, "character");
}

bool is_mu_scalar(reagent/*copy*/ r) {
  return is_mu_scalar(r.type);
}
bool is_mu_scalar(const type_tree* type) {
  if (!type) return false;
  if (is_mu_address(type)) return true;
  if (!type->atom) return false;
  if (is_literal(type))
    return type->name != "literal-string";
  return size_of(type) == 1;
}