making a dl
| From: | Chris Black | Date: | Wed, 04 Aug 1999 22:16:22 +0000 |
| Subject: | making a dl | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-9529@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I am trying to make a dynamically loadable module (called with ld()) but am
having trouble. I have followed calendar.so closely and I think I have all
the necessary parts. The .so builds fine. Here is a stripped down version
that I am using for testing:
(note, it is in my php/dl/bridgefeed/ dir, thus the extra step up in dir
includes)
Makefile
- ---
CC = gcc -Dbool=char -DHAS_BOOL -I/usr/include/apache -I.. -I../.. -fpic
LD = gcc -shared -rdynamic
all: bridgefeed.so
BF_OBJS = bridgefeed.o getprice.o
bridgefeed.so: $(BF_OBJS)
$(LD) -o $@ $(BF_OBJS)
clean:
rm -f *.o bridgefeed.so
- ---
bridgefeed.h
- ----
#ifndef _BRIDGEFEED_H_
#define _BRIDGEFEED_H_
#include "../phpdl.h"
/* functions accessable to PHP */
DLEXPORT void bf_getprice(INTERNAL_FUNCTION_PARAMETERS);
/* internal functions */
double _getprice(char *contract);
#endif /* _BRIDGEFEED_H_ */
- ---
bridgefeed.c
- ---
#include "bridgefeed.h"
/* array of php function to dll function mappings */
function_entry bridgefeed_functions[] = {
{"getprice", bf_getprice, NULL},
{NULL, NULL, NULL}
};
php3_module_entry bridgefeed_module_entry = {
"Bridgefeed", bridgefeed_functions, NULL, NULL, NULL, NULL, NULL,
0, 0, 0, NULL
};
#if COMPILE_DL
DLEXPPORT php3_module_entry *get_module(void) {
return &bridgefeed_module_entry;
}
#endif
/* {{{ proto float bridgefeed_getprice(char *contract)
return the price for the specified contract */
DLEXPORT void bf_getprice(INTERNAL_FUNCTION_PARAMETERS)
{
pval *contract_arg;
double price;
char pricestr[10];
char *contract;
if (getParameters(ht, 1, &contract_arg) == SUCCESS) {
convert_to_string(contract_arg);
contract = contract_arg->value.str.val;
price = _getprice(contract);
snprintf(pricestr, 10, "%f", price);
return_value->value.dval = price;
return_value->value.str.val = estrdup(pricestr);
return_value->value.str.len = strlen(pricestr);
return_value->type = IS_DOUBLE;
} else {
WRONG_PARAM_COUNT;
}
return;
}
- --
getprice.c
- ---
#include <stdio.h>
#include <stdlib.h>
double _getprice(char *contract) {
return 1.0;
}
Info:
redhat linux 6.0, kernel 2.2.10, x86, apache 1.3.6, php 3.0.9 as an apache
module.
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v0.9.8 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE3qLu2puT0mKRdCwERAq64AJsEwkp0TnmHPvwxuPygIE4sBo2AIACglsVH
D4ZH1hzYfZ5TFb6IyUcwHto=
=ATjN
-----END PGP SIGNATURE-----