Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EdgeInsets missing function in value #470

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
2024-11-26 Matvii Jarosh <[email protected]>

* NSByteOrder.h: fix NSSwappedFloat and NSSwappedDouble
* MISSING:

2024-11-25 Matvii Jarosh <[email protected]>

* NSInvocation.h: add enum _NSObjCValueType and
typedef structNSObjCValue. There are no functions not implemented
in NSInvocation.h left.
* MISSING:

2024-11-21 Matvii Jarosh <[email protected]>

* NSValue: add valueWithEdgeInsets and edgeInsetsValue.
* typeEncodingHelper.h: add NSINSETS_ENCODING_PREFIX and
IS_NSINSETS_ENCODING and update comment.
* type_encoding.m: add test NSINSETS_ENCODING_PREFIX.
* GSConcreteValueTamplate.m: add GSEdgeInsetsValue.
* GSConcreteValue.m: add TYPE_ORDER 6.

2024-11-19 Richard Frith-Macdonald <[email protected]>

* GSMime: fixed buffer overrun in rare circumstances when decoding
Expand Down
24 changes: 24 additions & 0 deletions Headers/Foundation/NSByteOrder.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,37 @@ NSSwapShort(unsigned short in)
static inline NSSwappedDouble
NSSwapDouble(NSSwappedDouble num)
{
#if GS_SIZEOF_DOUBLE == 2
return GSSwapI16(num);
#else
#if GS_SIZEOF_DOUBLE == 4
return GSSwapI32(num);
#else
#if GS_SIZEOF_DOUBLE == 8
return GSSwapI64(num);
#else
return GSSwapI128(num);
#endif
#endif
#endif
}

static inline NSSwappedFloat
NSSwapFloat(NSSwappedFloat num)
{
#if GS_SIZEOF_FLOAT == 2
return GSSwapI16(num);
#else
#if GS_SIZEOF_FLOAT == 4
return GSSwapI32(num);
#else
#if GS_SIZEOF_FLOAT == 8
return GSSwapI64(num);
#else
return GSSwapI128(num);
#endif
#endif
#endif
}

#if GS_WORDS_BIGENDIAN
Expand Down
42 changes: 42 additions & 0 deletions Headers/Foundation/NSInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import <GNUstepBase/GSVersionMacros.h>

#import <Foundation/NSMethodSignature.h>
#include <stdbool.h>

#if defined(__cplusplus)
extern "C" {
Expand Down Expand Up @@ -154,6 +155,47 @@ GS_EXPORT_CLASS
[NSInvocation _returnInvocationAndDestroyProxy: __proxy]; \
})

typedef NS_ENUM(char, _NSObjCValueType)
{
NSObjCArrayType = '[',
NSObjCBitfield = 'b',
NSObjCBoolType = 'B',
NSObjCCharType = 'c',
NSObjCDoubleType = 'd',
NSObjCFloatType = 'f',
NSObjCLonglongType = 'q',
NSObjCLongType = 'l',
NSObjCNoType = '\0',
NSObjCObjectType = '@',
NSObjCPointerType = '^',
NSObjCSelectorType = ':',
NSObjCShortType = 's',
NSObjCStringType = '*',
NSObjCStructType = '{',
NSObjCUnionType = '(',
NSObjCVoidType = 'v',
};

typedef struct
{
_NSObjCValueType type;
union
{
bool boolValue;
char charValue;
double doubleValue;
float floatValue;
long long longlongValue;
long longValue;
id objectValue;
void *pointerValue;
SEL selectorValue;
short shortValue;
char *cStringLocation;
void *structLocation;
} value;
} NSObjCValue;

#if defined(__cplusplus)
}
#endif
Expand Down
16 changes: 16 additions & 0 deletions Headers/Foundation/NSValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ GS_EXPORT_CLASS
*/
+ (NSValue*) valueWithSize: (NSSize)size;

