You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
generate-accessors: fix stale examples and redundant code
The examples in generate-accessors.md were generated with an older
version of the tool:
- excluded members leave no trace; the phantom "no accessors" comment
has been removed
- car struct accessors were missing their KernelDoc comments
- accessors.c used 4-space indentation instead of tabs
- accessors.ld was not shown at all
In generate-accessors.py, collapse the redundant two-branch isdigit()
check in emit_src_setter_chararray() — both branches produced identical
output.
Signed-off-by: Martin Belanger <[email protected]>
*@model: New string; a copy is stored. Pass NULL to clear.
224
+
*/
222
225
void car_set_model(struct car *p, const char *model);
226
+
227
+
/**
228
+
* car_get_model() - Get model.
229
+
*@p: The &struct car instance to query.
230
+
*
231
+
* Return: The value of the model field, or NULL if not set.
232
+
*/
223
233
const char *car_get_model(const struct car *p);
224
234
235
+
/**
236
+
* car_set_year() - Set year.
237
+
*@p: The &struct car instance to update.
238
+
*@year: Value to assign to the year field.
239
+
*/
225
240
void car_set_year(struct car *p, int year);
241
+
242
+
/**
243
+
* car_get_year() - Get year.
244
+
*@p: The &struct car instance to query.
245
+
*
246
+
* Return: The value of the year field.
247
+
*/
226
248
int car_get_year(const struct car *p);
227
249
250
+
/**
251
+
* car_get_vin() - Get vin.
252
+
*@p: The &struct car instance to query.
253
+
*
254
+
* Return: The value of the vin field, or NULL if not set.
255
+
*/
228
256
const char *car_get_vin(const struct car *p);
229
257
230
258
#endif/* _ACCESSORS_H_ */
231
259
```
232
260
233
-
> **Note:** The `secret` member is absent because of `//!accessors:none`. The `role` member has only a getter because of `//!accessors:readonly`. The `id` and `vin` members have only getters because they are declared `const`.
261
+
> **Note:** The `secret` member is absent because of `//!accessors:none` — excluded members leave no trace in the output. The `role` member has only a getter because of `//!accessors:readonly`. The `id` and `vin` members have only getters because they are declared `const`.
234
262
235
263
### Generated `accessors.c`
236
264
@@ -251,37 +279,89 @@ const char *car_get_vin(const struct car *p);
251
279
252
280
__public voidperson_set_name(struct person *p, const char *name)
253
281
{
254
-
free(p->name);
255
-
p->name = name ? strdup(name) : NULL;
282
+
free(p->name);
283
+
p->name = name ? strdup(name) : NULL;
256
284
}
257
285
258
286
__public const char *person_get_name(const struct person *p)
259
287
{
260
-
return p->name;
288
+
return p->name;
261
289
}
262
290
263
291
__public void person_set_age(struct person *p, int age)
264
292
{
265
-
p->age = age;
293
+
p->age = age;
266
294
}
267
295
268
296
__public int person_get_age(const struct person *p)
269
297
{
270
-
return p->age;
298
+
return p->age;
271
299
}
272
300
273
301
__public const char *person_get_id(const struct person *p)
274
302
{
275
-
return p->id;
303
+
return p->id;
276
304
}
277
305
278
306
__public const char *person_get_role(const struct person *p)
__public void car_set_model(struct car *p, const char *model)
316
+
{
317
+
free(p->model);
318
+
p->model = model ? strdup(model) : NULL;
319
+
}
320
+
321
+
__public const char *car_get_model(const struct car *p)
322
+
{
323
+
return p->model;
324
+
}
325
+
326
+
__public void car_set_year(struct car *p, int year)
327
+
{
328
+
p->year = year;
329
+
}
330
+
331
+
__public int car_get_year(const struct car *p)
332
+
{
333
+
return p->year;
281
334
}
282
335
283
-
/* ... struct car accessors follow the same pattern ... */
336
+
__public const char *car_get_vin(const struct car *p)
337
+
{
338
+
return p->vin;
339
+
}
340
+
```
341
+
342
+
### Generated `accessors.ld`
343
+
284
344
```
345
+
# SPDX-License-Identifier: LGPL-2.1-or-later
346
+
/* ... banner ... */
347
+
348
+
LIBNVME_ACCESSORS_3 {
349
+
global:
350
+
person_get_name;
351
+
person_set_name;
352
+
person_get_age;
353
+
person_set_age;
354
+
person_get_id;
355
+
person_get_role;
356
+
car_get_model;
357
+
car_set_model;
358
+
car_get_year;
359
+
car_set_year;
360
+
car_get_vin;
361
+
};
362
+
```
363
+
364
+
> **Note:** Only symbols for members that have accessors generated appear in the linker script. The `secret` member (excluded via `//!accessors:none`) and the write-only `token` example would have no getter entry. The version node name `LIBNVME_ACCESSORS_3` is hardcoded in the generator.
0 commit comments