Skip to content

Commit

Permalink
Merge pull request #15472 from barche/master
Browse files Browse the repository at this point in the history
Test for issue #15408
  • Loading branch information
yuyichao committed Mar 15, 2016
2 parents 71c3d62 + a4455ed commit f7ab0e2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
7 changes: 1 addition & 6 deletions doc/devdocs/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ translates these symbols into LLVM instructions during code generation.
<https://github.com/JuliaLang/julia/blob/master/src/builtins.c>`_
hooks C functions up to Julia function symbols. e.g. the symbol
:func:`Base.is` is bound to C function pointer :c:func:`jl_f_is`
by calling :code:`add_builtin_func("eval", jl_f_top_eval)`, which does::

jl_set_const(jl_core_module,
jl_symbol("is"),
jl_new_closure(jl_f_top_eval, jl_symbol("eval"), NULL));

by calling :code:`add_builtin_func("eval", jl_f_top_eval)`.

`jl_new_main_module()
<https://github.com/JuliaLang/julia/blob/master/src/toplevel.c>`_
Expand Down
1 change: 0 additions & 1 deletion doc/devdocs/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ Functions and LambdaInfo::

jl_function_t *jl_new_generic_function(jl_sym_t *name);
jl_lambda_info_t *jl_new_lambda_info(jl_value_t *ast, jl_tuple_t *sparams);
jl_function_t *jl_new_closure(jl_fptr_t proc, jl_value_t *env, jl_lambda_info_t *li);

Arrays::

Expand Down
15 changes: 15 additions & 0 deletions src/ccalltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

int verbose = 1;

int c_int = 0;

//////////////////////////////////
// Test for proper argument register truncation
Expand Down Expand Up @@ -362,6 +363,20 @@ JL_DLLEXPORT struct_big test_big(struct_big a) {
return a;
}

JL_DLLEXPORT int get_c_int(void)
{
return c_int;
}

JL_DLLEXPORT void set_c_int(int i)
{
c_int = i;
}

JL_DLLEXPORT void finalizer_cptr(void* v)
{
set_c_int(-1);
}

//////////////////////////////////
// Turn off verbose for automated tests, leave on for debugging
Expand Down
5 changes: 4 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,12 @@ void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name)
} else {
// Otherwise we use a global mapping
assert(!imaging_mode);
#if defined(USE_MCJIT) || defined(USE_ORCJIT)
#if defined(USE_ORCJIT)
jl_ExecutionEngine->addGlobalMapping(llvmf->getName(),
(void*)getAddressForOrCompileFunction(llvmf));
#elif defined(USE_MCJIT)
jl_ExecutionEngine->addGlobalMapping(llvmf->getName(),
getAddressForOrCompileFunction(llvmf));
#else
jl_ExecutionEngine->addGlobalMapping(llvmf,
jl_ExecutionEngine->getPointerToFunction(llvmf));
Expand Down
2 changes: 0 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,6 @@ JL_DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...);
JL_DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args,
uint32_t na);
JL_DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type);
JL_DLLEXPORT jl_function_t *jl_new_closure(jl_fptr_t proc, jl_value_t *env,
jl_lambda_info_t *li);
JL_DLLEXPORT jl_lambda_info_t *jl_new_lambda_info(jl_value_t *ast,
jl_svec_t *tvars,
jl_svec_t *sparams,
Expand Down
9 changes: 9 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,12 @@ let n=3
end

@test ccall(:jl_getpagesize, Clong, ()) == @threadcall(:jl_getpagesize, Clong, ())

# Pointer finalizer (issue #15408)
let A = [1]
ccall((:set_c_int, libccalltest), Void, (Cint,), 1)
@test ccall((:get_c_int, libccalltest), Cint, ()) == 1
finalizer(A, cglobal((:finalizer_cptr, libccalltest), Void))
finalize(A)
@test ccall((:get_c_int, libccalltest), Cint, ()) == -1
end

0 comments on commit f7ab0e2

Please sign in to comment.