Created
June 12, 2013 05:50
-
-
Save theory/5763082 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/semver.c b/src/semver.c | |
| index f25e06e..c405135 100644 | |
| --- a/src/semver.c | |
| +++ b/src/semver.c | |
| @@ -49,6 +49,9 @@ typedef struct semver | |
| char patchname[]; /* patch name, including the null byte for convenience */ | |
| } semver; | |
| +#define DatumGetSemverP(x) ((semver *) PG_DETOAST_DATUM(x)) | |
| +#define PG_GETARG_SEMVER_P(n) DatumGetSemverP(PG_GETARG_DATUM(n)) | |
| + | |
| // forward declarations, mostly to shut the compiler up but some are | |
| // actually necessary. | |
| char* emit_semver(semver* version); | |
| @@ -220,7 +223,7 @@ PG_FUNCTION_INFO_V1(semver_out); | |
| Datum | |
| semver_out(PG_FUNCTION_ARGS) | |
| { | |
| - semver* amount = (void*)PG_GETARG_POINTER(0); | |
| + semver* amount = (void*)PG_GETARG_SEMVER_P(0); | |
| char *result; | |
| result = emit_semver(amount); | |
| @@ -241,7 +244,7 @@ PG_FUNCTION_INFO_V1(semver_to_text); | |
| Datum | |
| semver_to_text(PG_FUNCTION_ARGS) | |
| { | |
| - semver* semver = (void*) PG_GETARG_POINTER(0); | |
| + semver* semver = (void*)PG_GETARG_SEMVER_P(0); | |
| char* xxx = emit_semver(semver); | |
| text* res = cstring_to_text(xxx); | |
| pfree(xxx); | |
| @@ -286,8 +289,8 @@ PG_FUNCTION_INFO_V1(semver_eq); | |
| Datum | |
| semver_eq(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| PG_FREE_IF_COPY(a, 0); | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -298,8 +301,8 @@ PG_FUNCTION_INFO_V1(semver_ne); | |
| Datum | |
| semver_ne(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| PG_FREE_IF_COPY(a, 0); | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -310,8 +313,8 @@ PG_FUNCTION_INFO_V1(semver_le); | |
| Datum | |
| semver_le(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| PG_FREE_IF_COPY(a, 0); | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -322,8 +325,8 @@ PG_FUNCTION_INFO_V1(semver_lt); | |
| Datum | |
| semver_lt(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| PG_FREE_IF_COPY(a, 0); | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -334,8 +337,8 @@ PG_FUNCTION_INFO_V1(semver_ge); | |
| Datum | |
| semver_ge(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| PG_FREE_IF_COPY(a, 0); | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -346,8 +349,8 @@ PG_FUNCTION_INFO_V1(semver_gt); | |
| Datum | |
| semver_gt(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| PG_FREE_IF_COPY(a, 0); | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -358,8 +361,8 @@ PG_FUNCTION_INFO_V1(semver_cmp); | |
| Datum | |
| semver_cmp(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| PG_FREE_IF_COPY(a, 0); | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -375,7 +378,7 @@ PG_FUNCTION_INFO_V1(hash_semver); | |
| Datum | |
| hash_semver(PG_FUNCTION_ARGS) | |
| { | |
| - semver* version = (void*)PG_GETARG_POINTER(0); | |
| + semver* version = (void*)PG_GETARG_SEMVER_P(0); | |
| uint32 hash = 0; | |
| int i; | |
| Datum patchname; | |
| @@ -399,8 +402,8 @@ PG_FUNCTION_INFO_V1(semver_larger); | |
| Datum | |
| semver_larger(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| if (diff >= 0) { | |
| PG_FREE_IF_COPY(b, 1); | |
| @@ -416,8 +419,8 @@ PG_FUNCTION_INFO_V1(semver_smaller); | |
| Datum | |
| semver_smaller(PG_FUNCTION_ARGS) | |
| { | |
| - semver* a = (void*)PG_GETARG_POINTER(0); | |
| - semver* b = (void*)PG_GETARG_POINTER(1); | |
| + semver* a = (void*)PG_GETARG_SEMVER_P(0); | |
| + semver* b = (void*)PG_GETARG_SEMVER_P(1); | |
| int diff = _semver_cmp(a, b); | |
| if (diff <= 0) { | |
| PG_FREE_IF_COPY(b, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment