lkml.org 
[lkml]   [2014]   [Jul]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Subject[PATCH 0/9] use correct structure type name in sizeof
    Date
    These patches fix typos in the name of a type referenced in a sizeof
    command. These problems are not caught by the compiler, because they have
    no impact on execution - the size of a pointer is independent of the size
    of the pointed value.

    The semantic patch that finds these problems is shown below
    (http://coccinelle.lip6.fr/). This semantic patch distinguishes between
    structures that are defined in C files, and thus are expected to be visible
    in only that file, and structures that are defined in header files, which
    could potential be visible everywhere. This distinction seems to be
    unnecessary in practice, though.

    <smpl>
    virtual after_start

    @initialize:ocaml@
    @@

    type fl = C of string | H

    let structures = Hashtbl.create 101
    let restarted = ref false

    let add_if_not_present _ =
    if not !restarted
    then
    begin
    restarted := true;
    let it = new iteration() in
    it#add_virtual_rule After_start;
    it#register()
    end

    let hashadd str file =
    let cell =
    try Hashtbl.find structures str
    with Not_found ->
    let cell = ref [] in
    Hashtbl.add structures str cell;
    cell in
    if not (List.mem file !cell) then cell := file :: !cell

    let get_file fl =
    if Filename.check_suffix fl ".c"
    then C fl
    else H

    @script:ocaml depends on !after_start@
    @@
    add_if_not_present()

    @r depends on !after_start@
    identifier nm;
    position p;
    @@

    struct nm@p { ... };

    @script:ocaml@
    nm << r.nm;
    p << r.p;
    @@

    hashadd nm (get_file (List.hd p).file)

    // -------------------------------------------------------------------------

    @sz depends on after_start@
    identifier nm;
    position p;
    @@

    sizeof(struct nm@p *)

    @script:ocaml@
    nm << sz.nm;
    p << sz.p;
    @@

    try
    let allowed = !(Hashtbl.find structures nm) in
    if List.mem H allowed or List.mem (get_file (List.hd p).file) allowed
    then ()
    else print_main nm p
    with Not_found -> print_main nm p
    </smpl>



    \
     
     \ /
      Last update: 2014-07-29 21:01    [W:3.413 / U:0.096 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site