Skip to content

Commit

Permalink
Apply patch
Browse files Browse the repository at this point in the history
  • Loading branch information
melonedo committed Aug 31, 2021
1 parent 40b7c3b commit f699062
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gen/libpng/generator.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[general]
library_name = "libpng"
output_file_path = "libpng.jl"
output_file_path = "libpng_api.jl"
prologue_file_path = "prologue.jl"
use_julia_native_enum_type = false
print_using_CEnum = false
Expand Down
2 changes: 1 addition & 1 deletion gen/libpng/libpng.jl → gen/libpng/libpng_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ function png_get_error_ptr(png_ptr)
end

function png_set_write_fn(png_ptr, io_ptr, write_data_fn, output_flush_fn)
ccall((:png_set_write_fn, libpng), Cvoid, (png_structrp, png_voidp, png_rw_ptr, png_flush_ptr), png_ptr, io_ptr, write_data_fn, output_flush_fn)
ccall((:png_set_write_fn, libpng), Cvoid, (png_structrp, Any, png_rw_ptr, png_flush_ptr), png_ptr, io_ptr, write_data_fn, output_flush_fn)
end

function png_set_read_fn(png_ptr, io_ptr, read_data_fn)
Expand Down
21 changes: 20 additions & 1 deletion gen/libpng/wrap_libpng.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
using Clang.Generators
using libpng_jll

function rewrite(ex::Expr)
if Meta.isexpr(ex, :function) && ex.args[1].args[1] == :png_set_write_fn
ex = quote
function png_set_write_fn(png_ptr, io_ptr, write_data_fn, output_flush_fn)
ccall((:png_set_write_fn, libpng), Cvoid, (png_structrp, Any, png_rw_ptr, png_flush_ptr), png_ptr, io_ptr, write_data_fn, output_flush_fn)
end
end |> Base.remove_linenums!
ex.args[]
else
ex
end
end

cd(@__DIR__)

include_dir = joinpath(libpng_jll.artifact_dir, "include") |> normpath
Expand All @@ -22,4 +35,10 @@ headers = [joinpath(header_dir, "png.h")]
ctx = create_context(headers, args, options)

# run generator
build!(ctx)
build!(ctx, BUILDSTAGE_NO_PRINTING)
for node in get_nodes(ctx.dag)
for (i, expr) in enumerate(node.exprs)
node.exprs[i] = rewrite(expr)
end
end
build!(ctx, BUILDSTAGE_PRINTING_ONLY)
2 changes: 1 addition & 1 deletion src/PNGFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using libpng_jll

libpng_wrap_dir = joinpath(@__DIR__, "..", "gen", "libpng")
using CEnum
include(joinpath(libpng_wrap_dir, "libpng.jl"))
include(joinpath(libpng_wrap_dir, "libpng_api.jl"))

const readcallback_c = Ref{Ptr{Cvoid}}(C_NULL)
const readcallback_iobuffer_c = Ref{Ptr{Cvoid}}(C_NULL)
Expand Down

0 comments on commit f699062

Please sign in to comment.