pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
C functions and int8?
4+ messages / 3 participants
[nested] [flat]

* C functions and int8?
@ 2000-09-21 08:05 Forest Wilkinson <fspam@home.com>
  2000-09-21 08:32 ` Re: C functions and int8? Karel Zak <zakkr@zf.jcu.cz>
  0 siblings, 1 reply; 4+ messages in thread

From: Forest Wilkinson @ 2000-09-21 08:05 UTC (permalink / raw)
  To: pgsql-sql@hub.org

I have written a few Postgres extension functions in C, and want to modify
some of them to return an int8.  However, I don't see any int8 definition
in postgres.h.  (I have the 7.0.2 RPMs installed.)  How should I
accomplish this?




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: C functions and int8?
  2000-09-21 08:05 C functions and int8? Forest Wilkinson <fspam@home.com>
@ 2000-09-21 08:32 ` Karel Zak <zakkr@zf.jcu.cz>
  2000-09-22 00:35   ` Re: C functions and int8? Forest Wilkinson <fspam@home.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Karel Zak @ 2000-09-21 08:32 UTC (permalink / raw)
  To: Forest Wilkinson <fspam@home.com>; +Cc: pgsql-sql@hub.org


On Thu, 21 Sep 2000, Forest Wilkinson wrote:

> I have written a few Postgres extension functions in C, and want to modify
> some of them to return an int8.  However, I don't see any int8 definition
> in postgres.h.  (I have the 7.0.2 RPMs installed.)  How should I
> accomplish this?

 in the source tree: src/include/c.h

 typedef signed char int8;           /* == 8 bits */


 ... but I not sure if this file is included in the RPM package.


					Karel




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: C functions and int8?
  2000-09-21 08:05 C functions and int8? Forest Wilkinson <fspam@home.com>
  2000-09-21 08:32 ` Re: C functions and int8? Karel Zak <zakkr@zf.jcu.cz>
@ 2000-09-22 00:35   ` Forest Wilkinson <fspam@home.com>
  2000-09-22 02:06     ` Re: C functions and int8? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Forest Wilkinson @ 2000-09-22 00:35 UTC (permalink / raw)
  To: Karel Zak <zakkr@zf.jcu.cz>; +Cc: pgsql-sql@hub.org

That's an int8 meaning "eight bit integer".  I want to work with an int8
meaning "64 bit integer", as described in the docs:
http://www.postgresql.org/users-lounge/docs/7.0/user/datatype.htm#AEN942

So how do I return one of these suckers from a C function?

Forest

On Thu, 21 Sep 2000 10:32:50 +0200 (CEST), Karel Zak wrote:

>
>On Thu, 21 Sep 2000, Forest Wilkinson wrote:
>
>> I have written a few Postgres extension functions in C, and want to modify
>> some of them to return an int8.  However, I don't see any int8 definition
>> in postgres.h.  (I have the 7.0.2 RPMs installed.)  How should I
>> accomplish this?
>
> in the source tree: src/include/c.h
>
> typedef signed char int8;           /* == 8 bits */
>
>
> ... but I not sure if this file is included in the RPM package.
>
>
>					Karel




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: C functions and int8?
  2000-09-21 08:05 C functions and int8? Forest Wilkinson <fspam@home.com>
  2000-09-21 08:32 ` Re: C functions and int8? Karel Zak <zakkr@zf.jcu.cz>
  2000-09-22 00:35   ` Re: C functions and int8? Forest Wilkinson <fspam@home.com>
@ 2000-09-22 02:06     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2000-09-22 02:06 UTC (permalink / raw)
  To: pgsql-sql@hub.org

Forest Wilkinson <fspam@home.com> writes:
> That's an int8 meaning "eight bit integer".  I want to work with an int8
> meaning "64 bit integer", as described in the docs:
> http://www.postgresql.org/users-lounge/docs/7.0/user/datatype.htm#AEN942
> So how do I return one of these suckers from a C function?

Emulate the code in src/backend/utils/adt/int8.c.

Currently this involves palloc'ing an int8, setting it, and returning
a pointer to it.  For instance, int8 addition is

int64 *
int8pl(int64 *val1, int64 *val2)
{
    int64       *result = palloc(sizeof(int64));

    if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
        return NULL;

    *result = *val1 + *val2;

    return result;
}


In 7.1 it'll be a lot cleaner (IMNSHO anyway ;-)):

Datum
int8pl(PG_FUNCTION_ARGS)
{
    int64        val1 = PG_GETARG_INT64(0);
    int64        val2 = PG_GETARG_INT64(1);

    PG_RETURN_INT64(val1 + val2);
}

which actually does about the same things under the hood, but you
don't have to sully your hands with 'em ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2000-09-22 02:06 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-09-21 08:05 C functions and int8? Forest Wilkinson <fspam@home.com>
2000-09-21 08:32 ` Karel Zak <zakkr@zf.jcu.cz>
2000-09-22 00:35   ` Forest Wilkinson <fspam@home.com>
2000-09-22 02:06     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox