code logs -> 2011 -> Thu, 25 Aug 2011< code.20110824.log - code.20110826.log >
--- Log opened Thu Aug 25 00:00:10 2011
00:06
< Attilla>
it chafes uncomfortably, that's why I prefer leather
00:10
<@Tarinaky>
Not funny.
00:12
<@Tamber>
I thought it was.
00:20 * Alek sends someone to fit Attilla for a polyester gimp suit.
00:32 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has joined #code
00:41 celticminstrel [celticminst@Nightstar-5d22ab1d.cable.rogers.com] has quit [Ping timeout: 121 seconds]
00:53 Derakon[AFK] is now known as Derakon
00:55 Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Connection closed]
00:59 Vornicus [Vash@Nightstar-f03c5637.sd.cox.net] has quit [Connection closed]
01:27 Derakon [Derakon@Nightstar-c826c088.ca.comcast.net] has quit [Client exited]
01:27 Derakon [Derakon@Nightstar-c826c088.ca.comcast.net] has joined #code
01:55 Attilla [Some.Dude@Nightstar-f29f718d.cable.virginmedia.com] has quit [Ping timeout: 121 seconds]
02:27 celticminstrel [celticminst@Nightstar-5d22ab1d.cable.rogers.com] has joined #code
03:46
< Phox>
Hey, I have a problem. My instructor kept telling me to put a star in front of a variable to make it a pointer, so I loaded up a japanese IME and put a star in front of my variable, and it wouldn't compile. int ?b = &a;
03:47
< Phox>
Should I tell him he's a moron, and should use proper terminology?
03:48
<@McMartin>
Er
03:48
<@McMartin>
That looks like it should be right.
03:48
<@McMartin>
Oh. You're using a five-pointed star
03:48
<@McMartin>
No, you're being a twatwaffle.
03:48
<@McMartin>
"star" is a perfectly good name for the unicode code point *.
03:49
< Phox>
XD, twatwaffle.
03:51
< Phox>
Nah, I actually kid. I have a lot of respect for the guy. I think he's just finishing up his Masters. I do things like this because I get bored in class.
03:53
<@McMartin>
If you want to have Fun With Official Unicode Names, "=" has QUADRATHORPE as an alias.
03:55
< Phox>
... I even have a use for that.
03:57 Vash [Vash@Nightstar-f03c5637.sd.cox.net] has joined #code
03:58 Vash is now known as Vornicus
04:04 cpux is now known as shade_of_cpux
04:08 Kindamoody[zZz] is now known as Kindamoody
04:35 Omega [omegaboot@Nightstar-10752b3e.il.comcast.net] has joined #code
04:35 Alek [omegaboot@Nightstar-10752b3e.il.comcast.net] has quit [NickServ (GHOST command used by Omega)]
04:35 Omega is now known as Alek
05:13 PinkFreud [WhyNot@NetworkAdministrator.Nightstar.Net] has quit [Ping timeout: 121 seconds]
06:11 AnnoDomini [annodomini@Nightstar-f7eedefa.80-203-17.nextgentel.com] has joined #code
06:27 Stalker [Z@Nightstar-3602cf5a.cust.comxnet.dk] has quit [Ping timeout: 121 seconds]
06:34 Derakon is now known as Derakon[AFK]
06:36 Kindamoody is now known as KiMo|prog
06:46 celticminstrel [celticminst@Nightstar-5d22ab1d.cable.rogers.com] has quit [[NS] Quit: And lo! The computer falls into a deep sleep, to awake again some other day!]
07:09 Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has joined #code
08:13 jeroid [jerith@687AAB.5E3E50.73E66E.A55161] has joined #code
08:21 Vornicus [Vash@Nightstar-f03c5637.sd.cox.net] has quit [[NS] Quit: Spaaaaaaaaaaaaaaaaace sleeeeeeeeeeeeeeeep!]
08:39 You're now known as TheWatcher
08:55 KiMo|prog is now known as Kindamoody
09:06 jeroid [jerith@687AAB.5E3E50.73E66E.A55161] has quit [[NS] Quit: Bye]
09:10 Kindamoody is now known as Kindamoody|out
10:05 Attilla [Some.Dude@Nightstar-f29f718d.cable.virginmedia.com] has joined #code
13:50 PinkFreud [WhyNot@NetworkAdministrator.Nightstar.Net] has joined #code
14:14 celticminstrel [celticminst@Nightstar-5d22ab1d.cable.rogers.com] has joined #code
15:24 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has quit [Client closed the connection]
15:24 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has joined #code
15:34 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has quit [Ping timeout: 121 seconds]
15:39 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has joined #code
16:01 Stalker [Z@Nightstar-3602cf5a.cust.comxnet.dk] has joined #code
16:11 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has quit [Ping timeout: 121 seconds]
16:17 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has joined #code
16:38 Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Connection closed]
17:47 Derakon [chriswei@Nightstar-c826c088.ca.comcast.net] has joined #code
17:52 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has quit [Ping timeout: 121 seconds]
17:55 * Derakon mutters at SWIG and Python and nonresponsive mailing lists.
17:57 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has joined #code
18:07 * Derakon sticks "int main(int argc, char** argv) {}" into a file, does "gcc test.c", gets an "undefined symbol: _main" error.
18:07
< Derakon>
Oh wait, I'm a dumbass.
18:09
< Derakon>
(Forgot to make the forward function declaration match the function -- I had an errant "static")
18:33 * Derakon mutters some more at the use of wide characters in general.
18:34
< Derakon>
Especially since the library I have to interoperate with a) just uselessly renames the standard wchar_t to "AT_WC", and b) provides conversion functions between wchar_t* and char*, which makes me think they aren't even using the extra byte.
18:36 * TheWatcher hates all over wide characters >.<
18:36
< Derakon>
I understand the need for them in certain areas, but this is really not one of them.
18:37
< Derakon>
(I'm trying to talk to a camera, and strings are used only for choosing options by name or for error codes)
18:40
< Derakon>
Ideally there'd be some way in the SWIG interface file to say "Here, these wchar_t things? Convert them to chars and then handle them normally, please", but I'm having a devil of a time figuring out how to do that and the mailing list appears to be dead.
18:40
< Derakon>
(And there's no associated IRC channel)
19:09 Kindamoody|out is now known as Kindamoody
19:10 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has quit [Ping timeout: 121 seconds]
19:11 Reiver [orthianz@3CF3A5.E1CD01.C6689C.33956A] has joined #code
19:19 Vash [Vash@Nightstar-f03c5637.sd.cox.net] has joined #code
19:19 Vash is now known as Vornicus
19:20 * Derakon spends a half-hour trying to figure out why his typemap isn't getting used, only to realize it's because he wasn't generating the necessary intermediary file after having added it.
19:20
< Derakon>
I hate it when that happens.
19:21
< Vornicus>
typemap? what're you playing with today?
19:21
< Derakon>
SWIG.
19:21
< Derakon>
I need to teach it how to convert Python strings into wchar_t*s
19:21
< Vornicus>
aha
19:22
< Derakon>
So I was modifying my SWIG interface file, building the wrapper file, linking it, and trying to use it...but between steps 1 and 2 I was supposed to be generating the wrapper file from the interface file. >.<
19:24
< Derakon>
!
19:24
< Derakon>
It worked!
19:24 * Derakon does a small version of the happy coder dance in his chair.
19:24
< Vornicus>
Happy Coder Dances, yay!
19:28
< Derakon>
This is one of those tasks that would have been trivial to anyone who knew what they were doing~
19:29
< Vornicus>
Yeah, I noticed that happens a lot.
20:02 Kindamoody is now known as Kindamoody[zZz]
21:06 Vornicus [Vash@Nightstar-f03c5637.sd.cox.net] has quit [Connection closed]
21:19
< Derakon>
There, now I have functional string returning too.
21:19
< Derakon>
...though there might be the possibility for a memory leak here.
21:20
< Derakon>
Yeah, memory leak. Hm.
21:21
< Derakon>
Wow, my C is rusty. How do you generate and return a C string (array of chars) without memory leaks or returning the address of a local variable?
21:22
< Derakon>
mallocing the array of course causes the memory leak, and doing "char buffer[1000]" means returning the address of a local.
21:24
<@Tamber>
Maybe I'm thinking of this problem in a different way to you, but why is it leaking memory? You're malloc-ing the memory inside foo(), returning the pointer to it, then not freeing it in the caller when you're finished with it?
21:24
<@McMartin>
(a) malloc, and rely on the caller to dispose of it (ownership model!)
21:24
<@Tamber>
^
21:24
< Derakon>
That gets difficult when the caller is Python.
21:24
<@McMartin>
(b) pass in a pre-allocated array as an argument, a la sprintf, and trust they got the size right.
21:24
< Derakon>
Likewise.
21:24
<@Tamber>
...ah, yes, that doesn make it a little difficult.
21:24 mode/#code [+ooooooooooooooooo Derakon[AFK] Phox TheWatcher simon_ Reiver Attilla PinkFreud celticminstrel AnnoDomini Derakon Kazriko Kindamoody[zZz] ToxicFrog Syloqs-AFH Alek Stalker shade_of_cpux] by Tamber
21:24
<@McMartin>
That's not "your C is rusty"
21:24
<@McMartin>
that's "your Python/C FFI is rusty"
21:24
<@Derakon>
Ah.
21:25
<@Derakon>
For some reason I remembered there being some way to pass character arrays around by value.
21:25
<@McMartin>
A struct with a char array in it, passed by value
21:25
<@McMartin>
If it's fixed size
21:25
<@McMartin>
Viz. Not A String.
21:26
<@Derakon>
The ultimate goal is to call an API function which accepts a wchar_t* buffer and stuffs a result value into it.
21:26
<@Derakon>
I'm trying to make that look, to the Python, like "call this function with no arguments, and get a string back".
21:26
<@Derakon>
So somewhere in there I have to allocate a buffer of some arbitrary size and pass it to the API function.
21:27
<@McMartin>
Python must have some form of "this chunk of memory belongs to you now, and it's a string, or "build a string from this buffer, and the buffer can be destroyed later".
21:30 * McMartin throws together a small Haskell program over lunch to decode the clues he's collected in M&M2.
21:30
<@Derakon>
All of the actual conversions are being done inside SWIG, which is AFAICT entirely little C stubs.
21:31
<@Derakon>
So I have access to the Python C libraries, which I have zero familiarity with, but no actual Python.
21:31
<@Derakon>
In short: tricky.
21:41
<@Derakon>
...hm, this gets worse, since I'm actually allocating two distinct buffers.
21:41
<@Derakon>
Though I can eliminate one of those...
21:42
<@Derakon>
Yeah, that's gone but I still have a memory leak because of the other buffer. :\
21:45
<@Kazriko>
There's StringIO for building strings as if they were files, but i'm not sure as to its internal implementation.
21:45
<@Derakon>
Hokay, there's a solution that works and doesn't leak memory, but it required me to write a one-off wrapper for a specific function.
21:45
<@Derakon>
That's not so good for generalizing to all functions that return strings in this fashion.
21:46
<@Kazriko>
http://www.python.org/dev/peps/pep-3137/ << Buffers in python 3.x?
21:49
<@Derakon>
(This solution involves telling SWIG "Okay, replace this function with a function that allocates a wchar_t buffer, calls the original function, allocations a char buffer, copies the wchar_t buffer to it, creates a PyObject from the char buffer, then frees both buffers and returns the PyObject"
21:49
<@Derakon>
The only part of that that's function-specific is where the original function is called, mind you...
21:49
<@Derakon>
Seems like it %Bshould%B be possible to generalize.
21:50
<@Derakon>
Er. should
22:40 AnnoDomini [annodomini@Nightstar-f7eedefa.80-203-17.nextgentel.com] has quit [[NS] Quit: Zzz.]
23:17 * Derakon eyes wcstombs.
23:17
<@Derakon>
Why aren't you inserting a null character at the end of the array?
23:18
<@Derakon>
I'm having to set it manually. What the heck.
23:23
<@McMartin>
Does the length not include the null?
23:24
<@Derakon>
Here, this is what I'm talking about: http://paste.ubuntu.com/674868/
23:24
<@Derakon>
If I don't have line 6, then when I print cBuffer it wanders off the end of the array.
23:26
<@McMartin>
That's because wcslen doesn't include the null character
23:26
<@McMartin>
So you're running out of space because it doesn't have "room" to convert it.
23:27
<@McMartin>
n is wcstombs isn't the "length of the string", it's the size of the destination buffer
23:27
<@Derakon>
Derp. Thank you.
23:27
<@McMartin>
So it's running out of space - or so it thinks - before it can convert the terminator
23:27
<@Derakon>
Yes, once you said the line about not having room I got it.
23:27
<@McMartin>
Also, this code will break if you actually have any multibyte chars; you should call it with n=0 and buffer=NULL first to get the amount of space you need to malloc.
23:27
<@Derakon>
Clearly I am le tired.
23:28
<@McMartin>
Er
23:28
<@McMartin>
plus 1
23:28
<@Derakon>
I didn't follow that bit...
23:28
<@McMartin>
instead of having len be wcslen(wideStr)
23:29
<@McMartin>
the man page suggests using wcstombs(NULL,src,0)+1
23:29
<@McMartin>
Then that is your amount of bytes to malloc and the size of the buffer you pass in
23:29
<@Derakon>
Ah.
23:29
<@McMartin>
That will - in the event that some characters *do* require multiple bytes - ensure space for exactly enough to hold them.
23:30
<@Derakon>
Right, makes sense.
23:30
<@McMartin>
However, it can also return (size_t)(-1), which means "this has characters I can't convert".
23:30
<@McMartin>
You probably don't want to try to malloc that. -_-
23:31
<@Derakon>
Is that "negative size_t" or "one less than maxint"?
23:31
<@Derakon>
Or something else?
23:31
<@McMartin>
That is, in fact, "precisely MAXINT", since size_t is unsigned and twos-complement
23:31
<@Derakon>
Oh, right, a cast.
23:31
<@McMartin>
It might even be MAXINT64.
23:31
<@McMartin>
Whatever that's really called.
23:33
<@Derakon>
Man, I am missing semicolons every time.
23:34
<@Derakon>
In the absence of the desire to properly handle this, I'll just return "Whoops, that didn't work at all!" if invalid characters show up. >.>
23:34
<@Derakon>
Maybe I'll deal with it properly tomorrow when my brain returns.
23:36
<@Derakon>
Oh look, I managed to trigger that behavior. I guess trying to print the 1024 characters that come after 'a' doesn't work so well~
23:37
<@Derakon>
Guess i'll need to figure out a saner default buffer size.
23:46
<@McMartin>
Odd, that should work if your default locale is UTF-8
23:53 * McMartin shakes the spiders out of his brain
23:59 Derakon [chriswei@Nightstar-c826c088.ca.comcast.net] has quit [[NS] Quit: leaving]
--- Log closed Fri Aug 26 00:00:26 2011
code logs -> 2011 -> Thu, 25 Aug 2011< code.20110824.log - code.20110826.log >

[ Latest log file ]