Skip to content

Commit ffc6384

Browse files
committed
Move unary minus to separate file
1 parent e86982d commit ffc6384

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension_version = 0
1313

1414
EXTENSION = uint
1515
MODULE_big = uint
16-
OBJS = uint.o hash.o hex.o magic.o operators.o aggregates.o
16+
OBJS = uint.o hash.o hex.o magic.o misc.o operators.o aggregates.o
1717
DATA_built = uint--$(extension_version).sql
1818

1919
REGRESS = init hash hex operators misc drop

misc.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <postgres.h>
2+
#include <fmgr.h>
3+
4+
#include "uint.h"
5+
6+
7+
PG_FUNCTION_INFO_V1(int1um);
8+
Datum
9+
int1um(PG_FUNCTION_ARGS)
10+
{
11+
int8 arg = PG_GETARG_INT8(0);
12+
int8 result;
13+
14+
result = -arg;
15+
/* overflow check */
16+
if (arg != 0 && SAMESIGN(result, arg))
17+
ereport(ERROR,
18+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
19+
errmsg("integer out of range")));
20+
PG_RETURN_INT8(result);
21+
}

uint.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,3 @@ uint8out(PG_FUNCTION_ARGS)
203203
sprintf(result, "%"PRIu64, (uint64_t) arg1);
204204
PG_RETURN_CSTRING(result);
205205
}
206-
207-
PG_FUNCTION_INFO_V1(int1um);
208-
Datum
209-
int1um(PG_FUNCTION_ARGS)
210-
{
211-
int8 arg = PG_GETARG_INT8(0);
212-
int8 result;
213-
214-
result = -arg;
215-
/* overflow check */
216-
if (arg != 0 && SAMESIGN(result, arg))
217-
ereport(ERROR,
218-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
219-
errmsg("integer out of range")));
220-
PG_RETURN_INT8(result);
221-
}

0 commit comments

Comments
 (0)