octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #55542] Undefine bahavior in loading oct files


From: Rik
Subject: [Octave-bug-tracker] [bug #55542] Undefine bahavior in loading oct files and shared libraries
Date: Tue, 22 Jan 2019 12:22:26 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Update of bug #55542 (project octave):

                  Status:                    None => Invalid                
             Open/Closed:                    Open => Closed                 
                 Summary: Undefine bahavior in loading oct files and shred
libraries => Undefine bahavior in loading oct files and shared libraries

    _______________________________________________________

Follow-up Comment #2:

I don't think this is accurate.  There is no file
'liboctave/util/oct-shlib.cpp' so I'm not sure what code you were reviewing.

There is a file oct-shlib.cc.  If I take a look at one of the overloaded
implementations of search I find


  void *
  octave_dlopen_shlib::search (const std::string& name,
                               dynamic_library::name_mangler mangler)
  {
    void *function = nullptr;

    if (! is_open ())
      (*current_liboctave_error_handler)
        ("shared library %s is not open", file.c_str ());

    std::string sym_name = name;

    if (mangler)
      sym_name = mangler (name);

    if (search_all_loaded)
      function = dlsym (RTLD_DEFAULT, sym_name.c_str ());
    else
      function = dlsym (library, sym_name.c_str ());

    return function;
  }


The man page for dlsym is very clear that it returns a pointer to void.


NAME
       dlsym, dlvsym - obtain address of a symbol in a shared object or
executable

SYNOPSIS
       #include <dlfcn.h>

       void *dlsym(void *handle, const char *symbol);


Similarly, if we are compiling on a Mac platform then the code is


  void *
  octave_dyld_shlib::search (const std::string& name,
                             dynamic_library::name_mangler mangler)
  {
    void *function = nullptr;

    if (! is_open ())
      (*current_liboctave_error_handler)
        ("bundle %s is not open", file.c_str ());

    std::string sym_name = name;

    if (mangler)
      sym_name = mangler (name);

    NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ());

    if (symbol)
      {
        function = NSAddressOfSymbol (symbol);
      }

    return function;
  }


The NSAddressOfSymbol returns a void pointer as well


void *
NSAddressOfSymbol(NSSymbol symbol)


Also, we are writing in C++, rather than C, so we are not subject to all of
the same restrictions as the C compiler.  For example, if you look at how the
void pointer returned from search() is used in Octave, you will find that it
is always changed with a reinterpret_cast in to a pointer to a function.  Here
is an example from lo-sysinfo.cc.


typedef void (*flexi_f_type) (int*, int*, int*);
flexi_f_type flexi_f_ptr = reinterpret_cast<flexi_f_type>
                           (dyn_libs.search ("flexiblas_get_version"));




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?55542>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]