#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
/**
* Convenience method to create instance holding an <code>NSEdgeInsets</code>
* structure.
*/
+ (NSValue*) valueWithEdgeInsets: (NSEdgeInsets)insets;
#endif

#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
/**
* Synonym for value:withObjCType: .
Expand Down Expand Up @@ -166,6 +174,14 @@ GS_EXPORT_CLASS
*/
- (NSPoint) pointValue;

#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
/**
* If receiver was initialized with an <code>NSEdgeInsets</code> value, return it,
* else raises <code>NSInternalInconsistencyException</code>.
*/
- (NSEdgeInsets) edgeInsetsValue;
#endif

@end

/**
Expand Down
11 changes: 2 additions & 9 deletions MISSING
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ NSBundle:
/** Not implemented */ (GNUstep comment)
- executableArchitectures;
-------------------------------------------------------------
NSByteOrder:
NSSwappedFloat — incompatible declaration
NSSwappedDouble — incompatible declaration
-------------------------------------------------------------
NSCalendar:
NSWeekOfMonthCalendarUnit
NSWeekOfYearCalendarUnit
Expand Down Expand Up @@ -257,12 +253,7 @@ NSIndexSet:
- enumerateRangesUsingBlock:
- enumerateRangesWithOptions:usingBlock:
- enumerateRangesInRange:options:usingBlock:
-------------------------------------------------------------
NSInvocation:
<stdbool.h>

enum _NSObjCValueType
typedef struct NSObjCValue
-------------------------------------------------------------
NSKeyedArchiver:
<NSGeometry.h>
Expand Down Expand Up @@ -885,3 +876,5 @@ Good headers:
<NSXMLDTD.h>
<NSXMLDTDNode.h>
<NSXMLElement.h>
<NSInvocation.h>
<NSByteOrder.h>
4 changes: 4 additions & 0 deletions Source/GSConcreteValue.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@
#include "GSConcreteValueTemplate.m"
#undef TYPE_ORDER

#define TYPE_ORDER 6
#include "GSConcreteValueTemplate.m"
#undef TYPE_ORDER

29 changes: 29 additions & 0 deletions Source/GSConcreteValueTemplate.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ @interface GSSizeValue : NSValue
# define GSTemplateValue GSSizeValue
# define TYPE_METHOD sizeValue
# define TYPE_NAME NSSize
#elif TYPE_ORDER == 6
@interface GSEdgeInsetsValue : NSValue
{
NSEdgeInsets data;
}
@end
# define GSTemplateValue GSEdgeInsetsValue
# define TYPE_METHOD edgeInsetsValue
# define TYPE_NAME NSEdgeInsets
#endif

@implementation GSTemplateValue
Expand Down Expand Up @@ -164,6 +173,11 @@ - (BOOL) isEqualToValue: (NSValue*)aValue
return YES;
else
return NO;
#elif TYPE_ORDER == 6
if (data.top == val.top && data.left == val.left && data.bottom == val.bottom && data.right == val.right)
return YES;
else
return NO;
#endif
}
return NO;
Expand Down Expand Up @@ -213,6 +227,18 @@ - (NSUInteger) hash
for (i = 0; i < sizeof(double); i++)
hash += val.c[i];
return hash;
#elif TYPE_ORDER == 6
union {
double d;
unsigned char c[sizeof(double)];
} val;
NSUInteger hash = 0;
unsigned int i;

val.d = data.top + data.left + data.bottom + data.right;
for (i = 0; i < sizeof(double); i++)
hash += val.c[i];
return hash;
#endif
}

Expand Down Expand Up @@ -241,6 +267,9 @@ - (NSString *) description
return NSStringFromRect(data);
#elif TYPE_ORDER == 5
return NSStringFromSize(data);
#elif TYPE_ORDER == 6
return [NSString stringWithFormat:@"{top = %.2f, left = %.2f, bottom = %.2f, right = %.2f}",
data.top, data.left, data.bottom, data.right];
#endif
}

Expand Down
Loading