Giter VIP home page Giter VIP logo

Comments (15)

jordansissel avatar jordansissel commented on July 2, 2024

I'll buy the 'code is a mess' argument given , but I'm curious - what problem are you encountering? I'm not sure how best to answer your question without knowing your problem, so before I answer any code linting/analysis questions, let's figure out what that is! :)

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

To be honest, having reviewed this code briefly just now, it looks like I refactored hastily this code a few times (which explains the end-of-loop 'dead assignments' and such), but again, let's get to what your problem is so that we may solve it :)

from xdotool.

Lekensteyn avatar Lekensteyn commented on July 2, 2024

I was having issues with xdotool type --window $ID somekeystore, it would be entered in the current window instead of the window selected by $ID (actually, I tried searchwindow --name Firefox).

Our of curiousity, I ran scan-build on this project which found over 30 potentional bugs. I am in process of fixing them, you can expect a pull request tomorrow for that.

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

I rely mostly on the test suite to find bugs; any chance you can add tests for any bugs you're fixing that are indicated by your tools?

from xdotool.

Lekensteyn avatar Lekensteyn commented on July 2, 2024

I will try to add tests where applicable. Some of the bugs occur when feeding unexpected input, or rely on undefined behavior.

Aside, what do you think of using the goto keyword?

This:

  void *p1 = NULL;
  void *p2 = NULL;

  if (cond) {
    return EXIT_FAILURE;
  }

  p1 = malloc(...);

  if (condition) {
    /* note: leak of p1 */
    return EXIT_FAILURE;
  }

...

  free(p1);
  free(p2);

  return EXIT_SUCCESS;

could be converted to:

  int ret = EXIT_FAILURE;
  void *p1 = NULL;
  void *p2 = NULL;

  if (cond) {
    return EXIT_FAILURE;
  }

  p1 = malloc(...);

  if (condition) {
    goto free_p1;
  }

...

  ret = EXIT_SUCCESS;
free_p2:
  free(p2);
free_p1:
  free(p1);
  return ret;

(real example: cmd_exec in cmd_exec.c, p1 is terminator and p2 is command)

Btw, how to test for crashes? Undefined behavior is difficult to test...

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

Regarding typing to firefox; I just tested again now with Firefox 25 it seems to work:

% xdotool getactivewindow 
37748739
% xdotool search --classname Navigator 
56623242
% xdotool search --classname Navigator   key ctrl+t
# result: firefox opens a new tab

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

re: using goto for cleanup like like a finally(java)/ensure(ruby)/defer(go) +1 I would approve this refactoring.

from xdotool.

Lekensteyn avatar Lekensteyn commented on July 2, 2024

key is working, but type isn't:

xdotool search --name behave type x

I have pushed the fixes I have done so far here:
https://github.com/Lekensteyn/xdotool/compare/clang-fixes

There are still 18 memleaks, 1 dead assignment and 11 logic errors (garbage/undefined) to fix (including the ones from this issue).

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

it'd be nice if there were a more straight forward way to add cleanup tasks though, instead of having multiple goto labels, just queue up some function calls (like 'defer' in go) and call them all in order at the end.

Interested in implementing that? Shouldn't be too hard ;)

from xdotool.

Lekensteyn avatar Lekensteyn commented on July 2, 2024

For just freeing up resources one label is enough (free(NULL)) is fine, that should not need special treatment.

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

key is working, but type isn't

'type' defaults to --window 0, I believe, incorrectly. This works:

% xdotool search --classname Navigator   type --window "%1" 'hello world'

cmd_key.c has:

    /* use %1 if there is a window stack */
   if (window_arg == NULL && context->nwindows > 0) {
     window_arg = "%1";
   }

And cmd_type does not. cmd_type should also do this "default to %1 if window_arg is not specified and there is a window stack"

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

Also, I very much appreciate your energy put into helping improve this project :)

from xdotool.

Lekensteyn avatar Lekensteyn commented on July 2, 2024

Thanks for the tool, it already saved me some time as a workaround for bugs :-)

What do you think of the pattern I used here:
Lekensteyn@38cd31b

I could also have introduced some macros, but I feel that this is simple enough to avoid macros.

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

38cd31b looks good to me!

from xdotool.

jordansissel avatar jordansissel commented on July 2, 2024

Agreed re: macros; it's simple enough.

from xdotool.

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.