Skip to content

Commit

Permalink
remove more unneeded jl_get_global calls
Browse files Browse the repository at this point in the history
Except for those used by staticdata, which uses reflection for
everything, this removes most of the remaining runtime callbacks,
although a couple also exist to `jl_get_module_binding` still as well.
  • Loading branch information
vtjnash committed Feb 8, 2024
1 parent ac40f6d commit 03eb1f1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 98 deletions.
8 changes: 6 additions & 2 deletions base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ end

function read(f::File, ::Type{UInt8})
check_open(f)
ret = ccall(:jl_fs_read_byte, Int32, (OS_HANDLE,), f.handle)
p = Ref{UInt8}()
ret = ccall(:jl_fs_read, Int32, (OS_HANDLE, Ptr{Cvoid}, Csize_t),
f.handle, p, 1)
uv_error("read", ret)
return ret % UInt8
@assert ret <= sizeof(p) == 1
ret < 1 && throw(EOFError())
return p[] % UInt8
end

function read(f::File, ::Type{Char})
Expand Down
5 changes: 0 additions & 5 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
XX(jl_enter_handler) \
XX(jl_enter_threaded_region) \
XX(jl_environ) \
XX(jl_eof_error) \
XX(jl_eqtable_get) \
XX(jl_eqtable_pop) \
XX(jl_eqtable_put) \
Expand Down Expand Up @@ -239,8 +238,6 @@
XX(jl_method_lookup_by_tt) \
XX(jl_method_lookup) \
XX(jl_gf_invoke_lookup_worlds) \
XX(jl_git_branch) \
XX(jl_git_commit) \
XX(jl_global_event_loop) \
XX(jl_has_empty_intersection) \
XX(jl_has_free_typevars) \
Expand Down Expand Up @@ -436,7 +433,6 @@
XX(jl_stderr_obj) \
XX(jl_stderr_stream) \
XX(jl_stdin_stream) \
XX(jl_stdout_obj) \
XX(jl_stdout_stream) \
XX(jl_stored_inline) \
XX(jl_string_ptr) \
Expand Down Expand Up @@ -516,7 +512,6 @@
XX(jl_vprintf) \
XX(jl_wakeup_thread) \
XX(jl_write_compiler_output) \
XX(jl_yield) \

#define JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) \
XX(jl_setjmp) \
Expand Down
19 changes: 0 additions & 19 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,25 +662,6 @@ JL_DLLEXPORT int jl_fs_read(uv_os_fd_t handle, char *data, size_t len)
return ret;
}

JL_DLLEXPORT int jl_fs_read_byte(uv_os_fd_t handle)
{
uv_fs_t req;
unsigned char c;
uv_buf_t buf[1];
buf[0].base = (char*)&c;
buf[0].len = 1;
int ret = uv_fs_read(unused_uv_loop_arg, &req, handle, buf, 1, -1, NULL);
uv_fs_req_cleanup(&req);
switch (ret) {
case -1: return ret;
case 0: jl_eof_error();
case 1: return (int)c;
default:
assert(0 && "jl_fs_read_byte: Invalid return value from uv_fs_read");
return -1;
}
}

