Git Product home page Git Product logo

Comments (27)

parched avatar parched commented on May 20, 2024 2

Isn't

let keysym_list = [keysym, keysym].as_ptr();
creating a dangling pointer?

from enigo.

pythoneer avatar pythoneer commented on May 20, 2024 2

i could put one out immediately ... (if ci says ok)

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 20, 2024 1

Interesting! Operating system?

EDIT: Confirmed not working on Linux...
EDIT 2: It feels like the problem here is inside unicode_string_to_keycode, as it only affects unicode sequences (which is why your workaround worked. You could also use the parser.)
EDIT 3: That's odd, the LLVM-IR doesn't look very different

image
(Debug mode)
image
(Release mode)

EDIT 4: The MIR doesn't look different either, although I'm not sure if that is pre or post optimization.

from enigo.

vitiral avatar vitiral commented on May 20, 2024 1

also, I re-opened the rust bug. Not sure if the rust guys consider this a bug (basically it's a symptom of when the compiler says "temporary value doesn't live long enough" -- except it's an unsafe pointer so the compiler doesn't tell you anything).

This is probably a case where an unsafe linter would be GREAT

from enigo.

parched avatar parched commented on May 20, 2024 1

Oh that's great it was the fix, I also noticed this line should be fixed too

let keysym_list = [0 as KeySym, 0 as KeySym].as_ptr();

from enigo.

vitiral avatar vitiral commented on May 20, 2024

also, the need for Key::Shift looks like it might be a bug to me.

from enigo.

vitiral avatar vitiral commented on May 20, 2024

sorry, operating system is Arch Linux

$ uname -a                                                                       
Linux vitiral 4.12.8-2-ARCH #1 SMP PREEMPT Fri Aug 18 14:08:02 UTC 2017 x86_64 GNU/Linux

from enigo.

vitiral avatar vitiral commented on May 20, 2024

maybe try adding #[inline(never)] on a few functions an experiment? I don't know the best way to avoid these kind of optimizations.

I don't see speed as super crtical to this library :)

from enigo.

vitiral avatar vitiral commented on May 20, 2024

also, this might very well be a rust compiler bug. It's pretty weird to see different behavior for different build modes.

from enigo.

vitiral avatar vitiral commented on May 20, 2024

also, the two pieces of LLVM you posted look like stuff from the mouse commands? This is a problem with the keyboard (although maybe I'm misunderstanding)

Edit: pretty sure "MIR" is always pre-optimization, since release optimization is all LLVM at this point.

I think we just need to tell LLVM not to optimize some stuff.

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 20, 2024

The key_sequence function supports unicode, by temporarily mapping an unused keyboard key in unicode_string_to_keycode. In release mode, this appears to be optimized away.

I doubt this is an #[inline(never)] issue, but I am unsure. I know too little about this to answer.

from enigo.

vitiral avatar vitiral commented on May 20, 2024

it looks like we might be able to disable optimizations for this crate with:

[profile.dev]
opt-level = 0

[profile.release]
opt-level = 0

In the Cargo.toml file. Here is a reference.

If you are okay with that, I can make the change and test it locally.

It seems to build an unoptimized release when I build locally:

$ cargo build --release       
    Updating registry `https://github.com/rust-lang/crates.io-index`                                     
   Compiling pkg-config v0.3.9                      
   Compiling libc v0.2.30 
   Compiling enigo v0.0.10 (file:///home/garrett/src/ruststuff/enigo)                                    
    Finished release [unoptimized] target(s) in 4.2 secs 

Edit: I'm testing it out with my application now.

from enigo.

vitiral avatar vitiral commented on May 20, 2024

hmm... it doesn't seem to have had an effect :(

from enigo.

vitiral avatar vitiral commented on May 20, 2024

I've also blanketed all functions in linux_impl with #[no_mangle] and it seems to not have an effect

Edit: also added #[inline(never)]... still no effect

from enigo.

vitiral avatar vitiral commented on May 20, 2024

I opened the above ticket, hopefully someone from rust knows how this might be solved.

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 20, 2024

Shouldn't that be dropped like normal?

from enigo.

parched avatar parched commented on May 20, 2024

I might be mistaken but I was under the impression that the temporary array would be dropped at the end of that that line. You can test if it is the issue by moving the as_ptr call to the function call.

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 20, 2024

Ooooo yeah that's a good call. However, I think Rust keeps it alive, just like it would with a pointer.

Playground

from enigo.

ollie27 avatar ollie27 commented on May 20, 2024

Try this: playground

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 20, 2024

Also works?

from enigo.

ollie27 avatar ollie27 commented on May 20, 2024

Use release mode.

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 20, 2024

Ooooooooooo! Is that supposed to happen or is it a Rust bug?

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 20, 2024

Doesn't seem like GitHub shows the commit that fixed this... Here it is

from enigo.

vitiral avatar vitiral commented on May 20, 2024

Confirmed that this now works for novault. Thanks!

Any idea when a new release will be made?

from enigo.

parched avatar parched commented on May 20, 2024

Does clippy say anything about it? If not, I agree it definitely should, it's easy to do.

from enigo.

pythoneer avatar pythoneer commented on May 20, 2024

we should start using clippy though :/ idk to be honest

from enigo.

pythoneer avatar pythoneer commented on May 20, 2024

@vitiral new version in the wild. Thanks for your help and everybody involved!

from enigo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.