home *** CD-ROM | disk | FTP | other *** search
- @(#)BUGS 1.1 9/2/93
-
- The Sybase DB-Library - Perl savestr() conflict
- ------------------------------------------------
-
-
- Ah! The joys of tying different packages together!
-
- Both Perl and DB-Library have a function called savestr(). The
- DB-Library version is used in dbcmd() to add an SQL command to the
- list of commands pointed to by dpproc->dbcmdbuf, and in dbuse() as
- well. Now there are several ways to work around this problem.
-
- 1) Compile sybperl.c with -DBROKEN_DBCMD. I've written some code
- that emulates calls to dbcmd() and dbuse(). This works OK on my
- machine/OS/Version of Perl/Version of DBlib, but it relies on
- the internal storing method used by DBlib, and that might
- change in the future.
-
- 2) Recompile Perl (specifically, uperl.o in the Perl source
- directory) with some suitable flags (eg -Dsavestr=p_savestr).
- This does not create any compatibility problems, but is a
- lengthy procedure.
-
- 3) Do something like:
- cc -c sybperl.c
- ld -r -o sybperl2.o sybperl.o -lsybdb
- [edit sybperl2.o and replace `_savestr' with something like `_savest1']
- cc -o sybperl uperl.o sybperl2.o
- This is not a bad solution, but won't work if you have shared
- library versions of libsybdb.a
-
- 4) Edit uperl.o and replace savestr with something else. This is
- the solution I've chosen as the default. It is relatively fast,
- does not rely on any internal knowledge of DB-Library, and does
- not require Perl to be recompiled.
-
- The Makefile gives some information on how to achieve these
- different options.
-
- Thanks to Teemu Torma for providing the initial input on this problem.
-
-
-
- Sybperl Memory Usage
- --------------------
-
- The general format of a Sybperl script usually looks somewhat like
- this:
-
- #!/usr/local/bin/sybperl
-
- &dbcmd( query text );
- &dbsqlexec;
- &dbresults;
-
- while(@data = &dbnextrow)
- {
- process data
- }
-
-
- If you are using a version of Perl prior to release 4, patchlevel
- 35, then this method will result in a rather important memory
- leak. There are two ways around this problem:
-
- 1) Upgrade to Perl 4, patchlevel 35 :-)
-
- 2) Write a subroutine that calls &dbnextrow and stores the returned
- array to a local variable, and which in turn returns that array to
- the main while() loop, like so:
-
- sub getRow
- {
- local(@data);
-
- @data = &dbnextrow;
-
- @data;
- }
-
- while(@data = &getRow)
- {
- etc.
- }
-
-
- This technique should keep the memory usage of Sybperl to a
- manageable level.
-
-
-
- Perl packages / usersubs bug
- ----------------------------
-
- The following is bug that was uncovered by Jeff Wong:
-
- ------ begin excerpt -------
-
- a: sybperl script z.pl has some *.pl required scripts. Let's call
- them x.pl and y.pl for convenience.
-
- b: z.pl looks like this (basic structure):
-
- ...
- require "sybperl.pl";
- require "x.pl";
- require "y.pl";
- ...
-
- c: x.pl looks like this (basic structure):
-
- ...
- package x;
- ...
- < Sybperl functions with main package dereferencing, e.g. &main'dbcancel(), >
- < &main'dbcancel( $dbproc ), &main'dbnextrow(), ... >
- ...
- package main;
- ...
-
- d: y.pl looks like x.pl or perhaps like other required packages (in format).
-
- e: Bug surfaces in x.pl in that it suddenly cannot locate the sybperl
- functions.
-
- My guess is that the bug is caused by the way that usersub functions
- are treated by the "require" and "package" operators. I say this because:
-
- - Usersub functions look very much like perl built-in functions, except that
- usersub functions require an ampersand character in front of their names.
-
- - Built-in functions are global to all packages.
-
- - Perl user-defined functions are local to the package which contains their
- name definition (i.e. where the namespace is).
-
- - When I don't use the x.pl style package construct, the problem disappears.
-
- ------ end excerpt -------
-
-
- The way around this bug is to compile Sybperl with the PACKAGE_BUG
- macro defined. When this is done, sybperl.pl creates a number of
- 'glue' routines (see lib/sybdb_redefs.pl') which bypass the bug.
-
- It's not the cleanest of solutions, but it works...
-
-
-
-
- Please let me know if you find any other problems with Sybperl so
- that I can look into it.
-
- Thank you.
-
- Michael Peppler <mpeppler@itf.ch>
-
-
-