JL_DLLEXPORT int jl_fs_close(uv_os_fd_t handle)
{
uv_fs_t req;
Expand Down
49 changes: 0 additions & 49 deletions src/jlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,20 +437,6 @@ JL_DLLEXPORT jl_value_t *jl_call3(jl_function_t *f, jl_value_t *a,
return v;
}

/**
* @brief Yield to the Julia scheduler.
*
* Yields control to the Julia scheduler, allowing other Julia tasks to run.
*/
JL_DLLEXPORT void jl_yield(void)
{
static jl_function_t *yieldfunc = NULL;
if (yieldfunc == NULL)
yieldfunc = (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("yield"));
if (yieldfunc != NULL)
jl_call0(yieldfunc);
}

/**
* @brief Get a field from a Julia object.
*
Expand Down Expand Up @@ -619,41 +605,6 @@ JL_DLLEXPORT const char *jl_ver_string(void)
return JULIA_VERSION_STRING;
}

// return char* from String field in Base.GIT_VERSION_INFO
static const char *git_info_string(const char *fld)
{
static jl_value_t *GIT_VERSION_INFO = NULL;
if (!GIT_VERSION_INFO)
GIT_VERSION_INFO = jl_get_global(jl_base_module, jl_symbol("GIT_VERSION_INFO"));
jl_value_t *f = jl_get_field(GIT_VERSION_INFO, fld);
assert(jl_is_string(f));
return jl_string_data(f);
}

/**
* @brief Get the name of the Git branch for the Julia build.
*
* @return A C string containing the name of the Git branch.
*/
JL_DLLEXPORT const char *jl_git_branch(void)
{
static const char *branch = NULL;
if (!branch) branch = git_info_string("branch");
return branch;
}

/**
* @brief Get the Git commit hash for the Julia build.
*
* @return A C string containing the Git commit hash.
*/
JL_DLLEXPORT const char *jl_git_commit(void)
{
static const char *commit = NULL;
if (!commit) commit = git_info_string("commit");
return commit;
}

/**
* @brief Convert a Julia value to a tagged value.
*
Expand Down
7 changes: 0 additions & 7 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,6 @@ JL_DLLEXPORT void JL_NORETURN jl_bounds_error_tuple_int(jl_value_t **v,
JL_DLLEXPORT void JL_NORETURN jl_bounds_error_unboxed_int(void *v, jl_value_t *vt, size_t i);
JL_DLLEXPORT void JL_NORETURN jl_bounds_error_ints(jl_value_t *v JL_MAYBE_UNROOTED,
size_t *idxs, size_t nidxs);
JL_DLLEXPORT void JL_NORETURN jl_eof_error(void);

// Return the exception currently being handled, or `jl_nothing`.
//
Expand Down Expand Up @@ -2173,9 +2172,6 @@ JL_DLLEXPORT jl_value_t *jl_call2(jl_function_t *f JL_MAYBE_UNROOTED, jl_value_t
JL_DLLEXPORT jl_value_t *jl_call3(jl_function_t *f JL_MAYBE_UNROOTED, jl_value_t *a JL_MAYBE_UNROOTED,
jl_value_t *b JL_MAYBE_UNROOTED, jl_value_t *c JL_MAYBE_UNROOTED);

// interfacing with Task runtime
JL_DLLEXPORT void jl_yield(void);

// async signal handling ------------------------------------------------------

JL_DLLEXPORT void jl_install_sigint_handler(void);
Expand Down Expand Up @@ -2409,7 +2405,6 @@ JL_DLLEXPORT int jl_termios_size(void);

// showing and std streams
JL_DLLEXPORT void jl_flush_cstdio(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_stdout_obj(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_stderr_obj(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT size_t jl_static_show(JL_STREAM *out, jl_value_t *v) JL_NOTSAFEPOINT;
JL_DLLEXPORT size_t jl_static_show_func_sig(JL_STREAM *s, jl_value_t *type) JL_NOTSAFEPOINT;
Expand Down Expand Up @@ -2510,8 +2505,6 @@ JL_DLLEXPORT extern int jl_ver_minor(void);
JL_DLLEXPORT extern int jl_ver_patch(void);
JL_DLLEXPORT extern int jl_ver_is_release(void);
JL_DLLEXPORT extern const char *jl_ver_string(void);
JL_DLLEXPORT const char *jl_git_branch(void);
JL_DLLEXPORT const char *jl_git_commit(void);

// nullable struct representations
typedef struct {
Expand Down
16 changes: 0 additions & 16 deletions src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,6 @@ JL_DLLEXPORT void JL_NORETURN jl_bounds_error_ints(jl_value_t *v JL_MAYBE_UNROOT
jl_throw(jl_new_struct((jl_datatype_t*)jl_boundserror_type, v, t));
}

JL_DLLEXPORT void JL_NORETURN jl_eof_error(void)
{
jl_datatype_t *eof_error =
(jl_datatype_t*)jl_get_global(jl_base_module, jl_symbol("EOFError"));
assert(eof_error != NULL);
jl_throw(jl_new_struct(eof_error));
}

JL_DLLEXPORT void jl_typeassert(jl_value_t *x, jl_value_t *t)
{
if (!jl_isa(x,t))
Expand Down Expand Up @@ -546,14 +538,6 @@ JL_DLLEXPORT void jl_flush_cstdio(void) JL_NOTSAFEPOINT
fflush(stderr);
}

JL_DLLEXPORT jl_value_t *jl_stdout_obj(void) JL_NOTSAFEPOINT
{
if (jl_base_module == NULL)
return NULL;
jl_binding_t *stdout_obj = jl_get_module_binding(jl_base_module, jl_symbol("stdout"), 0);
return stdout_obj ? jl_atomic_load_relaxed(&stdout_obj->value) : NULL;
}

JL_DLLEXPORT jl_value_t *jl_stderr_obj(void) JL_NOTSAFEPOINT
{
if (jl_base_module == NULL)
Expand Down
26 changes: 26 additions & 0 deletions src/staticdata_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,32 @@ JL_DLLEXPORT uint8_t jl_match_cache_flags(uint8_t flags)
return flags >= current_flags;
}

// return char* from String field in Base.GIT_VERSION_INFO
static const char *git_info_string(const char *fld)
{
static jl_value_t *GIT_VERSION_INFO = NULL;
if (!GIT_VERSION_INFO)
GIT_VERSION_INFO = jl_get_global(jl_base_module, jl_symbol("GIT_VERSION_INFO"));
jl_value_t *f = jl_get_field(GIT_VERSION_INFO, fld);
assert(jl_is_string(f));
return jl_string_data(f);
}

static const char *jl_git_branch(void)
{
static const char *branch = NULL;
if (!branch) branch = git_info_string("branch");
return branch;
}

static const char *jl_git_commit(void)
{
static const char *commit = NULL;
if (!commit) commit = git_info_string("commit");
return commit;
}


// "magic" string and version header of .ji file
static const int JI_FORMAT_VERSION = 12;
static const char JI_MAGIC[] = "\373jli\r\n\032\n"; // based on PNG signature
Expand Down

0 comments on commit 03eb1f1

Please sign in to comment.