Re: what is a wrapper function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/2/06, Md.Zaheeruddin Khan <zaheer031@xxxxxxxxx> wrote:
> HI ,
>  I want 2 know what is a wrapper function and where is it used?

A wrapper function is simply a function that "wraps" around a call to
another function.
They are used for different purposes, one use is to preserve backwards
compatibility until all users of an old function can be updated to
call a new function. An example would be when verify_area() was
replaced with access_ok(), verify_area was turned into a wrapper
around a call to access_ok() - new code would just call access_ok()
directly and old code could continue to call verify_area() as it
always had until someone had the time to change the call. Once all
calls of verify_area() were replaced with calls to access_ok() we
removed the wrapper.
Another use of wrapper functions can be to ensure correctness. For
example, if some lock should always be taken before a call to some
function and released immidiately after the function returns you would
often create a small wrapper around the taking of the lock, call of
function and release of the lock and then call the wrapper instead of
doing all 3 steps everywhere (and possibly getting it wrong)

  void foo_wrapper_with_locking()
  {
    spin_lock(&some_lock);
    foo();
    spin_unlock(&some_lock);
  }

Another use of wrapper functions would be if you need to call some
function where one or more of the arguments are always fixed for your
use, then to ensure that you always get it right you could create a
small wrapper :

  int wrap_function_call_with_fixed_args(int arg1)
  {
    return func(arg1, NULL, SOME_CONSTANT);
  }


--
Jesper Juhl <jesper.juhl@xxxxxxxxx>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux