The great merge

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
1508 changed files with 125983 additions and 44037 deletions

View file

@ -0,0 +1,4 @@
#! /bin/sh -e
${SWIG:=swig} -php4 -phpfull -noproxy -withc example.c example.i
phpize && ./configure && make clean && make

View file

@ -0,0 +1,15 @@
TOP = ../..
SWIG = $(TOP)/../swig
SRCS = example.c
TARGET = php_example
INTERFACE = example.i
SWIGOPT = -noproxy
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php4
clean::
rm -f *_wrap* *.o core *~ *.so *.php php_example.h
check: all

View file

@ -0,0 +1,90 @@
/* File : example.c */
/* I'm a file containing some C global variables */
#include <stdio.h>
#include <stdlib.h>
#include "example.h"
int ivar = 0;
short svar = 0;
long lvar = 0;
unsigned int uivar = 0;
unsigned short usvar = 0;
unsigned long ulvar = 0;
signed char scvar = 0;
unsigned char ucvar = 0;
char cvar = 0;
float fvar = 0;
double dvar = 0;
char *strvar = 0;
const char *cstrvar = 0;
int *iptrvar = 0;
char name[256] = "Dave";
char path[256] = "/home/beazley";
/* Global variables involving a structure */
Point *ptptr = 0;
Point pt = { 10, 20 };
/* A variable that we will make read-only in the interface */
int status = 1;
/* A debugging function to print out their values */
void print_vars() {
printf("ivar = %d\n", ivar);
printf("svar = %d\n", svar);
printf("lvar = %ld\n", lvar);
printf("uivar = %u\n", uivar);
printf("usvar = %u\n", usvar);
printf("ulvar = %lu\n", ulvar);
printf("scvar = %d\n", scvar);
printf("ucvar = %u\n", ucvar);
printf("fvar = %g\n", fvar);
printf("dvar = %g\n", dvar);
printf("cvar = %c\n", cvar);
printf("strvar = %s\n", strvar ? strvar : "(null)");
printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
printf("iptrvar = %x\n", iptrvar);
printf("name = %s\n", name);
printf("ptptr = %x (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
printf("pt = (%d, %d)\n", pt.x, pt.y);
printf("status = %d\n", status);
}
/* A function to create an integer (to test iptrvar) */
int *new_int(int value) {
int *ip = (int *) malloc(sizeof(int));
*ip = value;
return ip;
}
int value_int(int *value) {
return *value;
}
/* A function to create a point */
Point *new_Point(int x, int y) {
Point *p = (Point *) malloc(sizeof(Point));
p->x = x;
p->y = y;
return p;
}
char * Point_print(Point *p) {
static char buffer[256];
if (p) {
sprintf(buffer,"(%d,%d)", p->x,p->y);
} else {
sprintf(buffer,"null");
}
return buffer;
}
void pt_print() {
printf("(%d, %d)\n", pt.x, pt.y);
}

View file

@ -0,0 +1,6 @@
/* File: example.h */
typedef struct {
int x,y;
} Point;

View file

@ -0,0 +1,45 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Some global variable declarations */
extern int ivar;
extern short svar;
extern long lvar;
extern unsigned int uivar;
extern unsigned short usvar;
extern unsigned long ulvar;
extern signed char scvar;
extern unsigned char ucvar;
extern char cvar;
extern float fvar;
extern double dvar;
extern char *strvar;
extern const char *cstrvar;
extern int *iptrvar;
extern char name[256];
extern Point *ptptr;
extern Point pt;
/* Some read-only variables */
%immutable;
extern int status;
extern char path[256];
%mutable;
/* Some helper functions to make it easier to test */
extern void print_vars();
extern int *new_int(int value);
extern int value_ent(int *value);
extern Point *new_Point(int x, int y);
extern char *Point_print(Point *p);
extern void pt_print();

View file

@ -0,0 +1,71 @@
<?php
require "example.php";
/* Try to set the values of some global variables */
ivar_set(42);
svar_set(-31000);
lvar_set(65537);
uivar_set(123456);
usvar_set(61000);
ulvar_set(654321);
scvar_set(-13);
ucvar_set(251);
cvar_set("S");
fvar_set(3.14159);
dvar_set(2.1828);
strvar_set("Hello World");
cstrvar_set("Goodbye");
iptrvar_set(new_int(37));
ptptr_set(new_point(37,42));
name_set("Bill");
echo "Variables (values printed from PHP)\n";
echo "ivar = ".ivar_get()."\n";
echo "svar = ".svar_get()."\n";
echo "lvar = ".lvar_get()."\n";
echo "uivar = ".uivar_get()."\n";
echo "usvar = ".usvar_get()."\n";
echo "ulvar = ".ulvar_get()."\n";
echo "scvar = ".scvar_get()."\n";
echo "ucvar = ".ucvar_get()."\n";
echo "cvar = ".cvar_get()."\n";
echo "fvar = ".fvar_get()."\n";
echo "dvar = ".dvar_get()."\n";
echo "strvar = ".strvar_get()."\n";
echo "cstrvar = ".cstrvar_get()."\n";
echo "iptrvar = ".iptrvar_get()."\n";
echo "name = ".name_get()."\n";
echo "ptptr = ".ptptr_get() , point_print(ptptr_get()) , "\n";
echo "pt = ".pt_get(), point_print(pt_get()) , "\n";
echo "\nVariables (values printed from C)\n";
print_vars();
echo "\nI'm going to try and update a structure variable.\n";
pt_set(ptptr_get());
echo "The new value is \n";
pt_print();
echo "You should see the value", point_print(ptptr_get()), "\n";
echo "\nNow I'm going to try and modify some read only variables\n";
echo "Trying to set 'path'\n";
//path_set("Whoa!");
echo "Path = ".path_get()."\n";
echo "Trying to set 'status'\n";
/* And this */
//status_set(0);
echo "Status = ".status_get()."\n";
?>

View file

@ -0,0 +1,80 @@
<?php
### THIS VERSION was written for when php global vars fakingly mirrored
### the wrapped global vars, but it was very inefficient.
### For now we don't do this (pending some changes to php itself) so
### we use accessor functions instead; WE KEEP THIS version around ready
### for when those php changes are made and we can switch back.
### Specifically we want $_GLOBALS variable overloading like object
### property overloading
require "example.php";
/* Try to set the values of some global variables */
$ivar = 42;
$svar = -31000;
$lvar = 65537;
$uivar = 123456;
$usvar = 61000;
$ulvar = 654321;
$scvar = -13;
$ucvar = 251;
$cvar = "S";
$fvar = 3.14159;
$dvar = 2.1828;
$strvar = "Hello World";
$cstrvar = "Goodbye";
$iptrvar = new_int(37);
$ptptr = new_point(37,42);
$name = "Bill";
echo "Variables (values printed from PHP)\n";
echo "ivar = $ivar\n";
echo "svar = $svar\n";
echo "lvar = $lvar\n";
echo "uivar = $uivar\n";
echo "usvar = $usvar\n";
echo "ulvar = $ulvar\n";
echo "scvar = $scvar\n";
echo "ucvar = $ucvar\n";
echo "cvar = $cvar\n";
echo "fvar = $fvar\n";
echo "dvar = $dvar\n";
echo "strvar = $strvar\n";
echo "cstrvar = $cstrvar\n";
echo "iptrvar = $iptrvar\n";
echo "name = $name\n";
echo "ptptr = $ptptr" , point_print($ptptr) , "\n";
echo "pt = $pt" , point_print($pt) , "\n";
echo "\nVariables (values printed from C)\n";
print_vars();
echo "\nI'm going to try and update a structure variable.\n";
$pt = $ptptr;
echo "The new value is \n";
pt_print();
echo "You should see the value", point_print($ptptr), "\n";
echo "\nNow I'm going to try and modify some read only variables\n";
echo "Trying to set 'path'\n";
/* Sadly this works */
$path = "Whoa!";
echo "Path = $path\n";
echo "Trying to set 'status'\n";
/* And this */
$status = 0;
echo "Status = $status\n";
?>