Re: [MacRuby-devel] Porting Cocoa OpenGL sample code

2009-03-06 Thread Brian Chapados
I'm not sure what's happening with the pointer to an array of longs in
the first case. It looks like the Pointer is being created, but there
is no way to assign/retrieve values?

p = Pointer.new_with_type('^L')
p.assign([1,2,3])
p[0][1]  # => 2

I think the reason that this works is that rb_objc_rval_to_ocval seems
to only handle assigning a ruby array to an ObjC pointer type ("^").

I guess you could just go with it, but if the function you are passing
to will write to that address, then you need to ensure that the space
has been allocated (see below). When you call assign with an array,
it's like writing something like this in C:

unsigned long *p[1];
unsigned long array[3] = {1,2,3};
*p = array;  // same as p[0] = array;
*p[1]; // => 2

Ideally you just want a real C array:

unsigned long[10];

or the dynamically allocated equivalent.

The issue here is that CGGetActiveDisplayList is going to write data
to the pointer you pass it, and it is your responsibility to make sure
that you own that memory.  If you tell MacRuby that you want a pointer
to "^L", it reserves space for the pointer, but not space to hold the
data.  When you assign a ruby array to the pointer, the Pointer class
dynamically allocates space for each element in the array, so if
you're going to use that method, I think you might need to assign a
blank array of the proper size before you pass the pointer to
function:

p = Pointer.new_with_type('^L')
p.assign(Array.new(count,0))
count_p = Pointer.new_with_type("L")
CGGetActiveDisplayList(count, p[0], count_p)

This is my understanding from reading through objc.m, someone please
correct me if I'm wrong about this.

Brian

