|
1 | 1 | #include "postgres.h" |
| 2 | + |
2 | 3 | #undef _ |
| 4 | + |
3 | 5 | #include "fmgr.h" |
4 | 6 | #include "plperl.h" |
5 | 7 | #include "plperl_helpers.h" |
6 | 8 | #include "hstore.h" |
7 | 9 |
|
8 | 10 | PG_MODULE_MAGIC; |
9 | 11 |
|
| 12 | +extern void _PG_init(void); |
| 13 | + |
| 14 | +/* Linkage to functions in hstore module */ |
| 15 | +typedef HStore *(*hstoreUpgrade_t) (Datum orig); |
| 16 | +static hstoreUpgrade_t hstoreUpgrade_p; |
| 17 | +typedef int (*hstoreUniquePairs_t) (Pairs *a, int32 l, int32 *buflen); |
| 18 | +static hstoreUniquePairs_t hstoreUniquePairs_p; |
| 19 | +typedef HStore *(*hstorePairs_t) (Pairs *pairs, int32 pcount, int32 buflen); |
| 20 | +static hstorePairs_t hstorePairs_p; |
| 21 | +typedef size_t (*hstoreCheckKeyLen_t) (size_t len); |
| 22 | +static hstoreCheckKeyLen_t hstoreCheckKeyLen_p; |
| 23 | +typedef size_t (*hstoreCheckValLen_t) (size_t len); |
| 24 | +static hstoreCheckValLen_t hstoreCheckValLen_p; |
| 25 | + |
| 26 | + |
| 27 | +/* |
| 28 | + * Module initialize function: fetch function pointers for cross-module calls. |
| 29 | + */ |
| 30 | +void |
| 31 | +_PG_init(void) |
| 32 | +{ |
| 33 | + /* Asserts verify that typedefs above match original declarations */ |
| 34 | + AssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t); |
| 35 | + hstoreUpgrade_p = (hstoreUpgrade_t) |
| 36 | + load_external_function("$libdir/hstore", "hstoreUpgrade", |
| 37 | + true, NULL); |
| 38 | + AssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t); |
| 39 | + hstoreUniquePairs_p = (hstoreUniquePairs_t) |
| 40 | + load_external_function("$libdir/hstore", "hstoreUniquePairs", |
| 41 | + true, NULL); |
| 42 | + AssertVariableIsOfType(&hstorePairs, hstorePairs_t); |
| 43 | + hstorePairs_p = (hstorePairs_t) |
| 44 | + load_external_function("$libdir/hstore", "hstorePairs", |
| 45 | + true, NULL); |
| 46 | + AssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t); |
| 47 | + hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t) |
| 48 | + load_external_function("$libdir/hstore", "hstoreCheckKeyLen", |
| 49 | + true, NULL); |
| 50 | + AssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t); |
| 51 | + hstoreCheckValLen_p = (hstoreCheckValLen_t) |
| 52 | + load_external_function("$libdir/hstore", "hstoreCheckValLen", |
| 53 | + true, NULL); |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +/* These defines must be after the module init function */ |
| 58 | +#define hstoreUpgrade hstoreUpgrade_p |
| 59 | +#define hstoreUniquePairs hstoreUniquePairs_p |
| 60 | +#define hstorePairs hstorePairs_p |
| 61 | +#define hstoreCheckKeyLen hstoreCheckKeyLen_p |
| 62 | +#define hstoreCheckValLen hstoreCheckValLen_p |
| 63 | + |
10 | 64 |
|
11 | 65 | PG_FUNCTION_INFO_V1(hstore_to_plperl); |
12 | 66 |
|
|
0 commit comments