Haven't found my "working" example yet (might've been on a docker I blew
away). I did find some WIP code but some of the includes it uses are not
distributed.
Maybe this will help you get further until I find something concrete:
#include "Python.h"
#include <jsystem.h>
int ParseArguments(char* arr[],Py_ssize_t size, PyObject *args) {
/* Get arbitrary number of strings from Py_Tuple */
Py_ssize_t i;
PyObject *temp_p, * pyStr;
temp_p = PyTuple_GetItem(args,i);
if(temp_p == NULL) {return 0;}
char *ptr = PyUnicode_AsUTF8AndSize(temp_p, &size);
arr[i] = strdup(ptr);
}
return 1;
}
static PyObject * jbasepy_callsub(PyObject *self, PyObject *args)
{
struct jBASEDataAreas *dp;
dp = jbase_getdpEX(NULL,NULL,1,NULL);
if (dp != NULL)
{
char * subroutineName;
Py_ssize_t TupleSize = PyTuple_Size(args);
char ** all_args = malloc(TupleSize * sizeof(char*));
PyObject * list_out;
if (ParseArguments(all_args, TupleSize, args))
{
subroutineName = all_args[0];
int (*subptr)() = JediObjectFindFunction(dp,
subroutineName, 2);
if (subptr != NULL)
{
int i;
char V[256];
memset (V, 'V', TupleSize-1);
V[TupleSize-1] = '\0'; /* null terminate.
*/
VAR *varArg, **varArgs =
malloc((TupleSize-1) * sizeof(VAR*));
for(i = 1; i < TupleSize; ++i)
{
varArgs[i-1] = malloc(sizeof(VAR));
varArg = varArgs[i-1];
VAR_INITIALISE_VB(varArg);
STORE_VBS(varArg,(STRING*)all_args[i]);
}
list_out =
PyUnicode_FromString((char*)CONV_SFB(varArgs[0]));
for(i = 1; i < TupleSize; ++i)
{
VAR * varArg = varArgs[i-1];
VAR_RELEASE_VB(varArg);
free(varArgs[i-1]);
free(all_args[i]);
}
free(all_args[0]);
char V[256];
memset (V, 'V', TupleSize-1);
V[TupleSize-1] = '\0'; /* null terminate.
*/
VAR *varArg, **varArgs =
malloc((TupleSize-1) * sizeof(VAR*));
for(i = 1; i < TupleSize; ++i)
{
varArgs[i-1] = malloc(sizeof(VAR));
varArg = varArgs[i-1];
VAR_INITIALISE_VB(varArg);
STORE_VBS(varArg,(STRING*)all_args[i]);
}
subptr(dp, V, varArgs[0], varArgs[1],
varArgs[2], varArgs[3], varArgs[4], varArg
s[5], varArgs[6], varArgs[7], varArgs[8], varArgs[9]);
list_out =
PyUnicode_FromString((char*)CONV_SFB(varArgs[0]));
for(i = 1; i < TupleSize; ++i)
{
VAR * varArg = varArgs[i-1];
VAR_RELEASE_VB(varArg);
free(varArgs[i-1]);
free(all_args[i]);
}
free(all_args[0]);
free(all_args);
free(varArgs);
return list_out;
}
else
{
return PyUnicode_FromString("Subroutine not
found");
}
}
return PyUnicode_FromString("Error parsing arguments");
}
return PyUnicode_FromString("Failed to initialise jBASE");
}
static PyMethodDef jbasepy_methods[] = {
{"callsub", (PyCFunction)jbasepy_callsub, METH_VARARGS,
PyDoc_STR("call jBASE subroutine")},
On Wed, Mar 4, 2020 at 12:08 PM Peter Falson <[email protected]> wrote:
> What version of jBASE do you have?
>
> Sent from my iPhone
>
> On Mar 4, 2020, at 10:55 AM, Igor Osmolovskiy <[email protected]> wrote:
>
>
> Thanks Peter, would be really helpful!
>
> I've tried two ways
> 1. ctypes library. I managed to call a JBC function but it requires quite
> a lot work as the explicit variable types are required in this case. So all
> the transformations from PythonObj to a C type is required for each
> argument. Also in many cases polymorphismе would be required as JBC
> arguments often assume different types.
> 2. building a python library via distutils and working with PythonObj
> only. As I've mentioned already this works but was not able to get rid of
> the additional session being created at the step of "import lib" in python
> code.
>
> среда, 4 марта 2020 г., 16:11:12 UTC+1 пользователь pfalson написал:
>>
>> We have some examples of python calling a subroutine and vice versa. I
>> will dig around.
>>
>> Sent from my iPhone
>>
>> On Mar 4, 2020, at 7:05 AM, Igor Osmolovskiy <[email protected]> wrote:
>>
>>
>> Hello
>> pls see my response to Jim with the code sample
>>
>> вторник, 3 марта 2020 г., 21:06:27 UTC+1 пользователь pfalson написал:
>>>
>>> Can you post some code?
>>>
>>> Sent from my iPhone
>>>
>>> On Mar 3, 2020, at 11:19 AM, Igor Osmolovskiy <[email protected]> wrote:
>>>
>>>
>>> Dear all
>>>
>>> I need the jBase DP (data pointer) to be initialized. I've actually
>>> managed to initialize it by calling the jbase_getdp(). But in both cases
>>> the new child session is created in jshell (and gets removed automatically
>>> after the code has been executed).
>>>
>>> So I am wondering: is there a possibility to retrieve and use the
>>> current session DP somehow? So that no child session would get created
>>>
>>> Any advice would be highly appreciated
>>>
>>> Thanks in advance
>>>
>>>
>>> PS: to the admin, it is actually a jBase related question rather than
>>> TAFC. Thanks
>>>
>>>
>>> Kind regards,
>>> Igor
>>>
>>> --
>>> --
>>> IMPORTANT: T24/Globus posts are no longer accepted on this forum.
>>>
>>> To post, send email to [email protected]
>>> To unsubscribe, send email to [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/jBASE?hl=en
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "jBASE" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/jbase/73153581-25ae-493a-95f6-8afc5cdf7813%40googlegroups.com
>>> <https://groups.google.com/d/msgid/jbase/73153581-25ae-493a-95f6-8afc5cdf7813%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> --
>> --
>> IMPORTANT: T24/Globus posts are no longer accepted on this forum.
>>
>> To post, send email to [email protected]
>> To unsubscribe, send email to [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/jBASE?hl=en
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "jBASE" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jbase/5c46377f-4c68-4f50-a5fb-9d1d8164232b%40googlegroups.com
>> <https://groups.google.com/d/msgid/jbase/5c46377f-4c68-4f50-a5fb-9d1d8164232b%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> --
> --
> IMPORTANT: T24/Globus posts are no longer accepted on this forum.
>
> To post, send email to [email protected]
> To unsubscribe, send email to [email protected]
> For more options, visit this group at
> http://groups.google.com/group/jBASE?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "jBASE" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jbase/8ed5e66b-8076-495b-8b66-c7db7d4e8629%40googlegroups.com
> <https://groups.google.com/d/msgid/jbase/8ed5e66b-8076-495b-8b66-c7db7d4e8629%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
--
--
IMPORTANT: T24/Globus posts are no longer accepted on this forum.
To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en
---
You received this message because you are subscribed to the Google Groups
"jBASE" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jbase/CADBkQX3y2BVd0goEPGE8K1EdfrbcmdjZ1vK0xGWigTCaOfnBVA%40mail.gmail.com.