On Fri, Feb 27, 2009 at 8:57 AM, Julien Jassaud  wrote:
> Brian,
> Thanks for the very detailed answer. This tremendously helps. I am now
> having problems with arrays, though. I try to make a pointer to an array of
> 32 longs, like this :
>>> p = Pointer.new_with_type('[32L]')
> => #
>>> p[0]
> ArgumentError: can't convert C/Objective-C value `0x80052ae40' of type
> `[32i]' to Ruby object
> from (irb):49:in `[]'
> from (irb):49
> from /usr/local/bin/macirb:12:in `'
> Am I not getting the syntax explained in the documentation page you
> mentioned ?
> Also, something is puzzling me. In C, arrays are pointers so I thought I
> could solve the problem (and it works) by doing :
>>> p=Pointer.new_with_type('^L')
> => #
>>> p.assign([1,2,3])
> => [1, 2, 3]
>>> p[0][1]
> => 2
> Great ! I have a pointer to something that looks like an array of longs (and
> it seems to satisfy the CGGetActiveDisplayList function). But how is it
> possible when everything here is an object and not a series of neatly
> aligned bytes ?
> Anyway, you are right. The part of Cocoa OpenGL I am porting now probably
> doesn't need to and should be wrapped in an Objective-C object.
> Thanks,
> Julien Jassaud
> Le 26 févr. 09 à 05:43, Brian Chapados a écrit :
>
> Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
>
> incantation only known by the MacRuby/Obj overlords?
>
> Yes, it is actually a 7th level spell: 'Encode Structure'.  To learn
> it, you must study the ancient tome:
> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
>
> If it makes you feel better, I usually need to look it up (or just
> run the Obj-C code sample), unless it is something simple (like '@').
> I don't keep this spell in memory, as it is only required in special
> situations.
>
> Seriously though, that is actually how you encode a pointer to a
> struct.  If you use the @encode(type) directive, the compiler will
> return the runtime encoding for 'type'.  It's a bit cryptic, but not
> too bad once you know the syntax:
>
> '^type' encodes a pointer to type.
> '{name=...}'
> encodes a struct with N fields.
>
> To break it down using 2 examples:
>
> (from the docs)
> typedef struct example {
>    id   anObject; // encoding = @
>    char *aString; // encoding = c
>    int  anInt; // enoding = i
> } Example;
>
> @encode(Example) = "^{examp...@ci}"
>
> CGLRendererInfoObj is a pointer to an opaque struct (we don't know
> anything about the fields) named _CGLRendererInfoObject. All we know
> is:
> typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;
>
> so it's just "^{_CGLRendererInfoObject=}"
>
> In practice (unless you're working with CoreFoundation C APIs) you
> usually just need a pointer to an object.  The most common usage I run
> across is to retrieve NSError objects.  The CoreFoundation C API uses
> pass-by-reference extensively.  To use these functions with MacRuby,
> you need to create lots of pointer objects. In general, this is an
> area where interfacing ruby with C is just fugly.  I'd personally
> avoid doing this in MacRuby.  If you find yourself needing to use lots
> Pointer objects, it's probably better and less error-prone to write
> that code in C and expose it to MacRuby through an Objective-C
> interfa

Re: [MacRuby-devel] Recent changes cause gem statement to fail

2009-03-06 Thread Laurent Sansonetti

Hi Scott / Rich,

I fixed a few things in trunk and now the new stdlib should be working  
as before. RubyGems should even be better than before, I was able to  
install a few basic gems and require them from macirb (but not able to  
install a gem with a dependency, though).


I tested miniunit and rake. I also verified that all samples are  
working as before and that our tests are running too. So 0.4 is not  
far now!


Laurent

On Mar 2, 2009, at 7:55 PM, Richard Kilmer wrote:


Scott,

We merged in the lib directory from 1.9.1_0 tag (there were over 250  
changes since last time Laurent merged).  We are now going through  
and validating things (including RubyGems).


For the next few days trunk will (thus) be a tad unstable.

Best,

Rich

On Mar 2, 2009, at 10:00 PM, M. Scott Ford wrote:


Hello,

I just grabbed the latest from trunk (r831), and the following  
section from my rakefile causes the macruby process to hang. 	It  
seems to be the gem call that is causing the problem. Commenting  
that line out allows execution to proceed. I will keep  
investigating, but wanted to report this early. I would really like  
to see this fixed before 0.4 is released.


Thanks,
-Scott

ENV['GEM_PATH']=File.expand_path("#{File.dirname(__FILE__)}/vendor/ 
gems")

require "rubygems"
Gem.clear_paths
gem_paths = [
File.expand_path("#{File.dirname(__FILE__)}/vendor/gems")
]
Gem.send :set_paths, gem_paths.join(":")

gem 'cucumber'

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] [MacRuby] #161: `macgem install` fails for the "wirble" gem

2009-03-06 Thread MacRuby
#161: `macgem install` fails for the "wirble" gem
--+-
 Reporter:  macruby@… |Owner:  lsansone...@…
 Type:  defect|   Status:  closed   
 Priority:  minor |Milestone:  MacRuby 0.4  
Component:  MacRuby   |   Resolution:  fixed
 Keywords:|  
--+-
Changes (by lsansone...@…):

  * status:  new => closed
  * resolution:  => fixed
  * milestone:  => MacRuby 0.4


Comment:

 {{{
 $ sudo macgem install wirble --no-ri --no-rdoc
 Successfully installed wirble-0.1.2
 1 gem installed
 $ macirb
 >> gem 'wirble'
 => true
 >> MACRUBY_REVISION
 => "svn revision 835 from
 http://svn.macosforge.org/repository/ruby/MacRuby/trunk";
 >>
 }}}

-- 
Ticket URL: 
MacRuby 

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] [MacRuby] #202: Implement Numeric methods on NSNumber

2009-03-06 Thread MacRuby
#202: Implement Numeric methods on NSNumber
-+--
 Reporter:  eloy.de.en...@…  |Owner:  eloy.de.en...@…
 Type:  enhancement  |   Status:  closed 
 Priority:  blocker  |Milestone:  MacRuby 0.4
Component:  MacRuby  |   Resolution:  fixed  
 Keywords:   |  
-+--
Changes (by lsansone...@…):

  * status:  new => closed
  * resolution:  => fixed
  * milestone:  => MacRuby 0.4


Comment:

 Merged as r837.

-- 
Ticket URL: 
MacRuby 

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] [MacRuby] #226: rake fails with stringio (LoadError)

2009-03-06 Thread MacRuby
#226: rake fails with stringio (LoadError)
---+
 Reporter:  a...@… |   Owner:  lsansone...@… 
 Type:  defect |  Status:  new   
 Priority:  blocker|   Milestone:  MacRuby 0.4   
Component:  MacRuby|Keywords:  building rake stringio
---+
 I cannot build the trunk since rel 829. I get the following error:
 {{{
 (in /Users/adam/Code/MacRuby/MacRuby-trunk)
 ./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ext/extmk.rb
 --make="/usr/bin/make" --dest-dir="" --extout=".ext" --mflags="" --make-
 flags="" --extension --extstatic -- clean
 /Users/adam/Code/MacRuby/MacRuby-trunk/lib/yaml.rb:9:in `require': no such
 file to load -- stringio (LoadError)
 from /Users/adam/Code/MacRuby/MacRuby-trunk/lib/yaml.rb:9:in `'
 from /Users/adam/Code/MacRuby/MacRuby-
 trunk/lib/rubygems/config_file.rb:7:in `require'
 from /Users/adam/Code/MacRuby/MacRuby-
 trunk/lib/rubygems/config_file.rb:7:in `'
 from /Users/adam/Code/MacRuby/MacRuby-trunk/lib/rubygems.rb:883:in
 `require'
 from /Users/adam/Code/MacRuby/MacRuby-trunk/lib/rubygems.rb:883:in
 `'
 from /Users/adam/Code/MacRuby/MacRuby-trunk/lib/ubygems.rb:10:in
 `require'
 from /Users/adam/Code/MacRuby/MacRuby-trunk/lib/ubygems.rb:10:in
 `'
 from :0:in `require:'
 rake aborted!
 Command failed with status (1): [./miniruby -I./lib -I.ext/common -I./-
 -r]
 /Users/adam/Code/MacRuby/MacRuby-trunk/rakefile:644
 (See full trace by running task with --trace)
 }}}

 Any ideas?

