예제 #1
0
static int xsDecode(HV* hv, AV* av, SV* src, bool useIO) {
  csv_t csv;
  int result;

  SetupCsv(&csv, hv);
  if ((csv.useIO = useIO)) {
    csv.tmp = NULL;
    csv.size = 0;
  } else {
    STRLEN size;
    csv.tmp = src;
    csv.bptr = SvPV(src, size);
    csv.size = size;
  }
  result = Decode(&csv, src, av);
  if (result  &&  csv.types) {
    I32 i, len = av_len(av);
    SV** svp;
    
    for (i = 0;  i <= len  &&  i <= csv.types_len;  i++) {
      if ((svp = av_fetch(av, i, 0))  &&  *svp  &&  SvOK(*svp)) {
	switch (csv.types[i]) {
	case CSV_XS_TYPE_IV:
	  sv_setiv(*svp, SvIV(*svp));
	  break;
	case CSV_XS_TYPE_NV:
	  sv_setnv(*svp, SvIV(*svp));
	  break;
	}
      }
    }
  }
  return result;
}
예제 #2
0
void decode_float(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output)
{
    union {
        unsigned char bytes[4];
        float fl;
    } bytes_or_float;

    if (UNLIKELY(len != 4))
        croak("decode_float: len != 4");

    memcpy(bytes_or_float.bytes, input, 4);
    bswap4(bytes_or_float.bytes);
    sv_setnv(output, bytes_or_float.fl);
}
예제 #3
0
void decode_double(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output)
{
    union {
        unsigned char bytes[8];
        double doub;
    } bytes_or_double;

    if (UNLIKELY(len != 8))
        croak("decode_double: len != 8");

    memcpy(bytes_or_double.bytes, input, 8);
    bswap8(bytes_or_double.bytes);
    sv_setnv(output, bytes_or_double.doub);
}
예제 #4
0
//const char *duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
const char *aperl_duk_get_lstring(duk_context *ctx, duk_idx_t index, SV *out_len) {
	duk_size_t sz;
	const char *ret = duk_get_lstring(ctx, index, &sz);
	sv_setnv(out_len, sz);
	return ret;
}
예제 #5
0
//void *duk_get_buffer_data(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
void *aperl_duk_get_buffer_data(duk_context *ctx, duk_idx_t index, SV *out_len) {
	duk_size_t sz;
	void *ret = duk_get_buffer_data(ctx, index, &sz);
	sv_setnv(out_len, sz);
	return ret;
}
예제 #6
0
//void *duk_to_dynamic_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
void *aperl_duk_to_dynamic_buffer(duk_context *ctx, duk_idx_t index, SV *out_len) {
	duk_size_t sz;
	void *ret = duk_to_dynamic_buffer(ctx, index, &sz);
	sv_setnv(out_len, sz);
	return ret;
}
예제 #7
0
void
ffi_pl_closure_call(ffi_cif *ffi_cif, void *result, void **arguments, void *user)
{
  dSP;

  ffi_pl_closure *closure = (ffi_pl_closure*) user;
  ffi_pl_type_extra_closure *extra = &closure->type->extra[0].closure;
  int flags = extra->flags;
  int i;
  int count;
  SV *sv;
  SV **svp;

  if(!(flags & G_NOARGS))
  {
    ENTER;
    SAVETMPS;
  }

  PUSHMARK(SP);

  if(!(flags & G_NOARGS))
  {
    for(i=0; i< ffi_cif->nargs; i++)
    {
      if(extra->argument_types[i]->platypus_type == FFI_PL_NATIVE)
      {
        switch(extra->argument_types[i]->ffi_type->type)
        {
          case FFI_TYPE_VOID:
            break;
          case FFI_TYPE_UINT8:
            sv = sv_newmortal();
            sv_setuv(sv, *((uint8_t*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_SINT8:
            sv = sv_newmortal();
            sv_setiv(sv, *((int8_t*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_UINT16:
            sv = sv_newmortal();
            sv_setuv(sv, *((uint16_t*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_SINT16:
            sv = sv_newmortal();
            sv_setiv(sv, *((int16_t*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_UINT32:
            sv = sv_newmortal();
            sv_setuv(sv, *((uint32_t*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_SINT32:
            sv = sv_newmortal();
            sv_setiv(sv, *((int32_t*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_UINT64:
            sv = sv_newmortal();
#ifdef HAVE_IV_IS_64
            sv_setuv(sv, *((uint64_t*)arguments[i]));
#else
            sv_setu64(sv, *((uint64_t*)arguments[i]));
#endif
            XPUSHs(sv);
            break;
          case FFI_TYPE_SINT64:
            sv = sv_newmortal();
#ifdef HAVE_IV_IS_64
            sv_setiv(sv, *((int64_t*)arguments[i]));
#else
            sv_seti64(sv, *((int64_t*)arguments[i]));
#endif
            XPUSHs(sv);
            break;
          case FFI_TYPE_FLOAT:
            sv = sv_newmortal();
            sv_setnv(sv, *((float*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_DOUBLE:
            sv = sv_newmortal();
            sv_setnv(sv, *((double*)arguments[i]));
            XPUSHs(sv);
            break;
          case FFI_TYPE_POINTER:
            sv = sv_newmortal();
            if( *((void**)arguments[i]) != NULL)
              sv_setiv(sv, PTR2IV( *((void**)arguments[i]) ));
            XPUSHs(sv);
            break;
        }
      }
      else if(extra->argument_types[i]->platypus_type == FFI_PL_STRING)
      {
        sv = sv_newmortal();
        if( *((char**)arguments[i]) != NULL)
        {
          if(extra->argument_types[i]->extra[0].string.platypus_string_type == FFI_PL_STRING_FIXED)
            sv_setpvn(sv, *((char**)arguments[i]), extra->argument_types[i]->extra[0].string.size);
          else
            sv_setpv(sv, *((char**)arguments[i]));
        }
        XPUSHs(sv);
      }
    }
    PUTBACK;
  }

  svp = hv_fetch((HV *)SvRV((SV *)closure->coderef), "code", 4, 0);
  if (svp)
    count = call_sv(*svp, flags | G_EVAL);
  else
    count = 0;

  if(SvTRUE(ERRSV))
  {
#ifdef warn_sv
    warn_sv(ERRSV);
#else
    warn("%s", SvPV_nolen(ERRSV));
#endif
  }

  if(!(flags & G_DISCARD))
  {
    SPAGAIN;

    if(count != 1)
      sv = &PL_sv_undef;
    else
      sv = POPs;

    if(extra->return_type->platypus_type == FFI_PL_NATIVE)
    {
      switch(extra->return_type->ffi_type->type)
      {
        case FFI_TYPE_UINT8:
#ifdef FFI_PL_PROBE_BIGENDIAN
          ((uint8_t*)result)[3] = SvUV(sv);
#else
          *((uint8_t*)result) = SvUV(sv);
#endif
          break;
        case FFI_TYPE_SINT8:
#ifdef FFI_PL_PROBE_BIGENDIAN
          ((int8_t*)result)[3] = SvIV(sv);
#else
          *((int8_t*)result) = SvIV(sv);
#endif
          break;
        case FFI_TYPE_UINT16:
#ifdef FFI_PL_PROBE_BIGENDIAN
          ((uint16_t*)result)[1] = SvUV(sv);
#else
          *((uint16_t*)result) = SvUV(sv);
#endif
          break;
        case FFI_TYPE_SINT16:
#ifdef FFI_PL_PROBE_BIGENDIAN
          ((int16_t*)result)[1] = SvIV(sv);
#else
          *((int16_t*)result) = SvIV(sv);
#endif
          break;
        case FFI_TYPE_UINT32:
          *((uint32_t*)result) = SvUV(sv);
          break;
        case FFI_TYPE_SINT32:
          *((int32_t*)result) = SvIV(sv);
          break;
        case FFI_TYPE_UINT64:
#ifdef HAVE_IV_IS_64
          *((uint64_t*)result) = SvUV(sv);
#else
          *((uint64_t*)result) = SvU64(sv);
#endif
          break;
        case FFI_TYPE_SINT64:
#ifdef HAVE_IV_IS_64
          *((int64_t*)result) = SvIV(sv);
#else
          *((int64_t*)result) = SvI64(sv);
#endif
          break;
        case FFI_TYPE_FLOAT:
          *((float*)result) = SvNV(sv);
          break;
        case FFI_TYPE_DOUBLE:
          *((double*)result) = SvNV(sv);
          break;
        case FFI_TYPE_POINTER:
          *((void**)result) = SvOK(sv) ? INT2PTR(void*, SvIV(sv)) : NULL;
          break;
      }
    }

    PUTBACK;
  }
예제 #8
0
void
Tcl_SetDoubleObj (Tcl_Obj *objPtr, double value)
{
 dTHX;
 sv_setnv(ForceScalarLvalue(aTHX_ objPtr),value);
}
예제 #9
0
// Called when a Perl script says C<use Win32::SqlServer>.
void initialize ()
{
   SV *sv;
   DWORD       err;
   HRESULT     ret = S_OK;
   char      * obj;

   // In the critical section we create our starting point, the pointer to
   // OLE DB services. We also create a pointer to a conversion object.
   // Thess pointer will never be released.
   EnterCriticalSection(&CS);

   // Get classIDs for the possible providers.
   if (IsEqualCLSID(clsid_sqloledb, CLSID_NULL) &&
       IsEqualCLSID(clsid_sqlncli, CLSID_NULL)  &&
       IsEqualCLSID(clsid_sqlncli10, CLSID_NULL) && 
       IsEqualCLSID(clsid_sqlncli11, CLSID_NULL)) {

      ret = CLSIDFromProgID(L"SQLOLEDB", &clsid_sqloledb);
      if (FAILED(ret)) {
         clsid_sqloledb = CLSID_NULL;
      }

      ret = CLSIDFromProgID(L"SQLNCLI", &clsid_sqlncli);
      if (FAILED(ret)) {
         clsid_sqlncli = CLSID_NULL;
      }

      ret = CLSIDFromProgID(L"SQLNCLI10", &clsid_sqlncli10);
      if (FAILED(ret)) {
         clsid_sqlncli10 = CLSID_NULL;
      }

      ret = CLSIDFromProgID(L"SQLNCLI11", &clsid_sqlncli11);
      if (FAILED(ret)) {
         clsid_sqlncli11 = CLSID_NULL;
      }
   }

   if (OLE_malloc_ptr == NULL)
      CoGetMalloc(1, &OLE_malloc_ptr);

   if (data_init_ptr == NULL) {
      CoInitializeEx(NULL, COINIT_MULTITHREADED);

      ret = CoCreateInstance(CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER,
                             IID_IDataInitialize,
                             reinterpret_cast<LPVOID *>(&data_init_ptr));
      if (FAILED(ret)) {
         obj = "IDataInitialize";
      }

      // Fill the type map and the default login properties here.
      fill_type_map();
      setup_init_properties();

#ifdef FILEDEBUG
      // Open debug file.
      if (dbgfile == NULL) {
         dbgfile = _wfopen(L"C:\\temp\\ut.txt", L"wbc");
         fprintf(dbgfile, "\xFF\xFE");
      }
#endif
   }
   if (SUCCEEDED(ret) && data_convert_ptr == NULL) {
      ret = CoCreateInstance(CLSID_OLEDB_CONVERSIONLIBRARY,
                             NULL, CLSCTX_INPROC_SERVER,
                             IID_IDataConvert,
                             (void **) &data_convert_ptr);
      if (FAILED(ret)) {
         obj = "IDataConvert";
      }
   }

   LeaveCriticalSection(&CS);

   if (FAILED(ret)) {
      err = GetLastError();
      warn("Could not create '%s' object: %d", obj, err);
      warn("This could be because you don't have the MDAC on your machine,\n");
      warn("or an MDAC version you have is too arcane and not supported by\n");
      croak("Win32::SqlServer, which requires MDAC 2.6\n");
   }

   // Set Version string.
   if (sv = get_sv("Win32::SqlServer::Version", GV_ADD | GV_ADDMULTI))
   {
        char buff[256];
        sprintf_s(buff, 256,
                  "This is Win32::SqlServer, version %s\n\nCopyright (c) 2005-2012 Erland Sommarskog\n",
                  XS_VERSION);
        sv_setnv(sv, atof(XS_VERSION));
        sv_setpv(sv, buff);
        SvNOK_on(sv);
   }
}