Don't pass 'long' vars over process boundary

The only place 'long' was used was in scrollbar identifiers.  These are
now "truncated" to fit inside 32 bit (when compiling for 64 bit).
This commit is contained in:
Bjorn Winckler
2009-09-27 21:52:06 +02:00
parent fc05fb5e3e
commit 2b77fe974e
9 changed files with 75 additions and 59 deletions
+5 -5
View File
@@ -95,12 +95,12 @@
- (char *)browseForFileWithAttributes:(NSDictionary *)attr;
- (int)showDialogWithAttributes:(NSDictionary *)attr textField:(char *)txtfield;
- (void)showToolbar:(int)enable flags:(int)flags;
- (void)createScrollbarWithIdentifier:(long)ident type:(int)type;
- (void)destroyScrollbarWithIdentifier:(long)ident;
- (void)showScrollbarWithIdentifier:(long)ident state:(int)visible;
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(long)ident;
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type;
- (void)destroyScrollbarWithIdentifier:(int32_t)ident;
- (void)showScrollbarWithIdentifier:(int32_t)ident state:(int)visible;
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident;
- (void)setScrollbarThumbValue:(long)val size:(long)size max:(long)max
identifier:(long)ident;
identifier:(int32_t)ident;
- (void)setFont:(GuiFont)font wide:(BOOL)wide;
- (void)executeActionWithName:(NSString *)name;
- (void)setMouseShape:(int)shape;
+15 -15
View File
@@ -860,39 +860,39 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
[self queueMessage:ShowToolbarMsgID data:data];
}
- (void)createScrollbarWithIdentifier:(long)ident type:(int)type
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type
{
NSMutableData *data = [NSMutableData data];
[data appendBytes:&ident length:sizeof(long)];
[data appendBytes:&ident length:sizeof(int32_t)];
[data appendBytes:&type length:sizeof(int)];
[self queueMessage:CreateScrollbarMsgID data:data];
}
- (void)destroyScrollbarWithIdentifier:(long)ident
- (void)destroyScrollbarWithIdentifier:(int32_t)ident
{
NSMutableData *data = [NSMutableData data];
[data appendBytes:&ident length:sizeof(long)];
[data appendBytes:&ident length:sizeof(int32_t)];
[self queueMessage:DestroyScrollbarMsgID data:data];
}
- (void)showScrollbarWithIdentifier:(long)ident state:(int)visible
- (void)showScrollbarWithIdentifier:(int32_t)ident state:(int)visible
{
NSMutableData *data = [NSMutableData data];
[data appendBytes:&ident length:sizeof(long)];
[data appendBytes:&ident length:sizeof(int32_t)];
[data appendBytes:&visible length:sizeof(int)];
[self queueMessage:ShowScrollbarMsgID data:data];
}
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(long)ident
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident
{
NSMutableData *data = [NSMutableData data];
[data appendBytes:&ident length:sizeof(long)];
[data appendBytes:&ident length:sizeof(int32_t)];
[data appendBytes:&pos length:sizeof(int)];
[data appendBytes:&len length:sizeof(int)];
@@ -900,7 +900,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
}
- (void)setScrollbarThumbValue:(long)val size:(long)size max:(long)max
identifier:(long)ident
identifier:(int32_t)ident
{
float fval = max-size+1 > 0 ? (float)val/(max-size+1) : 0;
float prop = (float)size/(max+1);
@@ -911,7 +911,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
NSMutableData *data = [NSMutableData data];
[data appendBytes:&ident length:sizeof(long)];
[data appendBytes:&ident length:sizeof(int32_t)];
[data appendBytes:&fval length:sizeof(float)];
[data appendBytes:&prop length:sizeof(float)];
@@ -2222,7 +2222,7 @@ static void netbeansReadCallback(CFSocketRef s,
if (!data) return;
const void *bytes = [data bytes];
long ident = *((long*)bytes); bytes += sizeof(long);
int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t);
int hitPart = *((int*)bytes); bytes += sizeof(int);
float fval = *((float*)bytes); bytes += sizeof(float);
scrollbar_T *sb = gui_find_scrollbar(ident);
@@ -2267,12 +2267,12 @@ static void netbeansReadCallback(CFSocketRef s,
// need to set the knob position in the other cases.
if (sb->wp) {
// Update both the left&right vertical scrollbars.
long identLeft = sb->wp->w_scrollbars[SBAR_LEFT].ident;
long identRight = sb->wp->w_scrollbars[SBAR_RIGHT].ident;
int32_t idL = (int32_t)sb->wp->w_scrollbars[SBAR_LEFT].ident;
int32_t idR = (int32_t)sb->wp->w_scrollbars[SBAR_RIGHT].ident;
[self setScrollbarThumbValue:value size:size max:max
identifier:identLeft];
identifier:idL];
[self setScrollbarThumbValue:value size:size max:max
identifier:identRight];
identifier:idR];
} else {
// Update the horizontal scrollbar.
[self setScrollbarThumbValue:value size:size max:max
+5 -5
View File
@@ -656,24 +656,24 @@ static BOOL isUnsafeMessage(int msgid);
[windowController showToolbar:enable size:size mode:mode];
} else if (CreateScrollbarMsgID == msgid) {
const void *bytes = [data bytes];
long ident = *((long*)bytes); bytes += sizeof(long);
int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t);
int type = *((int*)bytes); bytes += sizeof(int);
[windowController createScrollbarWithIdentifier:ident type:type];
} else if (DestroyScrollbarMsgID == msgid) {
const void *bytes = [data bytes];
long ident = *((long*)bytes); bytes += sizeof(long);
int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t);
[windowController destroyScrollbarWithIdentifier:ident];
} else if (ShowScrollbarMsgID == msgid) {
const void *bytes = [data bytes];
long ident = *((long*)bytes); bytes += sizeof(long);
int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t);
int visible = *((int*)bytes); bytes += sizeof(int);
[windowController showScrollbarWithIdentifier:ident state:visible];
} else if (SetScrollbarPositionMsgID == msgid) {
const void *bytes = [data bytes];
long ident = *((long*)bytes); bytes += sizeof(long);
int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t);
int pos = *((int*)bytes); bytes += sizeof(int);
int len = *((int*)bytes); bytes += sizeof(int);
@@ -681,7 +681,7 @@ static BOOL isUnsafeMessage(int msgid);
identifier:ident];
} else if (SetScrollbarThumbMsgID == msgid) {
const void *bytes = [data bytes];
long ident = *((long*)bytes); bytes += sizeof(long);
int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t);
float val = *((float*)bytes); bytes += sizeof(float);
float prop = *((float*)bytes); bytes += sizeof(float);
+5 -5
View File
@@ -43,12 +43,12 @@
- (void)selectTabWithIndex:(int)idx;
- (NSTabViewItem *)addNewTabViewItem;
- (void)createScrollbarWithIdentifier:(long)ident type:(int)type;
- (BOOL)destroyScrollbarWithIdentifier:(long)ident;
- (BOOL)showScrollbarWithIdentifier:(long)ident state:(BOOL)visible;
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type;
- (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident;
- (BOOL)showScrollbarWithIdentifier:(int32_t)ident state:(BOOL)visible;
- (void)setScrollbarThumbValue:(float)val proportion:(float)prop
identifier:(long)ident;
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(long)ident;
identifier:(int32_t)ident;
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident;
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore;
+14 -14
View File
@@ -38,12 +38,12 @@ enum {
// TODO: Move!
@interface MMScroller : NSScroller {
long identifier;
int32_t identifier;
int type;
NSRange range;
}
- (id)initWithIdentifier:(long)ident type:(int)type;
- (long)identifier;
- (id)initWithIdentifier:(int32_t)ident type:(int)type;
- (int32_t)identifier;
- (int)type;
- (NSRange)range;
- (void)setRange:(NSRange)newRange;
@@ -56,7 +56,7 @@ enum {
- (BOOL)rightScrollbarVisible;
- (void)placeScrollbars;
- (int)representedIndexOfTabViewItem:(NSTabViewItem *)tvi;
- (MMScroller *)scrollbarForIdentifier:(long)ident index:(unsigned *)idx;
- (MMScroller *)scrollbarForIdentifier:(int32_t)ident index:(unsigned *)idx;
- (NSSize)vimViewSizeForTextViewSize:(NSSize)textViewSize;
- (NSRect)textViewRectForVimViewSize:(NSSize)contentSize;
- (NSTabView *)tabView;
@@ -374,7 +374,7 @@ enum {
return tvi;
}
- (void)createScrollbarWithIdentifier:(long)ident type:(int)type
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type
{
MMScroller *scroller = [[MMScroller alloc] initWithIdentifier:ident
type:type];
@@ -386,7 +386,7 @@ enum {
[scroller release];
}
- (BOOL)destroyScrollbarWithIdentifier:(long)ident
- (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident
{
unsigned idx = 0;
MMScroller *scroller = [self scrollbarForIdentifier:ident index:&idx];
@@ -400,7 +400,7 @@ enum {
return ![scroller isHidden];
}
- (BOOL)showScrollbarWithIdentifier:(long)ident state:(BOOL)visible
- (BOOL)showScrollbarWithIdentifier:(int32_t)ident state:(BOOL)visible
{
MMScroller *scroller = [self scrollbarForIdentifier:ident index:NULL];
if (!scroller) return NO;
@@ -414,7 +414,7 @@ enum {
}
- (void)setScrollbarThumbValue:(float)val proportion:(float)prop
identifier:(long)ident
identifier:(int32_t)ident
{
MMScroller *scroller = [self scrollbarForIdentifier:ident index:NULL];
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
@@ -430,18 +430,18 @@ enum {
- (void)scroll:(id)sender
{
NSMutableData *data = [NSMutableData data];
long ident = [(MMScroller*)sender identifier];
int32_t ident = [(MMScroller*)sender identifier];
int hitPart = [sender hitPart];
float value = [sender floatValue];
[data appendBytes:&ident length:sizeof(long)];
[data appendBytes:&ident length:sizeof(int32_t)];
[data appendBytes:&hitPart length:sizeof(int)];
[data appendBytes:&value length:sizeof(float)];
[vimController sendMessage:ScrollbarEventMsgID data:data];
}
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(long)ident
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident
{
MMScroller *scroller = [self scrollbarForIdentifier:ident index:NULL];
NSRange range = NSMakeRange(pos, len);
@@ -754,7 +754,7 @@ enum {
return [tabViewItems indexOfObject:tvi];
}
- (MMScroller *)scrollbarForIdentifier:(long)ident index:(unsigned *)idx
- (MMScroller *)scrollbarForIdentifier:(int32_t)ident index:(unsigned *)idx
{
unsigned i, count = [scrollbars count];
for (i = 0; i < count; ++i) {
@@ -871,7 +871,7 @@ enum {
@implementation MMScroller
- (id)initWithIdentifier:(long)ident type:(int)theType
- (id)initWithIdentifier:(int32_t)ident type:(int)theType
{
// HACK! NSScroller creates a horizontal scroller if it is init'ed with a
// frame whose with exceeds its height; so create a bogus rect and pass it
@@ -892,7 +892,7 @@ enum {
return self;
}
- (long)identifier
- (int32_t)identifier
{
return identifier;
}
+5 -5
View File
@@ -51,12 +51,12 @@
- (void)setTitle:(NSString *)title;
- (void)setDocumentFilename:(NSString *)filename;
- (void)setToolbar:(NSToolbar *)toolbar;
- (void)createScrollbarWithIdentifier:(long)ident type:(int)type;
- (BOOL)destroyScrollbarWithIdentifier:(long)ident;
- (BOOL)showScrollbarWithIdentifier:(long)ident state:(BOOL)visible;
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(long)ident;
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type;
- (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident;
- (BOOL)showScrollbarWithIdentifier:(int32_t)ident state:(BOOL)visible;
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident;
- (void)setScrollbarThumbValue:(float)val proportion:(float)prop
identifier:(long)ident;
identifier:(int32_t)ident;
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore;
- (void)setFont:(NSFont *)font;
- (void)setWideFont:(NSFont *)font;
+5 -5
View File
@@ -371,12 +371,12 @@
}
}
- (void)createScrollbarWithIdentifier:(long)ident type:(int)type
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type
{
[vimView createScrollbarWithIdentifier:ident type:type];
}
- (BOOL)destroyScrollbarWithIdentifier:(long)ident
- (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident
{
BOOL scrollbarHidden = [vimView destroyScrollbarWithIdentifier:ident];
shouldResizeVimView = shouldResizeVimView || scrollbarHidden;
@@ -384,7 +384,7 @@
return scrollbarHidden;
}
- (BOOL)showScrollbarWithIdentifier:(long)ident state:(BOOL)visible
- (BOOL)showScrollbarWithIdentifier:(int32_t)ident state:(BOOL)visible
{
BOOL scrollbarToggled = [vimView showScrollbarWithIdentifier:ident
state:visible];
@@ -393,13 +393,13 @@
return scrollbarToggled;
}
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(long)ident
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident
{
[vimView setScrollbarPosition:pos length:len identifier:ident];
}
- (void)setScrollbarThumbValue:(float)val proportion:(float)prop
identifier:(long)ident
identifier:(int32_t)ident
{
[vimView setScrollbarThumbValue:val proportion:prop identifier:ident];
}
+16 -5
View File
@@ -1123,6 +1123,14 @@ gui_macvim_font_with_name(char_u *name)
// -- Scrollbars ------------------------------------------------------------
// NOTE: Even though scrollbar identifiers are 'long' we tacitly assume that
// they only use 32 bits (in particular when compiling for 64 bit). This is
// justified since identifiers are generated from a 32 bit counter in
// gui_create_scrollbar(). However if that code changes we may be in trouble
// (if ever that many scrollbars are allocated...). The reason behind this is
// that we pass scrollbar identifers over process boundaries so the width of
// the variable needs to be fixed (and why fix at 64 bit when only 32 are
// really used?).
void
gui_mch_create_scrollbar(
@@ -1130,7 +1138,7 @@ gui_mch_create_scrollbar(
int orient) /* SBAR_VERT or SBAR_HORIZ */
{
[[MMBackend sharedInstance]
createScrollbarWithIdentifier:sb->ident type:sb->type];
createScrollbarWithIdentifier:(int32_t)sb->ident type:sb->type];
}
@@ -1138,7 +1146,7 @@ gui_mch_create_scrollbar(
gui_mch_destroy_scrollbar(scrollbar_T *sb)
{
[[MMBackend sharedInstance]
destroyScrollbarWithIdentifier:sb->ident];
destroyScrollbarWithIdentifier:(int32_t)sb->ident];
}
@@ -1148,7 +1156,7 @@ gui_mch_enable_scrollbar(
int flag)
{
[[MMBackend sharedInstance]
showScrollbarWithIdentifier:sb->ident state:flag];
showScrollbarWithIdentifier:(int32_t)sb->ident state:flag];
}
@@ -1168,7 +1176,7 @@ gui_mch_set_scrollbar_pos(
}
[[MMBackend sharedInstance]
setScrollbarPosition:pos length:len identifier:sb->ident];
setScrollbarPosition:pos length:len identifier:(int32_t)sb->ident];
}
@@ -1180,7 +1188,10 @@ gui_mch_set_scrollbar_thumb(
long max)
{
[[MMBackend sharedInstance]
setScrollbarThumbValue:val size:size max:max identifier:sb->ident];
setScrollbarThumbValue:val
size:size
max:max
identifier:(int32_t)sb->ident];
}
+5
View File
@@ -3627,7 +3627,12 @@ gui_create_scrollbar(sb, type, wp)
int type;
win_T *wp;
{
#ifdef FEAT_GUI_MACVIM
/* This is passed over to another process, make sure it fits in 32 bit */
static int32_t sbar_ident = 0;
#else
static int sbar_ident = 0;
#endif
sb->ident = sbar_ident++; /* No check for too big, but would it happen? */
sb->wp = wp;