-- 
Ticket URL: 
MacRuby 

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] [MacRuby] #226: rake fails with stringio (LoadError)

2009-03-06 Thread MacRuby
#226: rake fails with stringio (LoadError)
---+
 Reporter:  a...@… |   Owner:  lsansone...@… 
 Type:  defect |  Status:  new   
 Priority:  blocker|   Milestone:
Component:  MacRuby|Keywords:  building rake stringio
---+
Changes (by lsansone...@…):

  * milestone:  MacRuby 0.4 =>


Comment:

 Could you retry from a fresh/clean repository?

-- 
Ticket URL: 
MacRuby 

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] [MacRuby] #226: rake fails with stringio (LoadError)

2009-03-06 Thread MacRuby
#226: rake fails with stringio (LoadError)
---+
 Reporter:  a...@… |   Owner:  lsansone...@… 
 Type:  defect |  Status:  new   
 Priority:  blocker|   Milestone:
Component:  MacRuby|Keywords:  building rake stringio
---+

Comment(by a...@…):

 Replying to [comment:1 lsansone...@…]:
 > Could you retry from a fresh/clean repository?

  Same error, here's the build log from a fresh checkout:

 {{{
 (in /Users/adam/Code/MacRuby/MacRuby-trunk)
 mkdir -p .ext/include/universal-darwin9.0/ruby
 cp include/ruby/config.h .ext/include/universal-darwin9.0/ruby
 /usr/sbin/dtrace -h -s dtrace.d -o new_dtrace.h
 mv new_dtrace.h dtrace.h
 /usr/bin/ruby tool/compile_prelude.rb prelude.rb miniprelude.c.new
 mv miniprelude.c.new miniprelude.c
 touch prelude.c
 /usr/bin/bison -o y.tab.c parse.y
 /usr/bin/sed -f ./tool/ytab.sed -e "/^#/s!y.tab.c!parse.c!" y.tab.c >
 parse.c.new
 mv parse.c.new parse.c
 rm -f parse.o
 cp lex.c.blt lex.c
 /usr/bin/ruby -Ks tool/insns2vm.rb opt_sc.inc optinsn.inc optunifs.inc
 insns.inc insns_info.inc vmtc.inc vm.inc
 /usr/bin/ruby -n tool/node_name.rb include/ruby/node.h > node_name.inc
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c array.c -o array.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c bignum.c -o bignum.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c class.c -o class.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c compar.c -o compar.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c complex.c -o complex.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c dir.c -o dir.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c enum.c -o enum.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c enumerator.c -o enumerator.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c error.c -o error.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c eval.c -o eval.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c load.c -o load.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c proc.c -o proc.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c file.c -o file.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c gc.c -o gc.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c hash.c -o hash.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c inits.c -o inits.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c io.c -o io.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c marshal.c -o marshal.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-common -pipe -O2 -g -Wall -Wno-parentheses -Wno-deprecated-
 declarations -Werror -c math.c -o math.o
 /usr/bin/gcc -I. -I./include -I/usr/include/libxml2 -arch i386 -arch
 x86_64 -fno-