Io: my errno adventure in C

This pastie holds my first C patch. It actually repaired a Readline problem that appeared on my Mac when I git pull‘d Io’s source today. See the Io issue at their bugtracker.

The pgsql heroes fixed the problem way before, so I could stand on the shoulders of smart giants.

I don’t know how to test C stuff, except for running the programs, and Jonas reminded to actually do that:

c-5b66e555:~ olle$ rm .io_history 
c-5b66e555:~ olle$ mkdir .io_history
c-5b66e555:~ olle$ io
Io 20080120

 Exception: while loading history file '/Users/olle/.io_history', reason: Is a directory
 ---------
 loadHistory                         Z_CLI.io 47
 ReadLine ?                           Z_CLI.io 47
 Call relayStopStatus                 A2_Object.io 295
 CLI loadHistory                      Z_CLI.io 94
 CLI interactiveMultiline             Z_CLI.io 82
 CLI run                              IoState_runCLI() 1

c-5b66e555:~ olle$ 

So, the complaining functionality is retained.

What’s it do?

For those who are beginners at C, like I am, this small digression might interest:

  • First we include the errno mechanism as an include: #include <errno.h>
  • in each function, initialize the value of the static global variable “errno” to 0
  • functions like read_history(filename), from the libedit library return an int, but…
  • We are not interested in the return value, so we cast the computation to be void, the errno mechanism will take care of remembering that int on its own
  • It seems to be culturally correct to check for success instead of failure.

All these factoids are guesstimates of what went on, and I’m interested in the real story someday. Please provide any insight as comments, dear reader.

PS: As you can tell, mucking about other people’s C code is not something I do every day. I felt good, but weird.

Published by olleolleolle

Olle is a programmer, enjoying sunny Malmö in Sweden.

Join the Conversation

1 Comment

  1. Greetings! I was very glad to find that I’m not the only Mac user struggling with ReadLine in Io. Heh heh. I had been considering a different approach to solving the situation, but had not yet fully formulated it into a plan. Something along the lines of overwriting the saveHistory method from within my ~/.iorc file or something…

    I’ve been trying to figure out if Io methods are bound to the VM at runtime or at compile time. Is the only true “fix” to this error found in compiling a change to the C source, or do you think it may be possible to “fix” an already-compiled version by editing /usr/local/lib/io files or something?

    Your post is an excellent and encouraging read. I’m right about where you are, it would appear, with my Io use and C skills – just able to dig in and make changes, but not yet doing it with any frequency. ;P

    I’m on #io a lot (look for SpiderByte77, usually), or you can reach me at the “contact” link on my website. I’d love to meet and chat about Io on the Mac. Have a good one!

    David:.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.