Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#define MyVal 1e3 fails to correctly parse value #118

Open
dgleich opened this issue Nov 27, 2022 · 0 comments
Open

#define MyVal 1e3 fails to correctly parse value #118

dgleich opened this issue Nov 27, 2022 · 0 comments

Comments

@dgleich
Copy link

dgleich commented Nov 27, 2022

The automatic macro extractor...

module TestCBindingDefine
using CBinding
let
opts = [""]

c`$(opts)`

end
c"""
#define MyVal 1e3
"""ji
end

fails in this case because 1e3 matches both the int and float checks in this function

Error

WARNING: replacing module TestCBindingDefine.
ERROR: LoadError: ArgumentError: invalid base 10 digit 'e' in "1e3"

Cause

function getexprs_macro(ctx::Context{:c}, cursor::CXCursor)
	exprs = []
	
	expr = Bool(clang_Cursor_isMacroFunctionLike(cursor)) ? nothing : ""
	for (ind, token) in enumerate(tokenize(ctx.tu[], cursor))
		ind == 1 && continue  # first token is the macro name itself, so skip it
		expr === nothing && break
		
		str = string(ctx.tu[], token)
		kind = clang_getTokenKind(token)
		if kind == CXToken_Literal
			int = match(r"^(0|0x|0b)?([\da-f]+)([ul]*)$", lowercase(str))
			float = match(r"^(\d*\.)?(\d*)(e[-+]?\d+)?([fl])?$", lowercase(str))
			...

A related line occurs in the Qhull include files... so here's the real-world scenario.

module QhullAuto
  using CBinding
  using Qhull_jll

  #c`-I/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ -I$(joinpath(Qhull_jll.artifact_dir, "include", "libqhull_r"))`

  let 
    opts = ["-I/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/",
    "-I$(joinpath(Qhull_jll.artifact_dir, "include", "libqhull_r"))",
    "-L$(dirname(Qhull_jll.libqhull_r))",
    "-l$(splitpath(Qhull_jll.libqhull_r)[end])"]

    c`$(opts)`
  end

  c"""
  #include "qhull_ra.h"
  """ji
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant