How to correctly determine a small object?

2013-06-07 Thread Luboš Doležel
Hi, for toll-free bridging in CoreBase, I need a way to detect whether the incoming pointer is a small object encoded in a pointer and act accordingly (treat it as an ObjC object and avoid reading it). What is the correct approach? Thanks! -- Luboš Doležel _

Re: How to correctly determine a small object?

2013-06-07 Thread Stefan Bidi
The CF_IS_OBJC() macro will correctly identify small objects. The function objc_getClass() will return a valid ObjC class that isn't toll-free bridged and so CF_IS_OBJC() should return true. This should work. On Fri, Jun 7, 2013 at 10:29 AM, Luboš Doležel wrote: > Hi, > > for toll-free bridgi

Re: How to correctly determine a small object?

2013-06-07 Thread Luboš Doležel
I see. The problem is in CFGetTypeID() where the pointer is accessed in an unsafe way (as you noted yourself in the code). I haven't given in much thought yet, though... Lubos Dne 7. června 2013 17:41:15 Stefan Bidi napsal: The CF_IS_OBJC() macro will correctly identify small objects. The

Re: How to correctly determine a small object?

2013-06-07 Thread Stefan Bidi
Ah, I see how this can be a problem. In this case, if I remember correctly, small objects have the least significant bit set to 1. Checking for that bit should be sufficient: if ((0x01 & cf)) return _kCFRuntimeNotATypeID; On Fri, Jun 7, 2013 at 11:02 AM, Luboš Doležel wrote: > I see. The pr

Re: How to correctly determine a small object?

2013-06-07 Thread David Chisnall
On 7 Jun 2013, at 16:29, Luboš Doležel wrote: > for toll-free bridging in CoreBase, I need a way to detect whether the > incoming pointer is a small object encoded in a pointer and act accordingly > (treat it as an ObjC object and avoid reading it). In objc/runtime.h, there is a constant SMALL

Re: How to correctly determine a small object?

2013-06-07 Thread David Chisnall
On 7 Jun 2013, at 21:10, David Chisnall wrote: > On 64-bit platforms, the low 3 bits will always be zero P.S. I've done some profiling and discovered that in typical desktop applications 5-20% of objects are small strings (up to 8 7-bit ASCII chars stored in a pointer). This makes a fairly si

Re: How to correctly determine a small object?

2013-06-08 Thread Luboš Doležel
On 06/07/2013 10:10 PM, David Chisnall wrote: On 7 Jun 2013, at 16:29, Luboš Doležel wrote: for toll-free bridging in CoreBase, I need a way to detect whether the incoming pointer is a small object encoded in a pointer and act accordingly (treat it as an ObjC object and avoid reading it). In

Re: How to correctly determine a small object?

2013-06-08 Thread Maxthon Chan
So I can safely do this? (Macro rewritten as inline function) static inline __attribute__((always_inline)) BOOL objc_isSmallObject(id obj) { return (((intptr_t)obj) & 1) ? YES : NO; } 在 2013-6-8,上午4:10,David Chisnall 写道: > On 7 Jun 2013, at 16:29, Luboš Doležel wrote: > >> for toll-fr

Re: How to correctly determine a small object?

2013-06-08 Thread David Chisnall
No. See the email you replied to for why not. David On 8 Jun 2013, at 18:20, Maxthon Chan wrote: > So I can safely do this? (Macro rewritten as inline function) > > static inline __attribute__((always_inline)) BOOL objc_isSmallObject(id obj) > { > return (((intptr_t)obj) & 1) ? YES : NO

Re: How to correctly determine a small object?

2013-06-08 Thread Chan Maxthon
I am expecting a solution that works on both OS X and GNUstep. 发自我的 iPhone 在 2013-6-9,1:28,David Chisnall 写道: > No. See the email you replied to for why not. > > David > > On 8 Jun 2013, at 18:20, Maxthon Chan wrote: > >> So I can safely do this? (Macro rewritten as inline function) >> >>

Re: How to correctly determine a small object?

2013-06-08 Thread Ivan Vučica
On Sat, Jun 8, 2013 at 9:55 PM, Chan Maxthon wrote: > I am expecting a solution that works on both OS X and GNUstep. > Why? This is an implementation detail which can differ on OS X and GNUstep. As far as I understand it, it's only needed inside CoreBase/Core Foundation. Why would you need to e

Re: How to correctly determine a small object?

2013-06-08 Thread Chan Maxthon
I am sort of looking into the concept of running Objective-C in a kernel of an operating system, which would require implementing a (partial) libobjc2 and Foundation that can run on bare metal. Since all my develop machines have clang I can exchange compiled object files in LLVM bitcode and only

Re: How to correctly determine a small object?

2013-06-08 Thread Ivan Vučica
Hi Maxthon, I believe you'll really want to compile everything on the same platform, or cross-compile for the target platform. I don't think you'll be able to easily mix code targeting the GNUstep runtime with code targeting the NeXT runtime. The only reason that I can think of why you might have

Re: How to correctly determine a small object?

2013-06-08 Thread Chan Maxthon
Well that is why I am using LLVM bit code as the object file format (I have -emit-llvm lying in my Makefile's CFLAGS) as it is largely ABI and platform insensitive. And I also have -ffreestanding to make sure that the resulting bit code is suitable for bare metal execution. 发自我的 iPhone 在 2013-

Re: How to correctly determine a small object?

2013-06-09 Thread Graham Lee
This has been done. The search term you're looking for is DriverKit. Graham. Sent from my David Chisnall .sigfile generator On 8 Jun 2013, at 22:51, "Chan Maxthon" wrote: > I am sort of looking into the concept of running Objective-C in a kernel of > an operating system ___

Re: How to correctly determine a small object?

2013-06-09 Thread Graham Lee
And as soon as I'd sent that, I remembered reading about a kernel Objective-C implementation on Linux. Here it is: http://www.abdn.ac.uk/piprg/wiki/index.php?title=KCSP_an_Environment_for_Component_Based_Development_of_Linux_Kernel_Code Graham. Sent from my bed On 9 Jun 2013, at 08:06, "Graham

Re: How to correctly determine a small object?

2013-06-09 Thread Maxthon Chan
I am sort of looking at a microkernel design - inside the kernel there are only 2 drivers: tmpfs (implemented on top of NSDictionary and NSData) and tar (on top of NSArray and NSData) to make initramfs (which is a simple tar archive of all pre-filesystem kexts and services) work, and everything

Re: How to correctly determine a small object?

2013-06-09 Thread David Chisnall
On 8 Jun 2013, at 22:51, Chan Maxthon wrote: > I am sort of looking into the concept of running Objective-C in a kernel of > an operating system, which would require implementing a (partial) libobjc2 > and Foundation that can run on bare metal The question makes even less sense in that context

Re: How to correctly determine a small object?

2013-06-09 Thread David Chisnall
On 8 Jun 2013, at 23:14, Chan Maxthon wrote: > I am using LLVM bit code as the object file format (I have -emit-llvm lying > in my Makefile's CFLAGS) as it is largely ABI and platform insensitive This is not even slightly true. There is a long document on the LLVM web site that explains why n