[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

SWIG/Python interface bug

From: Marshall White <cscidork_at_yahoo.com>
Date: 2003-02-01 05:14:42 CET

I am going through looking into what I can do with the SWIG Python stuff.

I found one thing I can't do.

It seems like it doesn't like functions with arguments of "const char **"

I wrote a test script to verify this for myself. It is at the bottom of this email (I named it
"py_broke.py").
For instance, my output is:
mwhite@big-dog:/storage/code/python# ./py_broke.py /home/svnrepos /trunk
commit date = `_60141a08_p_char`
commit author = `_f0371a08_p_char`

The commit date and authors are human readable strings.
The problem is that the arguments are being returned as "char *" which means nothing to Python.
They should instead be returned back as Python string objects.

The function I am calling in this script is just one of many that currently won't work correctly.
In fact one example of this bug exists in cvs2svn (that's where I got the idea):
    conflicts, new_rev = fs.commit_txn(txn)

    # set the time to the proper (past) time
    fs.change_rev_prop(t_fs, new_rev, 'svn:date', date, c_pool)

    ### how come conflicts is a newline?
    if conflicts != '\n':
      print ' CONFLICTS:', `conflicts`

Indeed conflicts should not be a newline. In fact, most of the time it isn't. It is one of those
"*_p_char" things.

1) Is this a known bug?
2) I have a fairly simple patch to fix this. It causes "conflicts" in cvs2svn to be an empty
string (as it should be). It also allows the attached test script to print readable dates and
author names. I will post shortly.

Marshall

#!/usr/bin/env python
#
# SVN SWIG Python interface test: ...
#
# How well do we handle C functions with const char ** arguments
#

import os
import sys

from svn import fs, util, repos

def test_this(pool, ctx):
  t_repos = repos.svn_repos_open(ctx.repospath, pool)
  t_fs = repos.svn_repos_fs(t_repos)

  rev = fs.youngest_rev(t_fs, pool)
  txn = fs.begin_txn(t_fs, rev, pool)
  root = fs.txn_root(txn, pool)

  cr, cd, la = repos.svn_repos_get_committed_info(root, ctx.filepath, pool)

  print 'commit date = `%s`' % cd
  print 'commit author = `%s`' % la

class _ctx:
  pass

def usage(ctx):
  print 'USAGE: %s svn-repos-path repos-file' % os.path.basename(sys.argv[0])
  print ' svn-repos-path - A path to a valid repository'
  print ' repos-file - A path to a file in that repository'
  sys.exit(1)

def main():
  # prepare the operation context
  ctx = _ctx()

  if len(sys.argv) != 3:
    usage(ctx)

  ctx.repospath = sys.argv[1]
  ctx.filepath = sys.argv[2]

  util.run_app(test_this, ctx)

if __name__ == '__main__':
  main()

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Feb 1 05:15:20 2003

This is an archived mail posted to the Subversion Dev mailing list.