Objective C Runtime

I’m updating a project which heavily deals with the Objective C Runtime. The update is mainly about preparing the project for 64-bit. I planned to change all occurrences of Int32 and UInt32 to Integer and UInteger.

Now there is this comment on the Apple website:

When Xojo will be compiling for 64-bit on OS X, will Xojo’s Integer/UInteger work or will I get wrong results?

As an example, will the first line work, or will it have to be the latter:

Declare Function objc_copyClassList Lib "libobjc.dylib" (ByRef outCount As UInteger) As Ptr Declare Function objc_copyClassList Lib "libobjc.dylib" (ByRef outCount As UInt32) As Ptr

Then the comment continues with:

What about these 24-bit values? Can one just use Int32/UInt32, or even Integer/UInteger – or does one have to go with memory blocks and calculating the value from the single bytes in it?

that means that even if you pass in 64-bit, some functions only accept the last 32 bit.
Same for passing 32 bit and only using 24 bit.

Maybe you get an exception or an error reported if you pass in too big numbers.

It’s the other way around: these values will be returned by the Objective-C runtime (see the ByRef on the outCount parameter in my example above).

The question is: is it save to use a Xojo Integer/UInteger for 32-bit values returned by the runtime once we will be able to compile for 64-bit OS X (as an Integer or UInteger will be 64-bit then)?

Why do you want to change the fixed Integers to a flexible type? I’d rather go with the definitions that Apple lists.

Anyway, the Integer subtypes are very transparent to the compiler, so I think it won’t do any harm using a flexible (U)Integer as container for returned Int32 and the like, as long as no overflow occurs (like UInt32 -> Int32)

EDIT: But this is not true for the (external) method definition parameters. When Apple lists a UInt32, the declare should use one too or you end up trying to send the wrong number of bytes to a method.

There is no 24-bit integer in Xojo. So I have to know anyway if it is save to use a 32-bit integer for these return values. The alternative is to get a memory block, read out the three byte values and calculate them together so this value then can then be assigned to a Xojo Int32. Maybe I will dive into the ABI to see what the memory layout of the 24-bit values is – or I’ll set up a small XCode project to inspect them.

Again: the Objective-C Runtime only returns 32-bit and 24-bit values on 64-bit OS X – there is no function taking a 32-bit-sized integer as parameter.

Are you sure they use a 24bit Integer, not using merely 24 Bits of a 32Bit Int? I make a lot of use of Objective C Runtime methods in iOSLib and it works in 64bit as well as 32 – I guess they mean with sizeof they have a maximum possible value that’s below the maximum for an Integer of that type.

That’s the question I’m asking.

It is working here too on OS X. But I’d like to know. Just because something works in some test cases here, it does not mean that it will work in all cases.

I understand your concerns. I cannot say for sure. At least I read the docs that way – if they would use a special 24 bit data type (and I would wonder why – ObjC Runtime is meant to be fast –), the docs would list a structure/ptr. As long as they don’t but use an Integer type, I think you are sure to go with it. But don’t hit me if I should err!

When I read it in the Apple docs my first – naive and amateurish – thought was, they are using a 32-bit integer and one byte is used internally by the runtime for flags or whatever. So it might be problematic in the long run.

The quoted text above says simply that class size is limited to 4 GB (32bit, even for 64-bit system).
And a class can only have 2^24 as the maximum for number of methods, properties and size of a property.

Those limits are irrelevant to you as you probably will never have such a big class!

That is not the question. The question is if the 8 high-bits are filled with unwanted 1s instead of eight 0s when having a Int32 where the Objective C Runtime returns a 24-bit. I assume not, but I’d like to be sure.

the declaration in the runtime specifies int, size_t, long and other data types.
So they do have a defined bit size for the variable. Either 32 or 64-bit.

But the comment says you should not put values inside which are bigger than 24 or 32 bit.
The other bits of course must be zero.

No, it doesn’t, as this is a comment on their website only for values which are returned by the Objective C Runtime.

[quote=198443:@Christian Schmitz]The quoted text above says simply that class size is limited to 4 GB (32bit, even for 64-bit system).
And a class can only have 2^24 as the maximum for number of methods, properties and size of a property.

Those limits are irrelevant to you as you probably will never have such a big class![/quote]
If you do you probably have a much more serious design problem :stuck_out_tongue:

One class to rule them all!