Skip to content

Instantly share code, notes, and snippets.

Created March 2, 2013 10:22
Show Gist options
  • Save anonymous/5070416 to your computer and use it in GitHub Desktop.
Save anonymous/5070416 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Mar 2, 2013.
    24 changes: 24 additions & 0 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    inline op nqp_native_call_build(invar PMC, in STR, in STR, in STR, invar PMC, invar PMC) :base_core {
    char *lib_name = Parrot_str_to_cstring(interp, $2);
    char *sym_name = Parrot_str_to_cstring(interp, $3);
    PMC *arg_info = $5;
    PMC *ret_info = $6;
    int i;
    char *lib_name_2;

    /* Initialize the object; grab native call part of its body. */
    NativeCallBody *body = get_nc_body(interp, $1);

    /* Try to load the library. */
    body->lib_name = lib_name;
    body->lib_handle = dlLoadLibrary(strlen(lib_name) ? lib_name : NULL);

    if (!body->lib_handle) {
    INTVAL pos = STRING_index(interp, $2, Parrot_str_new(interp, ".bundle", 0), 0);
    STRING * lib_name_alternative = Parrot_str_replace(interp, $2, pos, 5, ".dylib");
    *lib_name_2 = Parrot_str_to_cstring(interp, lib_name_alternative);

    printf( "Did not found %s trying with %s",lib_name, lib_name_2);
    body->lib_name = lib_name_2;
    body->lib_handle = dlLoadLibrary(strlen(lib_name_2) ? lib_name_2 : NULL);
    }