# ReadOnlyMemoryError in ccall

**URL:** <https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781>\
**Category:** General Usage\
**Created:** [June 19, 2018, 12:10pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781 "2018-06-19T12:10:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [June 19, 2018, 12:10pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/1 "2018-06-19T12:10:34Z")

</div>

I’m trying to make my SDL bindings work on Linux but I’m getting this error that I don’t understand:

```julia
julia> ccall((:SDL_Init, SDL2.libSDL2), Cint, (UInt32,), SDL2.INIT_VIDEO)
ERROR: ReadOnlyMemoryError()

```

The function signature is:

`int SDL_Init(Uint32 flags)`

And `SDL2.libSDL2` points to the correct (as far as I can tell) library installed with apt-get. The same code works on Windows and macOS.

What does this `ReadOnlyMemoryError` means exactly and is there a way to fix this ? Thanks!

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [June 19, 2018, 12:31pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/2 "2018-06-19T12:31:03Z")

</div>

Julia 0.6.2 on Linux:

```julia
julia> ccall((:SDL_Init, "/usr/lib64/libSDL-1.2.so.0"), Cint, (UInt32,), 0x00000020)
0

```

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [June 19, 2018, 1:10pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/3 "2018-06-19T13:10:40Z")

</div>

Does it work with SDL2 (libsdl2-2.0-0) as well ?

```julia
ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.4.0"), Cint, (UInt32,), 0x00000020)

```

I’m on Ubuntu 16.04.4 LTS.

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [June 19, 2018, 6:59pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/4 "2018-06-19T18:59:08Z")

</div>

I can confirm this problem with SDL2 on Ubuntu 18.04 LTS:

```julia
julia> ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0"), Cint, (UInt32,), 0x00000020)
ERROR: ReadOnlyMemoryError()
Stacktrace:
 [1] anonymous at ./<missing>:?

```

But the following C code works fine:

```nohighlight
#include <SDL2/SDL.h>
#include <stdio.h>
int main( int argc, char *argv[])
{
   int ret = SDL_Init(0x00000020u);
   printf("%d\n",ret);
   return 0;
}

```

with both gcc and clang:

```julia
$ gcc test.c -lSDL2 -o test
$ ./test 
0
$ 

```

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [June 19, 2018, 7:12pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/5 "2018-06-19T19:12:04Z")

</div>

also julia segfaults on quitting the session.

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [June 19, 2018, 8:37pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/6 "2018-06-19T20:37:57Z")

</div>

Is this possibly still related to [https://github.com/JuliaLang/julia/issues/19606](https://github.com/JuliaLang/julia/issues/19606) ? If you are using the Gallium-based driver, you can test if this is the problem by setting the environment variable `GALLIUM_DRIVER="softpipe"` before starting Julia.

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [June 19, 2018, 11:04pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/7 "2018-06-19T23:04:51Z")

</div>

I am using r600 gallium, but setting GALLIUM\_DRIVER=“softpipe” before starting Julia does not help:

```julia
julia> ENV["GALLIUM_DRIVER"]
"softpipe"

julia> ccall((:SDL_Init, "/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0"), Cint, (UInt32,), 0x00000020)
ERROR: ReadOnlyMemoryError()
Stacktrace:
 [1] anonymous at ./<missing>:?

```

It is however similar to issue:  
[https://github.com/JuliaPy/PyPlot.jl/issues/291](https://github.com/JuliaPy/PyPlot.jl/issues/291)  
I have this pyplot issue in Ubuntu using PyQT5 backend but not on Fedora.

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [June 23, 2018, 12:56pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/8 "2018-06-23T12:56:40Z")

</div>

I have realised that to enable softpipe, you also need to:

> export LIBGL\_ALWAYS\_SOFTWARE=true

in addition to:

> export GALLIUM\_DRIVER=“softpipe”

but even then I get the same error.

This is an annoying bug and I would like to figure a way around it (especially for being able to plot with julia with all backends).  
If this is an Ubuntu bug, I will report it to Ubuntu, but first I need to understand it better.

How can I debug this?

If this is a LLVM version conflict problem, I don’t really see a way around it except for renaming all LLVM symbols in either julia or mesa.

In [LLVM conflict with Gallium3D (swrast) driver · Issue #19606 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/19606) , it says “The Mesa projects strongly recommends against linking their drivers dynamically for this reason”. Can we have the source of this statement?

On my system mesa is using LLVM6

```julia
$ glxinfo |grep -i llvm
    Device: AMD JUNIPER (DRM 2.50.0 / 4.15.0-23-generic, LLVM 6.0.0) (0x68ba)
OpenGL renderer string: AMD JUNIPER (DRM 2.50.0 / 4.15.0-23-generic, LLVM 6.0.0)

```

LLVM6 shared lib is installed and if I try to remove the package with apt it tries to deinstall most of the system packages including mesa, so it looks like mesa is linking LLVM dynamically however I could not find any explicit LLVM dependencies in the mesa shared lib:

```julia
$ ldd /usr/lib/x86_64-linux-gnu/*mesa* |grep -i LLVM
$

```

Is [Backport symbol versioning patch from LLVM 4.0 by ihnorton · Pull Request #24890 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/24890) going to fix this problem in Julia 0.7?

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [June 24, 2018, 8:35am UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/9 "2018-06-24T08:35:57Z")

</div>

> [@Bernard\_GODARD](#):
>
> If this is a LLVM version conflict problem, I don’t really see a way around it except for renaming all LLVM symbols in either julia or mesa.

If it really is the LLVM version conflict bug, then compiling Julia from source with the system compilers and LLVM should solve it, although using the system LLVM may introduce other problems. At least it will help to determine if this is the root cause or not.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [June 24, 2018, 10:21am UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/10 "2018-06-24T10:21:17Z")

</div>

I had the same issue with `hdf5` recently. The issue `ReadOnlyMemory` exception happed non-deterministically though always in the same function. I could solve this by switch to the `serial` version of `libhdf5` instead of the `openmp` version. As for @jonathanBieler this does not seem to have anything to do with the gallium issue.

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [June 24, 2018, 6:45pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/11 "2018-06-24T18:45:43Z")

</div>

I have tested that this error does not happen in Julia 0.7!

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [June 24, 2018, 10:09pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-ccall/11781/12 "2018-06-24T22:09:20Z")

</div>

Also I was in julia 0.6.2 and I just migrated to 0.6.3. The problem is also fixed on 0.6.3.
